// declare new variables for each new div that you add, and link to the div by ID
// var region_div = document.getElementById("region_div");
var doc = null;
var SITEURL;
function ajax()
{
    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 Valid_username(login){
		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.php?section=username&login="+login, false); 
	       doc.send(null);
		    
	      return  doc.responseText;
	    }
}

function Valid_mobile(tel){
		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.php?section=mobile&tel="+tel, false); 
	       doc.send(null);
	      return  doc.responseText;
	    }
}

function Edit_Valid_mobile(tel){
    	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.php?section=edit_mobile&tel="+tel, false); 
	       doc.send(null);
		  
	      return  doc.responseText;
	    }
}

function Edit_Valid_username(login){
    	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.php?section=edit_username&login="+login, false); 
	       doc.send(null);
		  
	      return  doc.responseText;
	    }
}



function Valid_email(email){
		
    	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.php?section=email&email="+email, false);   
	       doc.send(null);
	      return  doc.responseText;
	    }
}

function Edit_Valid_email(email){
		
    	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.php?section=edit_email&email="+email, false);   
	       doc.send(null);
	      return  doc.responseText;
	    }
}


function Admin_Valid_username(login){
		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.php?section=admin_username&login="+login, false); 
	       doc.send(null);
	      return  doc.responseText;
	    }
}


function Admin_Valid_mobile(tel){
		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.php?section=admin_mobile&mobile="+mobile, false); 
	       doc.send(null);
	      return  doc.responseText;
	    }
}

function Admin_Edit_Valid_mobile(mobile,edit_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.php?section=admin_edit_mobile&mobile="+mobile+"&user_id="+edit_id, false); 
	       doc.send(null);
		  
	      return  doc.responseText;
	    }
}

function Admin_Edit_Valid_username(login,edit_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.php?section=admin_edit_username&login="+login+"&user_id="+edit_id, false); 
	       doc.send(null);

	      return  doc.responseText;
	    }
}

function Admin_Valid_email(email){
		
    	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.php?section=admin_email&email="+email, false);   
	       doc.send(null);
	      return  doc.responseText;
	    }
}

function Admim_Edit_Valid_email(email,edit_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.php?section=admin_edit_email&email="+email+"&user_id="+edit_id, false);   
	       doc.send(null);
	      return  doc.responseText;
	    }
}


function Update_reverse_bid_auction()
	{
		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.php?section=update_reverse_auction", false);   
	       doc.send(null);
			}
		//setTimeout('Update_bid_auction();',10000);		
	}


function Update_session()
	{
		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.php?section=update_session", false);   
	       doc.send(null);
			}
		//setTimeout('Update_session();',10000);		
	}

function Expire_reverse_bid(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.php?section=expire_reverse_bid&pro_id=" + pro_id, false);
 			doc.send(null);
			Get_Reverse_Max_Bid(pro_id);
			}
}

function Expire_normal_product() {
    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.php?section=expire_normal_product", false);
 			doc.send(null);
			//alert(doc.responseText);
		}
}

function Start_reverse_auction() {
    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.php?section=start_reverse_auction", false);
 			doc.send(null);
			}
}


/*function Show_advert()
	{
		ajax();
	   if (doc){ 
	       doc.open("GET", "./location.php?Response=show_advert", false);    
	       doc.send(null);
		    document.getElementById('advert_div').innerHTML = doc.responseText;
			}
		setTimeout('Show_advert();',10000);		
	}*/	
	
function calc_counter_from_time_reverse(diff) 
{

  if (diff > 0) {
    days=Math.floor(diff / (3600*24));
		  
    hours=Math.floor((diff / 3600)-(days*24));
	  		
    minutes=Math.floor((diff / 3600 - hours -(days*24)) * 60);
	
    seconds=Math.round((((diff / 3600 - hours-(days*24)) * 60) - minutes) * 60);
  } else {
    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 days + "days,<br>"  + hours + "h:" + minutes + "m:" + seconds + "s";
}




function calc_counter_from_time_short(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 {
    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 minutes + " : " + seconds;
}


function DeleteCategory(category) {
    ajax();
	//alert(category);
		// 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.php?section=delete_category&category=" + category, false);
 			doc.send(null);
			var main_res=doc.responseText;
			if(main_res==1){
				 location.href = "index.php?show=category_setting";
			}else{
				alert("Please select category.");
			}
		}
}

function UpdateCategory(catvalue,catid) {
    ajax();
	//alert(catvalue);
		// 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.php?section=update_category&catvalue=" + catvalue +"&catid=" + catid, false);
 			doc.send(null);
			
			var main_res=doc.responseText;
			if(main_res==1){
				 location.href = "index.php?show=category_setting";
			}
		}
}

function InsertCategory(catvaluenew) {
    ajax();
	//alert(catvaluenew);
		// 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.php?section=insert_category&catvaluenew=" + catvaluenew , false);
 			doc.send(null);
			
			var main_res=doc.responseText;
			if(main_res==1){
				 location.href = "index.php?show=category_setting";
			}else if(main_res==9){
				alert("Category name exists in your.Please try another.");
			}else{
				alert("Please enter category name.");
			}
		}
}

function Valid_cat(category_sub)
	{//alert(category);
	//alert(category_sub);
		ajax();
		if(doc)
		{
			
			doc.open("GET", "location.php?admin_section=sub_cat&category_sub="+category_sub, false);
			doc.send(null);
			//alert(doc.responseText);
			//return  doc.responseText;
			if(doc.responseText==1)
			{
				document.getElementById('cat_sub').innerHTML ="";
				alert("There is no sub category");
				//location.href = "admin.php?show=view_bid&action=Add";
			}
			else
			document.getElementById('cat_sub').innerHTML = doc.responseText;
		}
		
	}
	
	function Valid_cat_motor(category_sub)
	{//alert(category);
	//alert(category_sub);
		ajax();
		if(doc)
		{
			
			doc.open("GET", "location.php?admin_section=sub_cat_motor&category_sub="+category_sub, false);
			doc.send(null);
			//alert(doc.responseText);
			//return  doc.responseText;
			if(doc.responseText==1)
			{
				document.getElementById('cat_sub_motor').innerHTML ="";
				alert("There is no sub category");
				//location.href = "admin.php?show=view_bid&action=Add";
			}
			else
			document.getElementById('cat_sub_motor').innerHTML = doc.responseText;
		}
		
	}
	
	function Get_Value_Manufacture(manufactid)
	{
		ajax();
		if(doc)
		{
			
			doc.open("GET", "location.php?admin_section=cat_manufact_list&manufactid="+manufactid, false);
			doc.send(null);
			
			if(doc.responseText==1)
			{
				document.getElementById('cat_manufact').innerHTML ="";
				alert("There is no Manufacturer");
				
			}
			else
			document.getElementById('cat_manufact').innerHTML = doc.responseText;
		}
		
	}
	
	function Get_Value_ModelList(modelid)
	{
		ajax();
		if(doc)
		{
			
			doc.open("GET", "location.php?admin_section=cat_model_list&modelid="+modelid, false);
			doc.send(null);
			
			if(doc.responseText==1)
			{
				document.getElementById('cat_model').innerHTML ="";
				alert("There is no Models");
				
			}
			else
			document.getElementById('cat_model').innerHTML = doc.responseText;
		}
		
	}
	
	function change_structure_field(auctiontype)
	{
		ajax();
		if(doc)
		{
			
			doc.open("GET", "location.php?admin_section=changetable&auctiontype="+auctiontype, false);
			doc.send(null);
			
			document.getElementById('changedivtable').innerHTML = doc.responseText;
		}
		
	}
	
	function change_motor_field(auctiontype)
	{
		ajax();
		if(doc)
		{
			
			doc.open("GET", "location.php?admin_section=changemotor&auctiontype="+auctiontype, false);
			doc.send(null);
			
			document.getElementById('changedivmotor').innerHTML = doc.responseText;
		}
		
	}
	
	function change_property_field(proptype)
	{
		ajax();
		if(doc)
		{
			
			doc.open("GET", "location.php?admin_section=changeproperty&proptype="+proptype, false);
			doc.send(null);
			
			document.getElementById('changedivproperty').innerHTML = doc.responseText;
		}
		
	}
	
	function Show_product_details(URL)
	{
	   
	   var arraylist=URL.split("=");
	   var arraylist1=URL.split("-");
	   
	   var urlid;
	   if(arraylist[2]){
		   urlid=arraylist[2];
	   }else{
		  var urltemp=arraylist1[1].split(".");
		  urlid=urltemp[0];
	   }
	   
	   ajax();
		if(doc)
		{
			
			doc.open("GET", SITEURL+"/location.php?admin_section=showprodetail&prourl="+urlid, false);
			doc.send(null);
			
			document.location=URL;
		}
	
	}
	
	function add_to_watchlist(item_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.php?section=add_to_watchlist&item_id=" + item_id, false);
		   	doc.send(null);
			
			if(doc.responseText==1)
				alert("Product is added to your watchlist successfully.");
			else if(doc.responseText==2)
				alert("Product is added to your watchlist already.");
			}
}


	function add_to_favorite_seller(item_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.php?section=add_to_favorite_seller&item_id=" + item_id, false);
		   	doc.send(null);
			
			if(doc.responseText==1)
				alert("Seller is added to your favorite seller successfully.");
			else if(doc.responseText==2)
				alert("Seller is added to your favorite seller already.");
			}
}




function showAllCats(){
	var div=window.document.getElementById('allCats');
	if(div.style.display=="none"){
		div.style.display="block";
		div.style.left=(findPos(window.document.getElementById('menu'))-1);
	}
}

function findPos(obj) {
	var curleft = curtop = 0;

	if (obj.offsetParent) {
		do {
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
		} while (obj = obj.offsetParent);
	}
	return curleft;
	//return [curleft,curtop];
}


function hideCats(){
	var div=window.document.getElementById('allCats');
	if(div.style.display=="block"){
		div.style.display="none";
	}
}

function showDdeals(chk){
	//alert(chk.checked)
	var ddls=window.document.getElementById('dailydeals');
	if(chk.checked) ddls.style.display="block";
	else ddls.style.display="none";
}

function chk(){
	return confirm("Are you sure?");
}

function ShowChangeNews(categorynum) {
    ajax();
	//alert(changetype);
		// 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.php?section=change_newslist&categorynum=" + categorynum, false);
 			doc.send(null);
			document.getElementById('change_newsdiv').innerHTML = doc.responseText;
			}
}

function showAllCatsMotors(item_id){
	//alert(item_id);
	var div=window.document.getElementById('allCats_'+ item_id);
	if(div.style.display=="none"){
		div.style.display="block";
		div.style.left=(findPosMotors(window.document.getElementById('menu'))-1);
	}
}

function findPosMotors(obj) {
	var curleft = curtop = 0;

	if (obj.offsetParent) {
		do {
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
		} while (obj = obj.offsetParent);
	}
	return curleft;
	//return [curleft,curtop];
}


function hideCatsMotors(item_id){
	var div=window.document.getElementById('allCats_'+ item_id);
	if(div.style.display=="block"){
		div.style.display="none";
	}
}



function showHide(id){
	var div=window.document.getElementById(id);
	var lmargin=0;
	if(div.style.display=="inline"){
		div.style.display="none";
	}else if(div.style.display=="none"){
		div.style.display="inline";
		if(id=='sell_dd') lmargin=50;
		if(id=='community_dd') lmargin=180;
		//div.style.left=(findPos(window.document.getElementById('topdd'))-1)+lmargin;
		
	}
}

function Valid_model_motor(manuf_id)
	{
		ajax();
		if(doc)
		{
			doc.open("GET", SITEURL+"/location.php?admin_section=models_motor&manuf_id="+manuf_id, false);
			doc.send(null);
			document.getElementById('models_div').innerHTML = doc.responseText;
		}
		
	}
	
function Get_Body_type(subcate_id)
	{
		ajax();
		if(doc)
		{
			
			doc.open("GET", "location.php?admin_section=bodytype_motor&subcate_id="+subcate_id, false);
			doc.send(null);
			
			document.getElementById('bodytype_div').innerHTML = doc.responseText;
		}
		
	}
	
function ListingFeesList(catid,listid,startval)
	{
		
		ajax();
		//alert(startval);
		if(doc)
		{
			
			doc.open("GET", "location.php?admin_section=listing_fees&catid="+catid +"&listid=" + listid +"&startval=" + startval, false);
			doc.send(null);
			//alert(doc.responseText);
			document.getElementById('listingfees_div').innerHTML = doc.responseText;
		}
		
	}
	
	function AddShippingPrice(shipprice,flvalprice)
	{
		
		ajax();
		if(doc)
		{
			
			doc.open("GET", "location.php?admin_section=shipping_fees&shipprice="+shipprice +"&flvalprice=" + flvalprice, false);
			doc.send(null);
			//alert(doc.responseText);
			document.getElementById('flvalprice_div').innerHTML = doc.responseText;
		}
		
	}
	
	function GetUPSRates(zip_code,city_text,state_drop,shipdrop,itemid)
	{
		
		ajax();
		
		if(doc)
		{
			
			doc.open("GET", "location.php?admin_section=getups_rates&zip_code="+zip_code +"&city_text=" + city_text +"&state_drop=" + state_drop +"&shipdrop=" + shipdrop +"&itemid=" + itemid, false);
			doc.send(null);
			if(doc.responseText!=0)
			{
			   //alert(doc.responseText);	
		       var arraylist=doc.responseText.split("**");
			   document.getElementById('shiprate_div').innerHTML = arraylist[0];
			   document.getElementById('tocity_div').innerHTML = arraylist[1];
			}else
			{
			   alert("Please entry valid data.");	
			}
		}
		
	}
	
	function Valid_State_Drop(country_id)
	{
		
		ajax();
		
		if(doc)
		{
			
			doc.open("GET", "location.php?admin_section=get_states&country_id="+country_id, false);
			doc.send(null);
			document.getElementById('states_div').innerHTML = doc.responseText;
		}
		
	}