/*
   Keys Auctions Javascript MK3
   SVN Revision: xx
   
   These functions are copyrighted, reproduction is prohibited. Although theres no earth shatteringly
   new techniques in here! Dont be a rubbish and lazy web developer, do a search for the thing you want 
   and learn something, rather than steal it off other people.
   
*/

function featureswap(fid)
{  
   fetchinfo("prt.getfeature.php?fid="+fid,'page_body_featured_ajax');
}

function getlot(sid)
{
   document.getElementById('page_body_ajax_lot').style.display="block";
   document.getElementById('page_body_ajax_lot').innerHTML="<br />Please Wait...";
   fetchinfo("prt.getlot.php?lid="+document.getElementById('lotno').value+'&sid='+sid,'page_body_ajax_lot');
}

function searchagain() 
{
   url="results.php?sid="+document.getElementById("sid").value+"&lim="+document.getElementById("lim").value+"&";
   url=url+"show="+document.getElementById("show").value+"&keywords="+document.getElementById("keywords").value;
   url=url+"&startfrom="+document.getElementById("startfrom").value+"&st="+document.getElementById("st").value;
   url=url+"&mode="+document.getElementById("mode").value;

   window.location=url;   
}

function login()
{
    fetchinfo("prt.getlogin.php?u="+document.getElementById('em').value+"&p="+document.getElementById('pw').value,"loginstatus");
    
    if(document.getElementById('loginstatus').value=='1')
    //successful
      window.location="myaccount2.php";
    else
    {
       document.getElementById('loginerror').style.display="block";
       document.getElementById('loginerror').innerHTML="Incorrect Login";
    }
}

function getarchive()
{
   // bit of input validation, make sure from is less than to etc
   var from=document.getElementById('archive_from').value;
   var to=document.getElementById('archive_to').value;
   
   if(to<from || from==to)
   {
     document.getElementById('date_range').style.color='red';
     document.getElementById('range_error').style.display='inline';
   }
   else
   {
     document.getElementById('date_range').style.color='black';
     document.getElementById('range_error').style.display='none';
     
     url='prt.getsales.php?ty='+document.getElementById('t').value+'&f='+from+'&t='+to;
     fetchinfo(url,'pagebody_salearchive_results');  
   }
}

function validatesignup()
{
   var errors=0;
   var list="fn,a1,tc,cs,pz,cy,dt,em,pw,pw2";
   var tags=list.split(",");
 
   for(i=0; i<tags.length; i++)
   {
     if(document.getElementById(tags[i]).value=="")
     {
       document.getElementById(tags[i]+"text").style.color="red";
       document.getElementById(tags[i]+"text").style.fontWeight="bold";
       errors++;
     }
     else
     {
       document.getElementById(tags[i]+"text").style.color="black";
       document.getElementById(tags[i]+"text").style.fontWeight="normal";
     }
   }
   
   if(!document.getElementById("em").value.match("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$"))
   {
     document.getElementById("emtext").style.color="red";
     document.getElementById("emtext").style.fontWeight="bold";
     errors++;
   }
   
   if(document.getElementById("pw").value!=document.getElementById("pw2").value)
   {
     document.getElementById("pwtext").style.color="red";
     document.getElementById("pwtext").style.fontWeight="bold";
     document.getElementById("pw2text").style.color="red";
     document.getElementById("pw2text").style.fontWeight="bold";
     errors++;   
   }
   
   if(document.getElementById("legal").checked==false)
   {
     document.getElementById("legaltext").style.color="red";
     document.getElementById("legaltext").style.fontWeight="bold";   
     errors++;
   }
   
   if(!errors)
   {
     frm=document.getElementById('signupfrm');
     frm.action="do.signup.php";
     frm.submit();
   }
}

function validatepasschange()
{
  if(document.getElementById('pw').value=="" || document.getElementById('pw2').value=="")
       document.getElementById('passerror').innerHTML="* Please enter a password * <br />";    
  else
  {
    if(document.getElementById('pw').value==document.getElementById('pw2').value)
    {
      frm=document.getElementById('passfrm');
      frm.action="do.changepass.php";
      frm.submit();
    } 
    else
       document.getElementById('passerror').innerHTML="* Passwords do not match, please try again *<br />";
   }
}

function validatemailchange()
{
  if(document.getElementById('em').value=="" || document.getElementById('em2').value=="")
       document.getElementById('error').innerHTML="* Please enter an address * <br />";    
  else
  {
    if(document.getElementById('em').value==document.getElementById('em2').value)
    {
      if(document.getElementById("em").value.match("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$") && document.getElementById("em2").value.match("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$"))
      {    
        frm=document.getElementById('passfrm');
        frm.action="do.changemail.php";
        frm.submit();
      }
      else
        document.getElementById('error').innerHTML="* Please enter valid addresses *<br />";
    } 
    else
       document.getElementById('error').innerHTML="* Addresses do not match, please try again *<br />";
   }
}

function validateamend()
{
   var errors=0;
   var list="fn,a1,tc,cs,pz,cy,dt";
   var tags=list.split(",");
 
   for(i=0; i<tags.length; i++)
   {
     if(document.getElementById(tags[i]).value=="")
     {
       document.getElementById(tags[i]+"text").style.color="red";
       document.getElementById(tags[i]+"text").style.fontWeight="bold";
       errors++;
     }
     else
     {
       document.getElementById(tags[i]+"text").style.color="black";
       document.getElementById(tags[i]+"text").style.fontWeight="normal";
     }
   }
     
   if(!errors)
   {
     frm=document.getElementById('signupfrm');
     frm.action="do.changedetails.php";
     frm.submit();
   }
}

function getbids()
{  
   fetchinfo("prt.getbids.php?sid="+document.getElementById('sid').value,'mybidlist');
}

function generateinvoice(sid)
{
   window.location="do.makeinvoice.php?sid="+sid;
}

function bid(id)
{
   var price=document.getElementById('price'+id).value.replace(/^\s*|\s*$/g,"");
  
   if(isNaN(price)==false && price!="" && price>0 && price.indexOf(".")==-1)
   {
     if(document.getElementById('bidding').style.display=="none")
       document.getElementById('bidding').style.display="block";
       
     fetchinfo("prt.addbid.php?id="+id+"&p="+price,'biddiv');
     document.getElementById('bid'+id).innerHTML="<b>You have a bid of &pound;"+price+" for this lot waiting to be confirmed.<br />Your bid will not be submitted until you confirm!</b>";
     
   }
   else
   {
     document.getElementById('tx'+id).style.color="red";
     document.getElementById('err'+id).innerHTML="<b style='color: red'>Please use only whole numbers, with no pence values or other characters.</b>";  
     document.getElementById('price'+id).focus();
   }
}

function submitbids()
{
   document.getElementById('submitbut').value="Please Wait...";
   document.getElementById('submitbut').disabled="true";
   
   window.location="do.precheckout.php";
}

function disablesubmit()
{
  document.getElementById('warning').innerHTML="Please click 'Update Bids', to confirm your altered bids.";
  document.getElementById('finalsubmit').disabled='true';
}

function updatebids()
{
  document.getElementById('updatefrm').action='do.updatebids.php';
  document.getElementById('updatefrm').submit();
}

function finalsubmitbids()
{
   document.getElementById('finalupdate').disabled='true';
   document.getElementById('finalupdate').value='Please Wait...';
   document.getElementById('finalsubmit').disabled='true';
   document.getElementById('finalsubmit').value='Please Wait...';
   
   if(document.getElementById('finalback')!=null)
   {
     document.getElementById('finalback').disabled='true';
     document.getElementById('finalback').value='Please Wait...';   
   }
   
   document.getElementById('updatefrm').action='do.submitbids.php';
   document.getElementById('updatefrm').submit(); 
}

function enlarge(lid)
{
   window.open("enlarge.php?lid="+lid,"","width=450,height=450,scrollbars=yes");
}


function enlargevertical(lid)
{
   window.open("enlarge.php?lid="+lid,"","width=600,height=550,scrollbars=yes");
}
