var trDisplay = 'inline';
var tdDisplay = 'inline';
if (navigator.appName == 'Netscape')
{
	trDisplay = 'table-row';
	tdDisplay = 'table-cell';
}
function openWin(pagename){
		microsite_window=window.open(pagename,'microsite_window','toolbar=no,location=no,borders=no,directories=no,status=no,menubar=no,scrollbars=no,top=0,left=0,resizable=no,width=10,height=10')
}
	
function openWindow(mypage, myname, w, h, scroll) {
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	winprops = "height="+h+", width="+w+", top="+wint+", left="+winl+", scrollbars="+scroll+", resizable=no";
	window.open(mypage, "CurencyConverter", winprops);
}

//////////////////////////////////////     
var xmlHttp
function showpage(ctlName,page){
//	alert(ctlName+"\n"+page);
	var xmlHttp = GetXmlHttpObject();
	var url = page+"&sid="+Math.random();
	if (!xmlHttp){
		alert ("Browser does not support HTTP Request")
		return
	}
	xmlHttp.onreadystatechange=function(){
		if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){ 
			document.getElementById(ctlName).innerHTML=xmlHttp.responseText;
		}
	};
	xmlHttp.open("GET", url, true);
	xmlHttp.send(null);
}
function chkreffer(){
	var xmlHttp = GetXmlHttpObject();
	if (checkempty(document.all.urName,"Information - Enter Your Name")==false) return false;
	if (test(document.all.urEmail,"Information - Enter Your Valid Email")==false) return false;
	if (checkempty(document.all.frName,"Information - Enter Your Friends Name")==false) return false;
	if (test(document.all.frEmail,"Information - Enter Your Friends Email")==false) return false;
	var url = "sendrefer.php?urName="+document.all.urName.value+"&urEmail="+document.all.urEmail.value+"&frName="+document.all.frName.value+"&frEmail="+document.all.frEmail.value+"&IDZ="+document.all.IDZ.value+"&sid="+Math.random();
	
	if (!xmlHttp){
		alert ("Browser does not support HTTP Request")
		return
	}
	xmlHttp.onreadystatechange=function(){
		if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){ 
			document.getElementById("txtref").innerHTML=xmlHttp.responseText;
		}
	};
	xmlHttp.open("GET", url, true);
	xmlHttp.send(null);
}
function chkqInq(){
	var xmlHttp = GetXmlHttpObject();
	if (checkempty(document.all.txtFirstname,"Information - Enter Your Name")==false) return false;
	if (checkempty(document.all.cCompany,"Information - Enter Your Company Name")==false) return false;
	if (test(document.all.ctxtEmail,"Information - Enter Your Email")==false) return false;
	if (checkempty(document.all.country,"Information - Select Country")==false) return false;
	if (checkempty(document.all.txtMessage,"Information - Enter Your Message")==false) return false;
	var url = "sqry.php?txtFirstname="+document.all.txtFirstname.value+"&cCompany="+document.all.cCompany.value+"&txtPhone="+document.all.txtPhone.value+"&ctxtEmail="+document.all.ctxtEmail.value+"&country="+document.all.country.value+"&Address="+document.all.Address.value+"&txtMessage="+document.all.txtMessage.value+"&ItmID="+document.all.product_id.value+"&sid="+Math.random();
	
	if (!xmlHttp){
		alert ("Browser does not support HTTP Request")
		return
	}
	xmlHttp.onreadystatechange=function(){
		if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){ 
			document.getElementById("txtqry").innerHTML=xmlHttp.responseText;
		}
	};
	xmlHttp.open("GET", url, true);
	xmlHttp.send(null);
}
function GetXmlHttpObject(){ 
var objXMLHttp=null;

     if (window.XMLHttpRequest){
          objXMLHttp=new XMLHttpRequest();
     }else if (window.ActiveXObject){
          objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP");
     }
     return objXMLHttp;
}
//////////////////////////////////////
	
function confirmPassword(obj,obj1,msg){
	if(obj.value!=obj1.value){
		alert(msg);
		obj.focus();
		return false;
	}
}

function checkzero(obj,msg){
	if(obj.value==0){
		alert(msg);
		obj.focus();
		return false;
	}
}
function checkiblkordr(obj,msg){
	if(obj.value<0){
		alert(msg);
		obj.focus();
		return false;
	}
}

/////////////////////////////////////////////////////////
function chknlemail(){
	if (test(document.frmNewsletter.txtEmail,"Information - Enter Your Valid Email")==false) return false;
}
function chksrch(){
	if(document.frmsrch.key.value=='Enter Key Word(s)'){
		alert("Enter Search Keyword(s)");
		document.frmsrch.key.value='';
		document.frmsrch.key.focus();
		return false;
	}
	if (checkempty(document.frmsrch.key,"Information - Enter Search Keyword(s)")==false) return false;
}
function IsNumeric(strString){
   var strValidChars = "0123456789";
   var strChar;
   var blnResult = true;

   if (strString.length == 0) return false;

   //  test strString consists of valid characters listed above
   for (i = 0; i < strString.length && blnResult == true; i++){
	  strChar = strString.charAt(i);
	  if (strValidChars.indexOf(strChar) == -1){
		 blnResult = false;
		}
	}
	return blnResult;
}
function validate(f){
	if(f.textfield.value==""){
		alert("Please fill the card holder name");
		f.textfield.focus();
		return false;
	}else if(!IsNumeric(f.textfield2.value)){
		alert("Please fill Numeric");
		f.textfield2.focus();
		return false;
	}else if((f.textfield2.value).length!=16){
		alert("Please fill 16 Digits");
		f.textfield2.focus();
		return false;
	}else if(!IsNumeric(f.textfield3.value)){
		alert("Please fill Numeric");
		f.textfield3.focus();
		return false;
	}else if((f.textfield3.value).length!=3){
		alert("Please fill 3 Digits");
		f.textfield3.focus();
		return false;
	}else if(!IsNumeric(f.textfield4.value)){
		alert("Please fill Numeric");
		f.textfield4.focus();
		return false;
	}
	return true;
}
function chkInq(){
	if (checkempty(document.frmSend.txtFirstname,"Information - Enter Your Name")==false) return false;
	if (checkempty(document.frmSend.cCompany,"Information - Enter Your Company Name")==false) return false;
	if (test(document.frmSend.ctxtEmail,"Information - Enter Your Email")==false) return false;
	if (checkempty(document.frmSend.country,"Information - Select Your Country")==false) return false;
	if (checkempty(document.frmSend.txtMessage,"Information - Enter Your Message")==false) return false;
	return true;
}
function chkLogin(){
	if (test(document.frmLogin.user,"Information - Enter Your Username")==false) return false;
	if (checkempty(document.frmLogin.pass,"Information - Enter Your Password")==false) return false;
	return true;
}
function chkLogin2(){
	if (test(document.frmLogin2.user,"Information - Enter Your Username")==false) return false;
	if (checkempty(document.frmLogin2.pass,"Information - Enter Your Password")==false) return false;
	return true;
}
function CheckRegUser(){
	if (test(document.frmOrder.Email,"Account Registration :.. Enter User's Email..:")==false) return false;
	if (checkempty(document.frmOrder.password,"Account Registration :.. Enter User's Password..:")==false) return false;
	if (confirmPassword(document.frmOrder.password,document.frmOrder.repassword,"Account Registration :.. Password & Confirm Password Fields must be same..:")==false) return false;
	if (checkempty(document.frmOrder.FName,"Account Registration :.. Enter User Full Name..:")==false) return false;
	if (checkempty(document.frmOrder.cAddress,"Account Registration :.. Enter Address..:")==false) return false;
	if (checkempty(document.frmOrder.country,"Account Registration :.. Select Country..:")==false) return false;
	if (checkempty(document.frmOrder.cdayph,"Account Registration :.. Enter Phone Number..:")==false) return false;
	if (checkempty(document.frmOrder.uGrp,"Account Registration :.. Select Account Type..:")==false) return false;
	return true;
}
function CheckeRegUser(){
	if (checkempty(document.frmOrder.password,"Account Information :.. Enter User's Password..:")==false) return false;
	if (confirmPassword(document.frmOrder.password,document.frmOrder.repassword,"Account Information :.. Password & Confirm Password Fields must be same..:")==false) return false;
	if (checkempty(document.frmOrder.FName,"Account Information :.. Enter User Full Name..:")==false) return false;
	if (checkempty(document.frmOrder.cAddress,"Account Information :.. Enter Address..:")==false) return false;
	if (checkempty(document.frmOrder.country,"Account Information :.. Select Country..:")==false) return false;
	if (checkempty(document.frmOrder.cdayph,"Account Registration :.. Enter Phone Number..:")==false) return false;
	return true;
}
function chkforget(){
	if (test(document.frmLogin2.user,"Login - Enter Email As User Name.")==false) return false;		
	return true;
}
function chkfcnReq(){
	if (checkempty(document.frmacReq.Maker1,"Information - Select Make of Phone")==false) return false;
	if (checkempty(document.frmacReq.MdlNo1,"Information - Enter Model Number")==false) return false;
	if (checkempty(document.frmacReq.Imei1,"Information - Enter Imei")==false) return false;
	if (checkint(document.frmacReq.Imei1,"Information - Enter Imei in Numbers")==false) return false;
	if (checkImei(document.frmacReq.Imei1,"Information - Enter 15 digit Imei")==false) return false;
	if (checkempty(document.frmacReq.Network1,"Information - Select Network")==false) return false;
	if (checkempty(document.frmacReq.Country1,"Information - Select Country")==false) return false;
	return true;
}
function chktrack(){
	if (checkempty(document.frmtrack.Imei,"Information - Enter Imei")==false) return false;
	if (checkint(document.frmtrack.Imei,"Information - Enter Imei in Numbers")==false) return false;
	if (checkImei(document.frmtrack.Imei,"Information - Enter 15 digit Imei")==false) return false;
	return true;
}
function setShipTo()
{
	if (document.getElementById('chkShipToSame').checked)
	{
		document.getElementById('txtFNameS').value = document.getElementById('txtFNameB').value;
		document.getElementById('txtLNameS').value = document.getElementById('txtLNameB').value;
		document.getElementById('txtAddress1S').value = document.getElementById('txtAddress1B').value;
		document.getElementById('txtAddress2S').value = document.getElementById('txtAddress2B').value;
		document.getElementById('txtCityS').value = document.getElementById('txtCityB').value;		
		document.getElementById('txtZipS').value = document.getElementById('txtZipB').value;
		document.getElementById('txtPhoneS').value = document.getElementById('txtPhoneB').value;
		document.getElementById('countryS').value = document.getElementById('countryB').value;
	}
}
function showHideLoginFields(cldFrm)
{
	switch(cldFrm)
	{
		case 1:
			showHide('trRePass', 'none');
			break;
		case 2:
			showHide('trRePass', trDisplay);
			break;
	}
}
function showHide(objId, val)
{
	if(document.getElementById(objId))
		document.getElementById(objId).style.display = val;
}
function validateLogin()
{
	if (!validateControl(document.getElementById('txtUserName'), 'Email', 'text'))
		return false;
	if (!validateControl(document.getElementById('txtPassword'), 'Password', 'text'))
		return false;
	if(document.getElementById('rdUserType1').checked)
	{
		if (!validateControl(document.getElementById('txtRePassword'), 'Re-Password', 'text'))
			return false;
		if (Trim(document.getElementById('txtPassword').value) != Trim(document.getElementById('txtRePassword').value))
		{
			alert('Passwords do not match!');
			return false;
		}
	}
	return true;
}
function LTrim(String)
{
	var i = 0;
	var j = String.length - 1;

	if (String == null)
		return (false);

	for (i = 0; i < String.length; i++)
	{
		if (String.substr(i, 1) != ' ' &&
		    String.substr(i, 1) != '\t')
			break;
	}

	if (i <= j)
		return (String.substr(i, (j+1)-i));
	else
		return ('');
}

function RTrim(String)
{
	var i = 0;
	var j = String.length - 1;

	if (String == null)
		return (false);

	for(j = String.length - 1; j >= 0; j--)
	{
		if (String.substr(j, 1) != ' ' &&
			String.substr(j, 1) != '\t')
		break;
	}

	if (i <= j)
		return (String.substr(i, (j+1)-i));
	else
		return ('');
}

function Trim(String)
{
	if (String == null)
		return (false);

	return RTrim(LTrim(String));
}

function validateControl(cntrl, cntrlName, cntrlType)
{
	if(cntrl)
	{
		cntrlValue = Trim(cntrl.value);
		switch(cntrlType)
		{
			case "text":
				if (cntrlValue.length < 1)
				{
					alert(cntrlName + " is required.");
					cntrl.focus();
					return false;
				}
				break;
			case "dd":
				if (cntrlValue <= 0)
				{
					alert(cntrlName + " is required.");
					cntrl.focus();
					return false;
				}
				break;
			case 'list':
				if(cntrl.selectedIndex == -1)
					var listId = -1;
				else
					var listId = parseInt(cntrl.options[cntrl.selectedIndex].value);
				if (listId == -1)
				{
					alert("Please Select "+cntrlName+".");
					return false;
				}
				break;
		}
	}
	return true;
}

function test(obj,msg) 
{
	var regex = /^[a-zA-Z0-9._-]+@([a-zA-Z0-9.-]+\.)+[a-zA-Z0-9.-]{2,4}$/;
	if (regex.test(obj.value))
	{
		return true;
	}
	else
	{
	alert(msg);
	obj.focus();
	return false;
	}
}

function checkempty(obj,msg)
{
	if(obj.value=="")
	{
		alert(msg);
		obj.focus();
		return false;
	}
}
function checkint(obj,msg)
{
	if(isNaN(obj.value))
	{
		alert(msg);
		obj.focus();
		return false;
	}
}
function checkImei(obj,msg)
{
	if(obj.value.length<15)
	{
		alert(msg);
		obj.focus();
		return false;
	}
}

function validateOrder()
{
	if (checkempty(document.frmOrder.txtFNameB,"Information - Enter 'Billing' First Name")==false) return false;		
	if (checkempty(document.frmOrder.txtLNameB,"Information - Enter 'Billing' Last Name")==false) return false;
	if (checkempty(document.frmOrder.txtPhoneB,"Information - Enter 'Billing' Phone Number")==false) return false;
	if (checkempty(document.frmOrder.txtAddress1B,"Information - Enter 'Billing' Address")==false) return false;
	if (checkempty(document.frmOrder.txtCityB,"Information - Enter 'Billing' City")==false) return false;
	if (checkempty(document.frmOrder.txtZipB,"Information - Enter 'Billing' Zip Code")==false) return false;
	if (checkempty(document.frmOrder.countryB,"Information - Select 'Billing' Country")==false) return false;
	
	if (checkempty(document.frmOrder.txtFNameS,"Information - Enter 'Shipping' First Name")==false) return false;		
	if (checkempty(document.frmOrder.txtLNameS,"Information - Enter 'Shipping' Last Name")==false) return false;
	if (checkempty(document.frmOrder.txtPhoneS,"Information - Enter 'Shipping' Phone Number")==false) return false;
	if (checkempty(document.frmOrder.txtAddress1S,"Information - Enter 'Shipping' Address")==false) return false;
	if (checkempty(document.frmOrder.txtCityS,"Information - Enter 'Shipping' City")==false) return false;
	if (checkempty(document.frmOrder.txtZipS,"Information - Enter 'Shipping' Zip Code")==false) return false;
	if (checkempty(document.frmOrder.countryS,"Information - Select 'Shipping' Country")==false) return false;
	return true;
}
function showPayment(element) {
    element.style.display="block";      
}

function hidePayment(element) {
    element.style.display="none";
}
