var xmlHttp
var inObj
var outObj
function GetXmlHttpObject()
{
	var xmlHttp=null;
	try
	  {
	  // Firefox, Opera 8.0+, Safari
	  xmlHttp=new XMLHttpRequest();
	  }
	catch (e)
	  {
	  // Internet Explorer
	  try
		{
		xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
	  catch (e)
		{
		xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	  }
	return xmlHttp;
}
//Shoping Cart
function addToCart( pid, indicator, cartitem, carttotal, quantity) {
	document.getElementById(indicator).innerHTML="<img src='images/indicator.gif'></img>";
	var xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null){
	  alert ("Your browser does not support AJAX!");
	  return;
	} 
	var url="ajax/ProcessCart.aspx?act=add&id="+pid;
	if (document.getElementById(quantity)) {
		if (!isNaN(document.getElementById(quantity).value)) {
			if (parseInt(document.getElementById(quantity).value) > 0) {
				url+="&quantity="+parseInt(document.getElementById(quantity).value);
			}
		}
	}
	url=url+"&sid="+Math.random();
	xmlHttp.onreadystatechange=function (){
		if (xmlHttp.readyState==4) { 
			var product = xmlHttp.responseXML.getElementsByTagName('product');
			document.getElementById(cartitem).innerHTML=product.length;
			var tmpTotal = 0;
			var tmpQuantity = 0;
			//for (i=0; i<product.length; i++) {
			//	tmpQuantity += parseInt(getNodeValue(product[i],'quantity'));
				//tmpTotal += getNodeValue(product[i],'price') * getNodeValue(product[i],'quantity');
			//	if (tmpTotal < parseInt(getNodeValue(product[i],'grandtotal')))
			//		tmpTotal = parseInt(getNodeValue(product[i],'grandtotal'));
			//}
			if (product.length > 0) {
				tmpQuantity = parseInt(getNodeValue(product[0],'grandqty'));
				tmpTotal = parseInt(getNodeValue(product[0],'grandtotal'));
			}else{
				tmpQuantity = 0;
				tmpTotal = 0;
			}
			document.getElementById(cartitem).innerHTML=tmpQuantity;
			document.getElementById(carttotal).innerHTML=formatCurrency(tmpTotal);
			document.getElementById(indicator).innerHTML = "";
			xmlHttp = null;
			delete(xmlHttp);
			alert(LABEL_AddToCart);
		}
	}
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}
function removeFromCart(pos, pid, indicator, cartitem, carttotal) {
	document.getElementById(indicator).innerHTML="<img src='images/indicator.gif'></img>";
	var xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null){
	  alert ("Your browser does not support AJAX!");
	  return;
	} 
	var url="ajax/ProcessCart.aspx?act=remove&id="+pid;
	url=url+"&sid="+Math.random();
	xmlHttp.onreadystatechange=function (){
		if (xmlHttp.readyState==4) { 
			window.location.reload(true);
			/*var product = xmlHttp.responseXML.getElementsByTagName('product');
			var tobj = document.getElementById("tbcart");
			var tmpLength = tobj.tBodies[0].rows.length;
			for (var i=0; i<tmpLength; i++) {
				tobj.tBodies[0].deleteRow(0);
			}
			var tmpTotal = 0;
			var tmpQuantity = 0;
			for (i=0; i<product.length; i++) {
				tmpTotal += getNodeValue(product[i],'price') * getNodeValue(product[i],'quantity');
				tmpQuantity += parseInt(getNodeValue(product[i],'quantity'));
				var newrow = tobj.tBodies[0].insertRow(0);
				
				var cell1 = document.createElement('td');
				var cell1_a = document.createElement('a');
				cell1_a.setAttribute('href', "javascript: removeFromCart(\'"+i+"\',\'"+getNodeValue(product[i],'id')+"\',\'"+indicator+"\',\'"+cartitem+"\',\'"+carttotal+"\');");
				cell1_a.setAttribute('title', "Remove" + getNodeValue(product[i],'name'));
				cell1_a.innerHTML = "Remove";
				
				var cell2 = document.createElement('td');
				var cell2_a = document.createElement('a');
				cell2_a.setAttribute('href', "ProductDetail.aspx?productid="+getNodeValue(product[i],'id'));
				cell2_a.setAttribute('title', getNodeValue(product[i],'name'));
				cell2_a.innerHTML = getNodeValue(product[i],'name');
				
				var cell3 = document.createElement('td');
				cell3.className = "cart-col3";
				
				var cell4 = document.createElement('td');
				var cell4_text = document.createElement('input');
				cell4_text.setAttribute('type', "input");
				cell4_text.setAttribute('id', getNodeValue(product[i],'id'));
				cell4_text.setAttribute('name', getNodeValue(product[i],'id'));
				cell4_text.setAttribute('value', getNodeValue(product[i],'quantity'));
				cell4_text.className = "txt_qty";
				
				var cell5 = document.createElement('td');
				var cell5_text = document.createTextNode("$");
				var cell5_span = document.createElement('span');
				cell5_span.setAttribute('id', "t_"+getNodeValue(product[i],'id'));
				cell5_span.innerHTML = formatCurrency(getNodeValue(product[i],'price') * getNodeValue(product[i],'quantity'));
				
				cell1.appendChild(cell1_a);
				cell2.appendChild(cell2_a);
				cell3.appendChild(document.createTextNode("$ " + formatCurrency(getNodeValue(product[i],'price'))));
				cell4.appendChild(cell4_text);
				cell5.appendChild(cell5_text);
				cell5.appendChild(cell5_span);
				newrow.appendChild(cell2);
				newrow.appendChild(cell4);
				newrow.appendChild(cell3);
				//newrow.appendChild(cell5);
				newrow.appendChild(cell1);
			}
			document.getElementById("overtotal").innerHTML = formatCurrency(tmpTotal);
			document.getElementById(cartitem).innerHTML=tmpQuantity;
			document.getElementById(carttotal).innerHTML=formatCurrency(tmpTotal);*/
			document.getElementById(indicator).innerHTML="";
			xmlHttp = null;
			delete(xmlHttp);
		}
	}
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}
function updateCart(obj, indicator, cartitem, carttotal) {
	var xmlStr = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>"
	xmlStr += "<root>"
  	var inputList = obj.getElementsByTagName("input");
	for (i=0; i<inputList.length; i++) {
		if (inputList[i].type == "text") {
			xmlStr += "<product>"
			xmlStr += "<id>"+inputList[i].id+"</id>"
			xmlStr += "<quantity>"+inputList[i].value+"</quantity>"
			xmlStr += "</product>"
			document.getElementById("p_"+inputList[i].id)
		}
	}
	xmlStr += "</root>"
	document.getElementById(indicator).innerHTML="<img src='images/indicator.gif'></img>";
	var xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null){
	  alert ("Your browser does not support AJAX!");
	  return;
	} 
	var url="ajax/ProcessCart.aspx?act=update&xml="+xmlStr;
	url=url+"&sid="+Math.random();
	xmlHttp.onreadystatechange=function (){
		if (xmlHttp.readyState==4) { 
			window.location.reload(true);
			/*var product = xmlHttp.responseXML.getElementsByTagName('product');
			document.getElementById(cartitem).innerHTML=product.length;
			var tmpTotal = 0;
			for (i=0; i<product.length; i++) {
				tmpTotal += getNodeValue(product[i],'price') * getNodeValue(product[i],'quantity');
			}
			document.getElementById("overtotal").innerHTML = tmpTotal.toFixed(2);
			document.getElementById(carttotal).innerHTML = tmpTotal.toFixed(2);*/
			document.getElementById(indicator).innerHTML="";
			xmlHttp = null;
			delete(xmlHttp);
		}
	}
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}
function setShippingCost(obj, costspan, totalspan)
{
  var oldcost = parseFloat(document.getElementById(costspan).innerHTML);
  var getstr = "?&shipping_id="+obj.value;
	var xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null) {
		  alert ("Your browser does not support AJAX!");
		  return;
	} 
    xmlHttp.onreadystatechange = function () {
	  if (xmlHttp.readyState == 4) {
		window.location.reload(true);
		/*document.getElementById(costspan).innerHTML = parseFloat(xmlHttp.responseText).toFixed(2);
		document.getElementById(totalspan).innerHTML = (parseFloat(document.getElementById(totalspan).innerHTML) - oldcost + parseFloat(xmlHttp.responseText)).toFixed(2);*/
	  }
	}
	getstr += "&sid="+Math.random();
    xmlHttp.open('POST', "Ajax/SetShippingCost.aspx", true);
    xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlHttp.setRequestHeader("Content-length", getstr.length);
    xmlHttp.setRequestHeader("Connection", "close");
    xmlHttp.send(getstr);
}
function getNodeValue(obj,tag)
{
	return obj.getElementsByTagName(tag)[0].firstChild.nodeValue;
}
//End Shoping Cart
function checkEmail(pre, sinObj, soutObj)
{
	if (document.getElementById(sinObj).value.length==0) { 
		document.getElementById(soutObj).innerHTML="";
		return;
	}
	if (document.getElementById(sinObj).value == pre) {
		return;
	}
	document.getElementById(soutObj).innerHTML="<img src='images/indicator.gif' alt='Processing...' />";
	var xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null)
	  {
	  alert ("Your browser does not support AJAX!");
	  return;
	  } 
	var url="Ajax/Check_Email.aspx";
	url=url+"?email="+document.getElementById(sinObj).value;
	url=url+"&sid="+Math.random();
	xmlHttp.onreadystatechange=function (){
		if (xmlHttp.readyState==4)
		{ 
			document.getElementById(soutObj).innerHTML=xmlHttp.responseText;
		}
	}
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}
function sendContact(obj) {
  var getstr = "?";
  var inputList = obj.getElementsByTagName("input");
  for (i=0; i<inputList.length; i++) {
	 if (inputList[i].type == "text" || inputList[i].type == "password" || inputList[i].type == "hidden") {
		   getstr += inputList[i].name + "=" + encodeURI(inputList[i].value) + "&";
		   inputList[i].value = "";
	 }   
  }
  var textareaList = obj.getElementsByTagName("textarea");
  for (i=0; i<textareaList.length; i++) {
	   getstr += textareaList[i].name + "=" + textareaList[i].value + "&";
	   textareaList[i].value = "";
  }
  makePOSTRequest('Ajax/SendContact.aspx', getstr);
}
function postReview(obj, outobj) {
  var getstr = "?";
  var inputList = obj.getElementsByTagName("input");
  for (i=0; i<inputList.length; i++) {
	 if (inputList[i].type == "text" || inputList[i].type == "password" || inputList[i].type == "hidden") {
		   getstr += "&" + inputList[i].name + "=" + encodeURI(inputList[i].value);
		   if (inputList[i].type == "text") inputList[i].value = "";
	 }   
  }
  var selectList = obj.getElementsByTagName("select");
  for (i=0; i<selectList.length; i++) {
	getstr +=  "&" + selectList[i].name + "=" + encodeURI(selectList[i].value);
  }	
  var textareaList = obj.getElementsByTagName("textarea");
  for (i=0; i<textareaList.length; i++) {
	   getstr += "&" + textareaList[i].name + "=" + textareaList[i].value;
	   textareaList[i].value = "";
  }
	document.getElementById("myspan").innerHTML="<img src='images/indicator.gif' alt='Processing...' />";
	var xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null) {
		  alert ("Your browser does not support AJAX!");
		  return;
	} 
    xmlHttp.onreadystatechange = function () {
	  if (xmlHttp.readyState == 4) {
		outobj.innerHTML = xmlHttp.responseText;
		//document.getElementById('myspan').innerHTML = "The review has been sent.";
		document.getElementById('myspan').innerHTML = document.getElementById('messagespan').innerHTML;
		$("#allreviews").click(function(event){
			event.preventDefault();
			var _pid = document.getElementById('productid').value;
			if (!_pid) return;
			window.open ('/Ajax/ShowReview.aspx?productid=' + _pid, 'ProductReview', sFuture);
		});
	  }
	}
	getstr += "&sid="+Math.random();
    xmlHttp.open('POST', "Ajax/PostReview.aspx", true);
    xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlHttp.setRequestHeader("Content-length", getstr.length);
    xmlHttp.setRequestHeader("Connection", "close");
    xmlHttp.send(getstr);
}
function requestPassword(obj) {
  var getstr = "?";
  var inputList = obj.getElementsByTagName("input");
  for (i=0; i<inputList.length; i++) {
	 if (inputList[i].type == "text" || inputList[i].type == "password" || inputList[i].type == "hidden") {
		   getstr += "&" + inputList[i].name + "=" + encodeURI(inputList[i].value);
		   //inputList[i].value = "";
	 }   
  }
  makePOSTRequest('Ajax/RequestPassword.aspx', getstr);
}
function subscribeNewsLetter(obj) {
  document.getElementById('subscribe').innerHTML="<img src='images/indicator.gif' alt='Processing...' />";
  var getstr = "?";
  var inputList = obj.getElementsByTagName("input");
  for (i=0; i<inputList.length; i++) {
	 if (inputList[i].type == "text" || inputList[i].type == "hidden") {
		   getstr += "&" + inputList[i].name + "=" + encodeURI(inputList[i].value);
		   //inputList[i].value = "";
	 }   
  }
	var xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null) {
		  alert ("Your browser does not support AJAX!");
		  return;
	} 
    xmlHttp.onreadystatechange = function () {
	  if (xmlHttp.readyState == 4) {
		document.getElementById('subscribe').innerHTML = xmlHttp.responseText;
	  }
	}
	getstr += "&sid="+Math.random();
    xmlHttp.open('POST', "Ajax/SubscribeNewsLetter.aspx", true);
    xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlHttp.setRequestHeader("Content-length", getstr.length);
    xmlHttp.setRequestHeader("Connection", "close");
    xmlHttp.send(getstr);
}
function login(obj, sout) {
  var getstr = "?";
  var outObj = document.getElementById(sout);
  var inputList = obj.getElementsByTagName("input");
  for (i=0; i<inputList.length; i++) {
	 if (inputList[i].type == "text" || inputList[i].type == "password" || inputList[i].type == "hidden") {
		   getstr += inputList[i].name + "=" + encodeURI(inputList[i].value) + "&";
	 }   
  }
	var xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null) {
		  alert ("Your browser does not support AJAX!");
		  return;
	} 
    xmlHttp.onreadystatechange = function () {
	  if (xmlHttp.readyState == 4) {
		//document.getElementById('myspan').className = "msg warning";
//		if (xmlHttp.responseText == "email not found") {
//			document.getElementById('myspan').innerHTML = "Email not found!";
//		}
//		else if (xmlHttp.responseText == "not found") {
//			document.getElementById('myspan').innerHTML = "Email and password not match!";
//		}
//		else if (xmlHttp.responseText == "input error") {
//			document.getElementById('myspan').innerHTML = "Fill the input field before login!";
//		}
//		else {
//			outObj.innerHTML = xmlHttp.responseText;
//		}
		outObj.innerHTML = xmlHttp.responseText.substring(5);
	  }
	}
    xmlHttp.open('POST', "Ajax/Login.aspx", true);
    xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlHttp.setRequestHeader("Content-length", getstr.length);
    xmlHttp.setRequestHeader("Connection", "close");
    xmlHttp.send(getstr);
}
function loginfull(obj, sout) {
  var getstr = "?";
  var outObj = document.getElementById(sout);
  var inputList = obj.getElementsByTagName("input");
  for (i=0; i<inputList.length; i++) {
	 if (inputList[i].type == "text" || inputList[i].type == "password" || inputList[i].type == "hidden") {
		   getstr += inputList[i].name + "=" + encodeURI(inputList[i].value) + "&";
	 }   
  }
	var xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null) {
		  alert ("Your browser does not support AJAX!");
		  return;
	} 
    xmlHttp.onreadystatechange = function () {
	  if (xmlHttp.readyState == 4) {
		if (xmlHttp.responseText.indexOf("error") == -1) {
			//document.getElementById('myspan').innerHTML = "Sign in successfull.";
			window.location = xmlHttp.responseText;
		}
		else {
			document.getElementById('myspan').innerHTML = xmlHttp.responseText.substring(5);
			if (xmlHttp.responseText.substring(5) != '') 
				document.getElementById('myspan').style.display = 'block';
		}
	  }
	}
    xmlHttp.open('POST', "Ajax/LoginFull.aspx", true);
    xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlHttp.setRequestHeader("Content-length", getstr.length);
    xmlHttp.setRequestHeader("Connection", "close");
    xmlHttp.send(getstr);
}
function registerAccount(obj) {
  var getstr = "?";
  var inputList = obj.getElementsByTagName("input");
  var selectList = obj.getElementsByTagName("select");
  for (i=0; i<inputList.length; i++) {
	 if (inputList[i].type == "text" || inputList[i].type == "password" || inputList[i].type == "hidden") {
		getstr +=  "&" + inputList[i].name + "=" + encodeURI(inputList[i].value);
	 }
	 if (inputList[i].type == "checkbox" && inputList[i].checked) {
		getstr +=  "&" + inputList[i].name + "=" + encodeURI(inputList[i].value);
	 }
  }	
  for (i=0; i<selectList.length; i++) {
	getstr +=  "&" + selectList[i].name + "=" + encodeURI(selectList[i].value);
  }	
	document.getElementById('myspan').className = "msg warning";
	document.getElementById('myspanex').className = "msg warning";
	document.getElementById("myspan").innerHTML="<img src='images/indicator.gif' alt='Processing...' />";
	document.getElementById("myspanex").innerHTML="<img src='images/indicator.gif' alt='Processing...' />";
	var xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null) {
		  alert ("Your browser does not support AJAX!");
		  return;
	} 
    xmlHttp.onreadystatechange = function () {
	  if (xmlHttp.readyState == 4) {
		if (xmlHttp.responseText.indexOf("error") != 0) {
			//document.getElementById('myspan').innerHTML = "<p>You have successful registered with us.</p><p>Please check your email and follow the instructions to complete your registration. Thank you! <a href='"+xmlHttp.responseText+"' title='Back'>Click here</a> to return </p>";
			//document.getElementById('myspanex').innerHTML = "<p>You have successful registered with us.</p><p>Please check your email and follow the instructions to complete your registration. Thank you! <a href='"+xmlHttp.responseText+"' title='Back'>Click here</a> to return </p>";
			//window.location = xmlHttp.responseText;
			document.getElementById('myspan').innerHTML = xmlHttp.responseText;
			document.getElementById('myspanex').innerHTML = xmlHttp.responseText;
			document.getElementById('myspan').className = 'msg success';
			document.getElementById('myspanex').className = 'msg success';
		}
		else {
			document.getElementById('myspan').innerHTML = xmlHttp.responseText.substring(5);
			document.getElementById('myspanex').innerHTML = xmlHttp.responseText.substring(5);
		}
	  }
	}
    xmlHttp.open('POST', 'Ajax/Register.aspx', true);
    xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlHttp.setRequestHeader("Content-length", getstr.length);
    xmlHttp.setRequestHeader("Connection", "close");
    xmlHttp.send(getstr);
}
function updateAccInfo(obj) {
  var getstr = "?";
  var inputList = obj.getElementsByTagName("input");
  var selectList = obj.getElementsByTagName("select");
  for (i=0; i<inputList.length; i++) {
	 if (inputList[i].type == "text" || inputList[i].type == "password" || inputList[i].type == "hidden") {
		getstr +=  "&" + inputList[i].name + "=" + encodeURI(inputList[i].value);
	 }
	 if (inputList[i].type == "checkbox" && inputList[i].checked) {
		getstr +=  "&" + inputList[i].name + "=" + encodeURI(inputList[i].value);
	 }
  }	
  for (i=0; i<selectList.length; i++) {
	getstr +=  "&" + selectList[i].name + "=" + encodeURI(selectList[i].value);
  }	
	document.getElementById('myspan').className = "msg warning";
	document.getElementById('myspanex').className = "msg warning";
	document.getElementById("myspan").innerHTML="<img src='images/indicator.gif' alt='Processing...' />";
	document.getElementById("myspanex").innerHTML="<img src='images/indicator.gif' alt='Processing...' />";
	var xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null) {
		  alert ("Your browser does not support AJAX!");
		  return;
	} 
    xmlHttp.onreadystatechange = function () {
	  if (xmlHttp.readyState == 4) {
		if (xmlHttp.responseText.indexOf("error") != 0) {
			document.getElementById('myspan').innerHTML = xmlHttp.responseText;
			document.getElementById('myspanex').innerHTML = xmlHttp.responseText;
		}
		else {
			if (xmlHttp.responseText.substring(5)=='InvalidSession'){
				window.location = 'login.aspx';
			}
			if (xmlHttp.responseText.substring(5)!='') {
				document.getElementById('myspan').innerHTML = xmlHttp.responseText.substring(5);
				document.getElementById('myspanex').innerHTML = xmlHttp.responseText.substring(5);
			}
		}
	  }
	}
    xmlHttp.open('POST', 'Ajax/ChangeProfile.aspx', true);
    xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlHttp.setRequestHeader("Content-length", getstr.length);
    xmlHttp.setRequestHeader("Connection", "close");
    xmlHttp.send(getstr);
}
function changeLanguage(lang)
{
    var getstr = "?";
	var xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null)
	  {
	  alert ("Your browser does not support AJAX!");
	  return;
	  } 
	var url="Ajax/Change_Language.aspx";
	getstr += "&lang="+lang;
	getstr += "&sid="+Math.random();
	xmlHttp.onreadystatechange=function (){
		if (xmlHttp.readyState==4)
		{ 
			window.location.reload(true);
		}
	}
    xmlHttp.open('POST', url, true);
    xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlHttp.setRequestHeader("Content-length", getstr.length);
    xmlHttp.setRequestHeader("Connection", "close");
    xmlHttp.send(getstr);
}
/*==================== Check out Process ====================*/
function checkOutStep1(obj) {
  var getstr = "?&step=1";
  var inputList = obj.getElementsByTagName("input");
  var selectList = obj.getElementsByTagName("select");
  for (i=0; i<inputList.length; i++) {
	 if (inputList[i].type == "text" || inputList[i].type == "password" || inputList[i].type == "hidden") {
		getstr +=  "&" + inputList[i].name + "=" + encodeURI(inputList[i].value);
	 }
	 if (inputList[i].type == "checkbox" && inputList[i].checked) {
		getstr +=  "&" + inputList[i].name + "=" + encodeURI(inputList[i].value);
	 }
  }	
  for (i=0; i<selectList.length; i++) {
	getstr +=  "&" + selectList[i].name + "=" + encodeURI(selectList[i].value);
  }	
	document.getElementById("myspan").innerHTML="<img src='images/indicator.gif' alt='Processing...' />";
	var xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null) {
		  alert ("Your browser does not support AJAX!");
		  return;
	} 
    xmlHttp.onreadystatechange = function () {
	  if (xmlHttp.readyState == 4) {
		document.getElementById('myspan').className = "msg success";
		if (xmlHttp.responseText.indexOf("error") != 0) {
			//document.getElementById('myspan').innerHTML = xmlHttp.responseText;
			//setTimeout("changePage('CheckOutStep2.aspx')",5000);
			changePage('CheckOutStep2.aspx');
		}
		else {
			if (xmlHttp.responseText.substring(5)=='InvalidSession'){
				window.location = 'login.aspx';
			}
			if (xmlHttp.responseText.substring(5)=='NoCart'){
				window.location = 'shoppingcart.aspx';
			}
			if (xmlHttp.responseText.substring(5)!='') {
				document.getElementById('myspan').innerHTML = xmlHttp.responseText.substring(5);
			}
		}
	  }
	}
    xmlHttp.open('POST', 'Ajax/ProcessCheckOut.aspx', true);
    xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlHttp.setRequestHeader("Content-length", getstr.length);
    xmlHttp.setRequestHeader("Connection", "close");
    xmlHttp.send(getstr);
}
function checkOutStep2(obj) {
  var getstr = "?&step=2";
  var inputList = obj.getElementsByTagName("input");
  var selectList = obj.getElementsByTagName("select");
  for (i=0; i<inputList.length; i++) {
	 if (inputList[i].type == "text" || inputList[i].type == "password" || inputList[i].type == "hidden") {
		getstr +=  "&" + inputList[i].name + "=" + encodeURI(inputList[i].value);
	 }
	 if (inputList[i].type == "checkbox" && inputList[i].checked) {
		getstr +=  "&" + inputList[i].name + "=" + encodeURI(inputList[i].value);
	 }
  }	
  for (i=0; i<selectList.length; i++) {
	getstr +=  "&" + selectList[i].name + "=" + encodeURI(selectList[i].value);
  }	
	document.getElementById("myspan").innerHTML="<img src='images/indicator.gif' alt='Processing...' />";
	var xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null) {
		  alert ("Your browser does not support AJAX!");
		  return;
	} 
    xmlHttp.onreadystatechange = function () {
	  if (xmlHttp.readyState == 4) {
		document.getElementById('myspan').className = "msg success";
		if (xmlHttp.responseText.indexOf("error") != 0) {
			//document.getElementById('myspan').innerHTML = xmlHttp.responseText;
			//setTimeout("changePage('CheckOutStep3.aspx')",5000);
			changePage('CheckOutStep3.aspx');
		}
		else {
			if (xmlHttp.responseText.substring(5)=='InvalidSession'){
				window.location = 'login.aspx';
			}
			if (xmlHttp.responseText.substring(5)=='NoCart'){
				window.location = 'shoppingcart.aspx';
			}
			if (xmlHttp.responseText.substring(5)!='') {
				document.getElementById('myspan').innerHTML = xmlHttp.responseText.substring(5);
			}
		}
	  }
	}
    xmlHttp.open('POST', 'Ajax/ProcessCheckOut.aspx', true);
    xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlHttp.setRequestHeader("Content-length", getstr.length);
    xmlHttp.setRequestHeader("Connection", "close");
    xmlHttp.send(getstr);
}
function checkOutStep3(obj) {
  var getstr = "?&step=3";
  var inputList = obj.getElementsByTagName("input");
  var selectList = obj.getElementsByTagName("select");
  for (i=0; i<inputList.length; i++) {
	 if (inputList[i].type == "text" || inputList[i].type == "password" || inputList[i].type == "hidden") {
		getstr +=  "&" + inputList[i].name + "=" + encodeURI(inputList[i].value);
	 }
	 if (inputList[i].type == "checkbox" && inputList[i].checked) {
		getstr +=  "&" + inputList[i].name + "=" + encodeURI(inputList[i].value);
	 }
	 if (inputList[i].type == "radio" && inputList[i].checked) {
		getstr +=  "&" + inputList[i].name + "=" + encodeURI(inputList[i].value);
	 }
  }	
  for (i=0; i<selectList.length; i++) {
	getstr +=  "&" + selectList[i].name + "=" + encodeURI(selectList[i].value);
  }	


	document.getElementById("myspan").innerHTML="<img src='images/indicator.gif' alt='Processing...' />";
	var xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null) {
		  alert ("Your browser does not support AJAX!");
		  return;
	} 
    xmlHttp.onreadystatechange = function () {
	  if (xmlHttp.readyState == 4) {
		document.getElementById('myspan').className = "msg success";
		if (xmlHttp.responseText.indexOf("error") == -1) {
			document.getElementById('myspan').innerHTML = xmlHttp.responseText;
			window.location = "CheckOutStep4.aspx";
		}
		else {
			document.getElementById('myspan').innerHTML = xmlHttp.responseText.substring(5);
		}
	  }
	}
    xmlHttp.open('POST', 'Ajax/ProcessCheckOut.aspx', true);
    xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlHttp.setRequestHeader("Content-length", getstr.length);
    xmlHttp.setRequestHeader("Connection", "close");
    xmlHttp.send(getstr);
}
function checkOutStep4(obj) {
  var getstr = "?&step=4";
  var inputList = obj.getElementsByTagName("input");
  var selectList = obj.getElementsByTagName("select");
  for (i=0; i<inputList.length; i++) {
	 if (inputList[i].type == "text" || inputList[i].type == "password" || inputList[i].type == "hidden") {
		getstr +=  "&" + inputList[i].name + "=" + encodeURI(inputList[i].value);
	 }
	 if (inputList[i].type == "checkbox" && inputList[i].checked) {
		getstr +=  "&" + inputList[i].name + "=" + encodeURI(inputList[i].value);
	 }
  }	
  for (i=0; i<selectList.length; i++) {
	getstr +=  "&" + selectList[i].name + "=" + encodeURI(selectList[i].value);
  }	
  var textareaList = obj.getElementsByTagName("textarea");
  for (i=0; i<textareaList.length; i++) {
	   getstr += "&" + textareaList[i].name + "=" + textareaList[i].value;
	   textareaList[i].value = "";
  }
	document.getElementById("myspan").innerHTML="<img src='images/indicator.gif' alt='Processing...' />";
	var xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null) {
		  alert ("Your browser does not support AJAX!");
		  return;
	} 
    xmlHttp.onreadystatechange = function () {
	  if (xmlHttp.readyState == 4) {
		document.getElementById('myspan').className = "msg success";
		if (xmlHttp.responseText.indexOf("error") == -1) {
			document.getElementById('myspan').innerHTML = xmlHttp.responseText;
		}
		else {
			document.getElementById('myspan').innerHTML = xmlHttp.responseText.substring(5);
		}
	  }
	}
    xmlHttp.open('POST', 'Ajax/ProcessCheckOut.aspx', true);
    xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlHttp.setRequestHeader("Content-length", getstr.length);
    xmlHttp.setRequestHeader("Connection", "close");
    xmlHttp.send(getstr);
}
/*==================== End Check out Process ====================*/
function makePOSTRequest(url, parameters) {
	document.getElementById("myspan").innerHTML="<img src='images/indicator.gif' alt='Processing...' />";
	var xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null) {
		  alert ("Your browser does not support AJAX!");
		  return;
	} 
    xmlHttp.onreadystatechange = function () {
	  if (xmlHttp.readyState == 4) {
		document.getElementById('myspan').className = "msg warning";
		document.getElementById('myspan').innerHTML = xmlHttp.responseText;
	  }
	}
	parameters += "&sid="+Math.random();
    xmlHttp.open('POST', url, true);
    xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlHttp.setRequestHeader("Content-length", parameters.length);
    xmlHttp.setRequestHeader("Connection", "close");
    xmlHttp.send(parameters);
}
function setShipping(obj) {
	if (obj.checked) {
		for (var i=1; i<arguments.length; i++) {
			if (document.getElementById("txtshipping" + arguments[i])) {
				document.getElementById("txtshipping" + arguments[i]).value = document.getElementById("txtbilling" + arguments[i]).value;
			}
			if (document.getElementById("slt_shipping" + arguments[i])) {
				document.getElementById("slt_shipping" + arguments[i]).value = document.getElementById("slt_billing" + arguments[i]).value;
			}
		}
	}
	else {
		for (var i=1; i<arguments.length; i++) {
			if (document.getElementById("txtshipping" + arguments[i])) {
				document.getElementById("txtshipping" + arguments[i]).value = "";
		
			}
			if (document.getElementById("slt_shipping" + arguments[i])) {
				document.getElementById("slt_shipping" + arguments[i]).value = document.getElementById("slt_shipping" + arguments[i]).options[0].value;
			}
		}
	}
}
function setShippingEdit(obj) {
	if (obj.checked) {
		for (var i=1; i<arguments.length; i++) {
			if (document.getElementById("txtshipping" + arguments[i])) {
				document.getElementById("txtshipping" + arguments[i]).value = document.getElementById("txtbilling" + arguments[i]).value;
			}
			if (document.getElementById("slt_shipping" + arguments[i])) {
				document.getElementById("slt_shipping" + arguments[i]).value = document.getElementById("slt_billing" + arguments[i]).value;
			}
		}
	}
	else {
		for (var i=1; i<arguments.length; i++) {
			if (document.getElementById("txtshipping" + arguments[i])) {
				document.getElementById("txtshipping" + arguments[i]).value = arguments[i+6];
		
			}
			if (document.getElementById("slt_shipping" + arguments[i])) {
				document.getElementById("slt_shipping" + arguments[i]).value = arguments[i+6];
			}
		}
	}
}
function setShipping(obj) {
	if (obj.checked) {
		for (var i=1; i<arguments.length; i++) {
			if (document.getElementById("txtshipping" + arguments[i])) {
				document.getElementById("txtshipping" + arguments[i]).value = document.getElementById("txtbilling" + arguments[i]).value;
			}
			if (document.getElementById("slt_shipping" + arguments[i])) {
				document.getElementById("slt_shipping" + arguments[i]).value = document.getElementById("slt_billing" + arguments[i]).value;
			}
		}
	}
	else {
		for (var i=1; i<arguments.length; i++) {
			if (document.getElementById("txtshipping" + arguments[i])) {
				document.getElementById("txtshipping" + arguments[i]).value = "";
		
			}
			if (document.getElementById("slt_shipping" + arguments[i])) {
				document.getElementById("slt_shipping" + arguments[i]).value = document.getElementById("slt_shipping" + arguments[i]).options[0].value;
			}
		}
	}
}
var arrArg = new Array();
function setShippingCheckOut(obj, _oid, _value) {
	var _cid, _pid;
	if (!obj.checked) {
		for (var i=0; i<_oid.length; i++) {
			if (document.getElementById("txtshipping" + _oid[i])) {
				document.getElementById("txtshipping" + _oid[i]).value = arrArg[i];
			}else if (document.getElementById("slt_shipping" + _oid[i])) {
				document.getElementById("slt_shipping" + _oid[i]).value = arrArg[i];
				if (_oid[i]=='country') _cid = arrArg[i];
				if (_oid[i]=='province') _pid = arrArg[i];
			}
		}
	}
	else {
		arrArg = new Array();
		for (var i=0; i<_oid.length; i++) {
			if (document.getElementById("txtshipping" + _oid[i])) {
				arrArg.push(document.getElementById("txtshipping" + _oid[i]).value);
				document.getElementById("txtshipping" + _oid[i]).value = _value[i];
		
			}else if (document.getElementById("slt_shipping" + _oid[i])) {
				arrArg.push(document.getElementById("slt_shipping" + _oid[i]).value);
				document.getElementById("slt_shipping" + _oid[i]).value = _value[i];
				if (_oid[i]=='country') _cid = _value[i];
				if (_oid[i]=='province') _pid = _value[i];
			}
		}
	}
	getProvince('slt_shippingprovince',_cid,_pid);
}
//===========================================================================
//	Form Validation
//===========================================================================
function validate_ex(theForm, _ErrMsg, arrNotRequired) {
	validForm = true;
	firstError = null;
	errorstring = '';
	var x = document.forms[theForm].elements;
	var arr = ','+arrNotRequired.toString()+ ',';
	for (var i=0;i<x.length;i++) {
		if (x[i].type == "undefined" || x[i].type == "button" || x[i].type == "submit" || x[i].type == "reset" || x[i].type == "hidden") continue;
		if (arr.indexOf(","+x[i].name+",") > -1) continue;
		if (!x[i].value)
		{
			writeError(x[i], '*');	//_ErrMsg
			if (firstError ==null)
			firstError = x[i];
		}
		if (x[i].name == 'txtemail')
		{
			var strEmail = /^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$/;
			if(!strEmail.test(x[i].value))
				writeError(x[i],'*');
		}
		if (x[i].name == 'txtconfirm')
		{
			if (x[i].value != x['txtpassword'].value)
				writeError(x[i], '*');
		}
	}
	
	if (!W3CDOM)
		alert(errorstring);
	if (firstError)
		firstError.focus();
	if (validForm)
		return true;
		
	return false; // I return false anyway to prevent actual form submission. Don't do this at home!
}
function validate(theForm, _ErrMsg ) {
	validForm = true;
	firstError = null;
	errorstring = '';
	var x = document.forms[theForm].elements;
	for (var i=0;i<x.length;i++) {
		if (!x[i].value)
		{
			var str="";
			str = "".concat(x[i].type);
			if (str.toString() != "undefined")
			{
				writeError(x[i], _ErrMsg);
				if (firstError ==null)
				firstError = x[i];
			}
		}
		if (x[i].name == 'txtEmail')
		{
			var strEmail = /^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$/;
				if(!strEmail.test(x['txtEmail'].value))
					writeError(x['txtEmail'],'**');
		}
		if (x[i].name == 'txtReNewPassword')
		{
			if (x[i].value != x['txtNewPassword'].value)
				writeError(x[i], '**');
		}
	}
	
	if (!W3CDOM)
		alert(errorstring);
	if (firstError)
		firstError.focus();
	if (validForm)
		return true;
		
	return false; // I return false anyway to prevent actual form submission. Don't do this at home!
}

function writeError(obj,message) {
	validForm = false;
	if (obj.hasError) return;
	if (W3CDOM) {
		obj.className += ' error';
		if (!obj.onchange) {
			obj.onchange = removeError;
		}
		var sp = document.createElement('span');
		sp.className = 'error';
		sp.appendChild(document.createTextNode(message));
		obj.parentNode.appendChild(sp);
		obj.hasError = sp;
	}
	else {
		errorstring += obj.name + ': ' + message + '\n';
		obj.hasError = true;
	}
	if (!firstError)
		firstError = obj;
}

function removeError() {
	this.className = this.className.substring(0,this.className.lastIndexOf(' '));
	this.parentNode.removeChild(this.hasError);
	this.hasError = null;
	this.onchange = null;
}
//===========================================================================
function formatCurrency(strValue)
{
	strValue = strValue.toString().replace(/\$|\,/g,'');
	dblValue = parseFloat(strValue);

	blnSign = (dblValue == (dblValue = Math.abs(dblValue)));
	dblValue = Math.floor(dblValue*100+0.50000000001);
	intCents = dblValue%100;
	strCents = intCents.toString();
	dblValue = Math.floor(dblValue/100).toString();
	if(intCents<10)
		strCents = "0" + strCents;
	for (var i = 0; i < Math.floor((dblValue.length-(1+i))/3); i++)
		dblValue = dblValue.substring(0,dblValue.length-(4*i+3))+','+
		dblValue.substring(dblValue.length-(4*i+3));
	return (((blnSign)?'':'-') + dblValue + '.' + strCents);
}
function brandselect(obj) {
	var index = obj.selectedIndex;
	if (obj.options[index].value != "0") {
		window.location = obj.options[index].value;
	}
}
function setFocusValue(obj, value) {
	if (obj.value == value) {
		obj.value = "";
	}
}
function setBlurValue(obj, value) {
	if (!obj.value) {
		obj.value = value;
	}
}
function getProvince(_obj, _cid, _selectedValue)
{
    var getstr = "?";
	var xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null)
	  {
	  alert ("Your browser does not support AJAX!");
	  return;
	  } 
	var obj = document.getElementById(_obj);
	if (obj==null) return;
	var url="Ajax/GetProvince.aspx";
	getstr += "&cid=" + _cid;
	getstr += "&sid="+Math.random();
	xmlHttp.onreadystatechange=function (){
		if (xmlHttp.readyState==4)
		{
			try {
				var xml = xmlHttp.responseXML;
				while (obj.length > 1){
					obj.remove(1);
				}
				//var root = xml.documentElement;
				var root = xml.getElementsByTagName("option")
				if (root.length > 0){
					for(var i=0;i<root.length;i++){
						var oOption = document.createElement("OPTION");
						oOption.value = root[i].getAttribute("id");
						oOption.text = root[i].getAttribute("name");
						if(_selectedValue==oOption.value){
							oOption.selected = true;
						}
						obj.options[i+1] = oOption;
					}
				}
			}catch(ex){alert(ex);}
		}
	}
    xmlHttp.open('POST', url, true);
    xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlHttp.setRequestHeader("Content-length", getstr.length);
    xmlHttp.setRequestHeader("Connection", "close");
    xmlHttp.send(getstr);
}
function changePage(_page) {
	window.location = _page;
}
function aff_login(obj, sout) {
  var getstr = "act=login&";
  var outObj = document.getElementById(sout);
  var inputList = obj.getElementsByTagName("input");
  for (i=0; i<inputList.length; i++) {
	 if (inputList[i].type == "text" || inputList[i].type == "password" || inputList[i].type == "hidden") {
		   getstr += inputList[i].name + "=" + encodeURI(inputList[i].value) + "&";
	 }   
  }
	var xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null) {
		  alert ("Your browser does not support AJAX!");
		  return;
	} 
    xmlHttp.onreadystatechange = function () {
	  if (xmlHttp.readyState == 4) {
		if (xmlHttp.responseText.indexOf("error") == -1) {
			//document.getElementById('myspan').innerHTML = "Sign in successfull.";
			window.location = xmlHttp.responseText;
		}
		else {
			document.getElementById('myspan').innerHTML = xmlHttp.responseText.substring(5);
			if (xmlHttp.responseText.substring(5) != '') 
				document.getElementById('myspan').style.display = 'block';
		}
	  }
	}
    xmlHttp.open('POST', "Ajax/Affiliate.aspx", true);
    xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlHttp.setRequestHeader("Content-length", getstr.length);
    xmlHttp.setRequestHeader("Connection", "close");
    xmlHttp.send(getstr);
}
function aff_update(obj, _act) {
  var getstr = "act=" + _act;
  var inputList = obj.getElementsByTagName("input");
  var selectList = obj.getElementsByTagName("select");
  var textList = obj.getElementsByTagName('textarea');
  for (i=0; i<inputList.length; i++) {
	 if (inputList[i].type == "text" || inputList[i].type == "password" || inputList[i].type == "hidden") {
		getstr +=  "&" + inputList[i].name + "=" + encodeURI(inputList[i].value);
	 }
	 if (inputList[i].type == "checkbox" && inputList[i].checked) {
		getstr +=  "&" + inputList[i].name + "=" + encodeURI(inputList[i].value);
	 }
  }	
  for (i=0; i<selectList.length; i++) {
	getstr +=  "&" + selectList[i].name + "=" + encodeURI(selectList[i].value);
  }	
  for (i=0; i<textList.length; i++){
	  getstr +=  "&" + textList[i].name + "=" + encodeURI(textList[i].value);
  }
	document.getElementById('myspan').className = "msg warning";
	document.getElementById('myspanex').className = "msg warning";
	document.getElementById("myspan").innerHTML="<img src='images/indicator.gif' alt='Processing...' />";
	document.getElementById("myspanex").innerHTML="<img src='images/indicator.gif' alt='Processing...' />";
	var xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null) {
		  alert ("Your browser does not support AJAX!");
		  return;
	} 
    xmlHttp.onreadystatechange = function () {
	  if (xmlHttp.readyState == 4) {
		if (xmlHttp.responseText.indexOf("error") != 0) {
			//document.getElementById('myspan').innerHTML = "<p>You have successful registered with us.</p><p>Please check your email and follow the instructions to complete your registration. Thank you! <a href='"+xmlHttp.responseText+"' title='Back'>Click here</a> to return </p>";
			//document.getElementById('myspanex').innerHTML = "<p>You have successful registered with us.</p><p>Please check your email and follow the instructions to complete your registration. Thank you! <a href='"+xmlHttp.responseText+"' title='Back'>Click here</a> to return </p>";
			//window.location = xmlHttp.responseText;
			document.getElementById('myspan').innerHTML = xmlHttp.responseText;
			document.getElementById('myspanex').innerHTML = xmlHttp.responseText;
			document.getElementById('myspan').className = 'msg success';
			document.getElementById('myspanex').className = 'msg success';
		}
		else {
			document.getElementById('myspan').innerHTML = xmlHttp.responseText.substring(5);
			document.getElementById('myspanex').innerHTML = xmlHttp.responseText.substring(5);
			if (xmlHttp.responseText.substring(5)=='') {
				document.getElementById('myspan').style.display = 'none';
				document.getElementById('myspanex').style.display = 'none';
			}
		}
	  }
	}
    xmlHttp.open('POST', 'Ajax/Affiliate.aspx', true);
    xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlHttp.setRequestHeader("Content-length", getstr.length);
    xmlHttp.setRequestHeader("Connection", "close");
    xmlHttp.send(getstr);
}
function aff_logout() {
  var getstr = "act=logout";
	var xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null) {
		  alert ("Your browser does not support AJAX!");
		  return;
	} 
    xmlHttp.onreadystatechange = function () {
	  if (xmlHttp.readyState == 4) {
		if (xmlHttp.responseText.indexOf("error") == -1) {
			//document.getElementById('myspan').innerHTML = "Sign in successfull.";
			window.location = xmlHttp.responseText;
		}
		else {
			document.getElementById('myspan').innerHTML = xmlHttp.responseText.substring(5);
			if (xmlHttp.responseText.substring(5) != '') 
				document.getElementById('myspan').style.display = 'block';
		}
	  }
	}
    xmlHttp.open('POST', "Ajax/Affiliate.aspx", true);
    xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlHttp.setRequestHeader("Content-length", getstr.length);
    xmlHttp.setRequestHeader("Connection", "close");
    xmlHttp.send(getstr);
}