var Extend_timer = new Array(); 
var Upcome_timer = new Array();
var Extend_status = new Array();
var Old_Bidcounter = new Array();
var Auction_ids=0;
var Product_id=0;
var Upcomelist_ids=0;
var Auction_ids_XP=0;


function ajax() {
	// Make a new XMLHttp object

    if (window.XMLHttpRequest) {
        try {
            doc = new XMLHttpRequest();
        } catch(e)  {}
    } else if (window.ActiveXObject) {
        try {
            doc = new ActiveXObject('Msxml2.XMLHTTP');
        } catch(e)  {
          try {
              doc = new ActiveXObject('Microsoft.XMLHTTP');
          } catch(e)  {}
        }
    }
}

	
function Start_Bid() {

	
	 var doc=null;
	 	 if (window.XMLHttpRequest) {
        try {
            doc = new XMLHttpRequest();
        } catch(e)  {}
    } else if (window.ActiveXObject) {
        try {
            doc = new ActiveXObject('Msxml2.XMLHTTP');
        } catch(e)  {
          try {
              doc = new ActiveXObject('Microsoft.XMLHTTP');
          } catch(e)  {}
        }
    }
		// Load the result from the response page
		// ** As far a I know firefox will only load a document on the SAME domain!!	

	   doc.open('GET', "./location_lowest.php?section=Start_Bid", true);
        doc.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		
       doc.onreadystatechange = function()
	   	{
	 	  if (doc.readyState == 4)
		  	{
	           if (doc.status == 200)	
				   setTimeout('Start_Bid();',10000);
			   else
			   		setTimeout('Start_Bid();',10000);	
//alert(doc.responseText);
			}
			
		}
		doc.send(null);
}
	



function trim(str, chars) {
return ltrim(rtrim(str, chars), chars);
}

function ltrim(str, chars) {
chars = chars || "\\s";
return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}

function rtrim(str, chars) {
chars = chars || "\\s";
return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}
	
function Add_bid_xpress(pro_id) {
    	
		ajax();
		// Load the result from the response page
		// ** As far a I know firefox will only load a document on the SAME domain!!	
	    if (doc){	
			
	       doc.open("GET", "./location_lowest.php?section=add_bid_xpress&pro_id="+pro_id, false);
 			doc.send(null);
			//alert(doc.responseText);
			if(parseInt(doc.responseText)==99999)
				document.location="index.php?show=login_full";
			else
				{
				var mainarraylist=doc.responseText.split("**");	
				if(mainarraylist.length>1)
					{
						
					if(Product_id!=0){
					   document.getElementById('full_index_div_X'+parseInt(pro_id)).innerHTML = mainarraylist[3];
					   Update_bid_table1(pro_id);
					   Update_Show_price_btn(pro_id);
					}else{   
					   document.getElementById('prince_index_div_X'+parseInt(pro_id)).innerHTML = mainarraylist[6];
					   Update_Xpress_det();
					   
					}
					  
					
												       
					/*if(Product_id==0){*/
						//document.getElementById('div_blance').innerHTML = mainarraylist[1];
						if(mainarraylist[5]=="BO")
					       document.getElementById('div_blance_voucher').innerHTML = mainarraylist[4];
					    else
					       document.getElementById('div_blance').innerHTML = mainarraylist[4];
					/*}*/
					
						
					
					
					
					}
				else
					alert(doc.responseText);
				}
			}
			

}


function Show_product_details(URL)
	{
	document.location=URL;
	}
	
function bid_list(item_id,table_type)
{
	ajax();
		// Load the result from the response page
		// ** As far a I know firefox will only load a document on the SAME domain!!	
	   if (doc){
	       doc.open("GET", "./location_lowest.php?section=bid_list_table&item_id="+item_id+"&table_type="+table_type, false);   
	       doc.send(null);

			var mainarraylist=doc.responseText.split("**");
				
			if(mainarraylist[1]=="BIDLIST")	
				document.getElementById('bidlist_table_div').innerHTML = mainarraylist[0];
			
			if(table_type=='B')
				Update_bid_table1(item_id);
	    }
}

function Update_bid_table1(product_id){
		ajax();
		// Load the result from the response page
		// ** As far a I know firefox will only load a document on the SAME domain!!	
	    if (doc){
	       doc.open("GET", "./location_lowest.php?section=update_bid_table&product_id="+product_id, false);
	       doc.send(null);
	    	// Write the response to the div
			//alert(doc.responseText);
			var mainarraylist=doc.responseText.split("**");
				
			if(mainarraylist[1]=="UPDBIDLIST")	
				document.getElementById('bid_table_div1').innerHTML = mainarraylist[0];
		}
	}
	
  function do_empty(sel_id){
		document.getElementById(sel_id).value="";
	}
	
	function do_default(sel_id,text_val){
		if(document.getElementById(sel_id).value=="")
			document.getElementById(sel_id).value =text_val;
	}
	
function validation(frm)
{
	var error=0;
	var message="";
if(frm.login.value=="" || frm.login.value=="User Name" || frm.login.value=="Benutzername")
    {		
       if(error==0)
	     frm.login.focus();
       message=message+document.getElementById('login_alert').innerHTML+"\n";
	   error=1;
	}


  if(frm.pass.value=="" || frm.pass.value=="Password")
    {		
       if(error==0)
	     frm.pass.focus();
       message=message+document.getElementById('pass_exists').innerHTML+"\n";
	   error=1;
	}
	
	if(message)
 	  {	  
	    alert(message);
		return false;
	   }
	   else
	   {	
	   		document.loginform.submit();
			return true;
	   }
	}

 
 function setFocusOnUserName()
	{
		document.registration.user.focus();
	}
function IsEmail(object,fieldName)
	{		 
		  var sMessage='';
		  var bValidated = true;
		  var Focus='';


			var object1 =object.value.toLowerCase();
				if (object.value.length != 0) 
					{
		  			var objectformat = /^[^@\s]+@([-a-z0-9]+\.)+([a-z]{2}|com|net|edu|org|gov|mil|int|biz|pro|info|arpa|aero|coop|name|museum)$/;
					if (!objectformat.test(object1)) 
						{
						 sMessage+="Please enter a valid id of "+fieldName;
						 if(Focus =="")
						 Focus =object;	
						 bValidated = false;
						}
					}
		  
		
		if (sMessage!='') 
			{ 
			alert(sMessage); 
			Focus.focus();
			return false;
			}
		else
		  	return true;		  
	}
function isNum(val) {

   if (val.value.length != 0) {
   
      for (i = 0; i < val.value.length; i++) 
	  {
         var ch = val.value.charAt(i);
		 
         if (ch >= "0" && ch <= "9") 
		  continue;
          else 
		  	{
				alert(document.getElementById('Num_value').innerHTML+"\n");
				val.value = "";
		 		val.focus();
		  		
			false;
          	}
      	}
   	}
   return true;
} 
function Valid_register(frm)
	{
	var message='';
	var ckeckFocus=0;
	
	if(frm.user.value=='')
	{

	
			if(ckeckFocus!=1)
				frm.user.focus();
				message=message+document.getElementById('login_alert').innerHTML+"\n";		
			var ckeckFocus=1;	     	  
		} 
	else
		{ 
			var ret=Valid_username(frm.user.value);
			
			if(ret==1)
				{

				if(ckeckFocus!=1)
					frm.user.focus();
					message=message+document.getElementById('login_exists').innerHTML+"\n";	
					var ckeckFocus=1;	
				}
		}		
	
	if(frm.pass.value=='')
	{
	
			if(ckeckFocus!=1)
				frm.pass.focus();
				message=message+document.getElementById('pass_exists').innerHTML+"\n";	
			var ckeckFocus=1;	     	  
		} 	
	else
		{
			if(frm.pass.value!=frm.re_pass.value)
				{
		
				if(ckeckFocus!=1)
					frm.re_pass.focus();
					message=message+document.getElementById('pass_check').innerHTML+"\n";	
					var ckeckFocus=1;	
				}
		}		
	
	if(frm.name.value=='')
	{
	
			if(ckeckFocus!=1)
				frm.name.focus();
				message=message+document.getElementById('name_alert').innerHTML+"\n";	
			var ckeckFocus=1;	     	  
		} 	
	
	
		
	if(frm.city.value=='')
	{
	
			if(ckeckFocus!=1)
				frm.city.focus();
				message=message+document.getElementById('city_alert').innerHTML+"\n";	
			var ckeckFocus=1;	     	  
		}
		
	
	if(frm.address.value=='')
	{
	
			if(ckeckFocus!=1)
				frm.address.focus();
				message=message+document.getElementById('address_alert').innerHTML+"\n";	
			var ckeckFocus=1;	     	  
		}
	
	if(frm.zipcode.value=='')
	{
	
			if(ckeckFocus!=1)
				frm.zipcode.focus();
				message=message+document.getElementById('zipcode_alert').innerHTML+"\n";	
			var ckeckFocus=1;	     	  
		}	
		
	if(frm.email.value=='')
    {

		if(ckeckFocus!=1)
			frm.email.focus();	
			message=message+document.getElementById('email_alert').innerHTML+"\n";	       	
		var ckeckFocus=1;
	}
	else
	{
		var frmEmail1 =frm.email.value.toLowerCase();	
		var frmEmailformat = /^[^@\s]+@([-a-z0-9]+\.)+([a-z]{2}|com|net|edu|org|gov|mil|int|biz|pro|info|arpa|aero|coop|name|museum)$/;
		if (!frmEmailformat.test(frmEmail1)) 
		{
			if(ckeckFocus!=1)
				frm.email.focus();	
				message=message+document.getElementById('email_valid').innerHTML+"\n";	
			var ckeckFocus=1;
		}
		else
		{ 
		var ret2=Valid_email(frm.email.value); 
		if(ret2==1)
			{

			if(ckeckFocus!=1)
				frm.email.focus();
				message=message+document.getElementById('email_exists').innerHTML+"\n";	
				var ckeckFocus=1;	
			}
		}	
	}
	
	if(frm.terms.checked==false)
    {
		if(ckeckFocus!=1)
				frm.terms.focus();
				message=message+document.getElementById('terms_required').innerHTML+"\n";	
			var ckeckFocus=1;
	}
	
	
	if(message)
 	  {	  
	    alert(message);
		return false;
	   }
	   else
	   {	document.registration.submit();
			return true;
	   }
}	
function Valid_edit_profile(frm)
	{
	
	
	
	var msg='';
	var ckeckFocus=0;
	if(frm.login.value=='')
	{
	//msg+="DATA_lang[login_alert] \n";		
			if(ckeckFocus!=1)
				frm.login.focus();
				msg=msg+document.getElementById('login_alert').innerHTML+"\n";
			var ckeckFocus=1;	     	  
		} 
	else
		{ 
			var ret=Edit_Valid_username(frm.login.value);
			
			if(ret==1)
				{
				//msg+="DATA_lang[login_exists] \n";		
				if(ckeckFocus!=1)
					frm.login.focus();
					msg=msg+document.getElementById('login_exists').innerHTML+"\n";
					var ckeckFocus=1;	
				}
		}		
	
	if(frm.password.value=='' || frm.new_pass.value!=''){
	if(frm.new_pass.value=='')
	{
	//msg+="DATA_lang[pass_exists] \n";		
			if(ckeckFocus!=1)
				frm.new_pass.focus();
				msg=msg+document.getElementById('pass_exists').innerHTML+"\n";
			var ckeckFocus=1;	     	  
		} 	
	else
		{
			if(frm.re_pass.value==''){
				//msg+="DATA_lang[pass_check] \n";		
				if(ckeckFocus!=1)
					frm.re_pass.focus();
					msg=msg+document.getElementById('pass_check').innerHTML+"\n";
					var ckeckFocus=1;	
				}
			else if(frm.new_pass.value!=frm.re_pass.value)
				{
				//msg+="DATA_lang[pass_check] \n";		
				if(ckeckFocus!=1)
					frm.re_pass.focus();
					msg=msg+document.getElementById('pass_check').innerHTML+"\n";
					var ckeckFocus=1;	
				}
		}		
	}
	if(frm.name.value=='')
	{
	//msg+="DATA_lang[name_alert] \n";		
			if(ckeckFocus!=1)
				frm.name.focus();
				msg=msg+document.getElementById('name_alert').innerHTML+"\n";
			var ckeckFocus=1;	     	  
		} 	
		
	
	if(frm.city.value=='')
	{
	//msg+="DATA_lang[city_alert] \n";		
			if(ckeckFocus!=1)
				frm.city.focus();
				msg=msg+document.getElementById('city_alert').innerHTML+"\n";
			var ckeckFocus=1;	     	  
		}
		
	
	if(frm.address.value=='')
	{
	//msg+="DATA_lang[address_alert] \n";		
			if(ckeckFocus!=1)
				frm.address.focus();
				msg=msg+document.getElementById('address_alert').innerHTML+"\n";
			var ckeckFocus=1;	     	  
		}
	
	if(frm.zipcode.value=='')
	{
	//msg+="DATA_lang[zipcode_alert] \n";		
			if(ckeckFocus!=1)
				frm.zipcode.focus();
				msg=msg+document.getElementById('zipcode_alert').innerHTML+"\n";
			var ckeckFocus=1;	     	  
		}	
	if(frm.email.value=='')
    {
		//msg+="DATA_lang[email_alert] \n";
		if(ckeckFocus!=1)
			frm.email.focus();
			msg=msg+document.getElementById('email_alert').innerHTML+"\n";	       	
		var ckeckFocus=1;
	}

	
	

	
	if(msg)
 	  {	  
	    alert(msg);
		return false;
	   }
	   else
	   {	document.registration.submit();
			return true;
	   }
}


 function setFocusOnUserNametell()
	{
		document.tellfriend.friend_email.focus();
	}
function contact_valid(frm)
	{
	
	var msg='';
	var ckeckFocus=0;
	
	if(frm.friend_email.value=='')
    {
		if(ckeckFocus!=1)
			frm.friend_email.focus();
			msg=msg+document.getElementById('email_alert').innerHTML+"\n";	       	
		var ckeckFocus=1;
	}
	else
	{
		var frmEmail1 =frm.friend_email.value.toLowerCase();	
		var frmEmailformat = /^[^@\s]+@([-a-z0-9]+\.)+([a-z]{2}|com|net|edu|org|gov|mil|int|biz|pro|info|arpa|aero|coop|name|museum)$/;
		if (!frmEmailformat.test(frmEmail1)) 
		{
			
			if(ckeckFocus!=1)
				frm.friend_email.focus();
				msg=msg+document.getElementById('email_valid').innerHTML+"\n";	
			var ckeckFocus=1;
		}
		else
		{ 
		var ret2=Valid_email(frm.friend_email.value); 
		if(ret2==1)
			{

					
			if(ckeckFocus!=1)
				frm.friend_email.focus();
				msg=msg+document.getElementById('email_exists').innerHTML+"\n";
				var ckeckFocus=1;	
			}
		}	
	}
	
	if(frm.subject.value=='')
	{
			
			if(ckeckFocus!=1)
				frm.subject.focus();
				msg=msg+document.getElementById('subject_alert').innerHTML+"\n";
			var ckeckFocus=1;	     	  
		} 	
		
	if(frm.message.value=='')
    {
		
		if(ckeckFocus!=1)
			frm.message.focus();
			msg=msg+document.getElementById('enquiry_alert').innerHTML+"\n";	       	
		var ckeckFocus=1;
	}
	
	if(msg)
 	  {	  
	    alert(msg);
		return false;
	   }
	   else
	   {	document.tellfriend.submit();
			return true;
	   }
}	

 
 function setFocusOnUserNamecontact()
	{
		document.contactus.from_name.focus();
	}
function contact_us_valid(frm)
	{
	
	var msg='';
	var ckeckFocus=0;
	if(frm.from_name.value=='')
	{
	//msg+="DATA_lang[name_alert] \n";		
			if(ckeckFocus!=1)
				frm.from_name.focus();
				msg=msg+document.getElementById('name_alert').innerHTML+"\n";
			var ckeckFocus=1;	     	  
		} 
	
	if(frm.from_email.value=='')
	{
	
	//msg+="DATA_lang[email_alert] \n";		
			if(ckeckFocus!=1)
				frm.from_email.focus();
		        msg=msg+document.getElementById('email_alert').innerHTML+"\n";	
			var ckeckFocus=1;	     	  
		} 
	else
	{
		var frmEmail1 =frm.from_email.value.toLowerCase();	
		var frmEmailformat = /^[^@\s]+@([-a-z0-9]+\.)+([a-z]{2}|com|net|edu|org|gov|mil|int|biz|pro|info|arpa|aero|coop|name|museum)$/;
		if (!frmEmailformat.test(frmEmail1)) 
		{
			//msg+="DATA_lang[email_valid] \n";
			if(ckeckFocus!=1)
				frm.from_email.focus();
				msg=msg+document.getElementById('email_valid').innerHTML+"\n";	
			var ckeckFocus=1;
		}
		
			
	}		
	
	if(frm.subject.value=='')
	{
	
	//msg+="DATA_lang[subject_alert] \n";		
			if(ckeckFocus!=1)
				frm.subject.focus();
				msg=msg+document.getElementById('subject_alert').innerHTML+"\n";
			var ckeckFocus=1;	     	  
		} 	
		
	if(frm.message.value=='')
    {
		//msg+="DATA_lang[enquiry_alert] \n";
		if(ckeckFocus!=1)
			frm.message.focus();
			msg=msg+document.getElementById('enquiry_alert').innerHTML+"\n";	       	
		var ckeckFocus=1;
	}
	
	if(msg)
 	  {	  
	    alert(msg);
		return false;
	   }
	   else
	   {	document.contactus.submit();
			return true;
	   }
}	

function Update_Show_price_btn(Pro_id)
{
	var doc=null;
	if (window.XMLHttpRequest) {
    	try {
            doc = new XMLHttpRequest();
    	    } catch(e)  {}
	    } else if (window.ActiveXObject) {
    	    try {
        	    doc = new ActiveXObject('Msxml2.XMLHTTP');
		        } catch(e)  {
        	try {
              doc = new ActiveXObject('Microsoft.XMLHTTP');
		        } catch(e)  {}
	        }
  		}
		
	doc.open('GET', "./location_lowest.php?section=update_show_price_btn&Pro_id="+Pro_id, true);
	doc.setRequestHeader('Content-Type','application/x-www-form-urlencoded'); 
	doc.onreadystatechange = function()
	   	{ 
		if(doc.readyState == 4)
			{
			if(doc.status == 200)
				{
				if(doc.responseText!=0)
					{ 
						var Main_array=doc.responseText.split("**");
						
						if(Main_array[0]=="SHOWPRICE")
						  document.getElementById('full_index_div_X'+Pro_id).innerHTML = Main_array[1];
						  
						  //Update_Show_price_btn(Pro_id);
						setTimeout('Update_Show_price_btn('+Pro_id+');',3000);	
					}
				}
			}
	    };
	doc.send(null);
	
}

function Update_Xpress_det()
{
	var doc=null;
	if (window.XMLHttpRequest) {
    	try {
            doc = new XMLHttpRequest();
    	    } catch(e)  {}
	    } else if (window.ActiveXObject) {
    	    try {
        	    doc = new ActiveXObject('Msxml2.XMLHTTP');
		        } catch(e)  {
        	try {
              doc = new ActiveXObject('Microsoft.XMLHTTP');
		        } catch(e)  {}
	        }
  		}
		
	doc.open('GET', "./location_lowest.php?section=update_xpress_det&Runngin_list_xp="+Auction_ids_XP, true);
	doc.setRequestHeader('Content-Type','application/x-www-form-urlencoded'); 
	doc.onreadystatechange = function()
	   	{ 
		if(doc.readyState == 4)
			{
			if(doc.status == 200)
				{
				if(doc.responseText!=0)
					{ 
					//alert(doc.responseText);
						var Main_array=doc.responseText.split("|@|");
						for(l=0;l<Main_array.length;l++)
						{
						   var arraylist1=Main_array[l].split("**");
						   var pro_id =(parseInt(arraylist1[1]));
						      document.getElementById('prince_index_div_X'+pro_id).innerHTML = arraylist1[0];
						  
						     
						}
					}
				}
			}
	    };
	setTimeout('Update_Xpress_det();',5000);
	//setTimeout('Update_show_status();',20000);
	doc.send(null);
	
}


function Update_show_status()
	{
		ajax();
		
	   if (doc){
	       doc.open("GET", "./location_lowest.php?section=update_show_status", false);   
	       doc.send(null);
		   //alert(doc.responseText);
			}
		setTimeout('Update_show_status();',3000);	
	}

function Upcome_Update_timer()
{
		var doc=null;
	
	if (window.XMLHttpRequest) {
    	try {
            doc = new XMLHttpRequest();
    	    } catch(e)  {}
	    } else if (window.ActiveXObject) {
    	    try {
        	    doc = new ActiveXObject('Msxml2.XMLHTTP');
		        } catch(e)  {
        	try {
              doc = new ActiveXObject('Microsoft.XMLHTTP');
		        } catch(e)  {}
	        }
  		}
		
	doc.open('GET', "./location_lowest.php?section=upcome_update_timer&upcount_list="+Upcomelist_ids, true);
	doc.setRequestHeader('Content-Type','application/x-www-form-urlencoded'); 
		
	doc.onreadystatechange = function()
	   	{ 
		if(doc.readyState == 4)
			{
			if(doc.status == 200)
				{
					//alert(doc.responseText);
				if(doc.responseText!=0)
					{
		  			var arraylist=doc.responseText.split("**");
					if(arraylist[2]=='UPCOM'){	
					
						var pro_id =(parseInt(arraylist[0]));
						Upcome_timer[pro_id] = parseInt(arraylist[1]);	
					}
						
					}
		}
				}
	};
	setTimeout('Upcome_Update_timer();', 10000);  
     doc.send(null);
}

function Upcome_reverse_timer()
{
   if(Upcomelist_ids!='0')
   {
	  var arraylist=Upcomelist_ids.split(",");
	  for(l=0;l<arraylist.length;l++)
	  {	 
	     var pro_id =(parseInt(arraylist[l]));
		
		 if(Upcome_timer[pro_id]>0){
			if(Upcome_timer[pro_id]<=10)
		        document.getElementById('upcome_timeid_'+pro_id).innerHTML = '<font color="red"><b>' + calc_counter_from_time_upcome(Upcome_timer[pro_id])+'</b></font>';
			else
			    document.getElementById('upcome_timeid_'+pro_id).innerHTML = '<font color="#3fa30e"><b>' + calc_counter_from_time_upcome(Upcome_timer[pro_id])+'</b></font>';
		 }else
			document.getElementById('upcome_timeid_'+pro_id).innerHTML = '<font color="#3fa30e"><b>--:--:--</b></font>';
			
		Upcome_timer[pro_id]=(Upcome_timer[pro_id]-1);	
	  }
	}
	setTimeout('Upcome_reverse_timer();', 950); 
}

function calc_counter_from_time_upcome(diff) 
{

  if (diff > 0) {
	  
	 
	hours=Math.floor(diff / 3600)

    minutes=Math.floor((diff / 3600 - hours) * 60)

    seconds=Math.round((((diff / 3600 - hours) * 60) - minutes) * 60)
  } else {
	days=0;
    hours = 0;
    minutes = 0;
    seconds = 0;
  }

  if (seconds == 60) {
    seconds = 0;
  }

  if (minutes < 10) {
    if (minutes < 0) {
      minutes = 0;
    }
    minutes = '0' + minutes;
  }
  if (seconds < 10) {
    if (seconds < 0) {
      seconds = 0;
    }
    seconds = '0' + seconds;
  }
  if (hours < 10) {
    if (hours < 0) {
      hours = 0;
    }
    hours = '0' + hours;
  }
  

  return hours + " : " + minutes + " : " + seconds;
}


