function processCart(mode)
{
	document.frmcart.mode.value = mode;
	document.frmcart.submit();
}

function addtocart(mode,id)
{
	document.frmmerch.mode.value = mode;
	document.frmmerch.id.value = id;
	document.frmmerch.submit();
}


function hideTable(val)
{
	if(val==true)
	{
		document.getElementById('Ship_Address').style.display = "none";
	}
	else
	{
		document.getElementById('Ship_Address').style.display="";
	}
}

function fillInfo(control,basefield,selectedfield)
{
	control.options.length = 0;
	flag = 0;
	for(i=0,j=0; i<fillArr.length; i++)
	{
		if(fillArr[i][0] == basefield)
		{
			if(selectedfield == fillArr[i][1])
			{
				control.options[j] = new Option(fillArr[i][1]+" "+fillArr[i][2]);
				control.options[j].value = fillArr[i][1];
				control.options[j].selected = true;
				flag = 1;
				
			}
			else
			{
				control.options[j] = new Option(fillArr[i][1]+" "+fillArr[i][2]);
				control.options[j].value = fillArr[i][1];
			}				
			j++;
		}
	}
}
function fillInfo_new(control,basefield,selectedfield,flag)
{
	//alert(basefield);
	if(basefield=='US' || basefield=='CA')
	{
		//document.getElementById("bl_state_div").innerHTML='';
		//document.getElementById("bl_state_div").innerHTML='<select name="bl_state" id="bl_state" style=" width:250px;"><option value="">Select State</option></select>';
		if(flag=='bill')
		{
			document.getElementById("bl_state_div").style.display='block';
			document.getElementById("bl_state_text_div").style.display='none';
		}
		else
		{
			document.getElementById("sh_state_div").style.display='block';
			document.getElementById("sh_state_text_div").style.display='none';
		}
		
		control.options.length = 0;
		flag = 0;
		for(i=0,j=0; i<fillArr.length; i++)
		{
			if(fillArr[i][0] == basefield)
			{
				if(selectedfield == fillArr[i][1])
				{
					control.options[j] = new Option(fillArr[i][1]+" "+fillArr[i][2]);
					control.options[j].value = fillArr[i][1];
					control.options[j].selected = true;
					flag = 1;
					
				}
				else
				{
					control.options[j] = new Option(fillArr[i][1]+" "+fillArr[i][2]);
					control.options[j].value = fillArr[i][1];
				}				
				j++;
			}
		}
	}
	else
	{
		if(flag=='bill')
		{
			document.getElementById("bl_state_div").style.display='none';
			document.getElementById("bl_state_text_div").style.display='block';
			document.getElementById("bl_state_text").value='';
			
		}
		else
		{
			document.getElementById("sh_state_div").style.display='none';
			document.getElementById("sh_state_text_div").style.display='block';
			document.getElementById("sh_state_text").value='';
		}
	}
	
}
////////////////////////For NewsLetter Popup//////////////////////////////////////


function echeck(str) 
{
		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("Invalid E-mail Address")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid E-mail Address")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Invalid E-mail Address")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid E-mail Address")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid E-mail Address")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid E-mail Address")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Invalid E-mail Address")
		    return false
		 }

 		 return true					
	}

function AlreadyExist(str)
	{

			
  if (str=="")
  {
	  return;
  }
 
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
  returnval=false;
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
		 submitform(xmlhttp.responseText);
    }
  }
//alert(xmlhttp.onreadystatechange);

xmlhttp.open("GET","checkemail.php?email="+str,true);
xmlhttp.send();

			}
			
function Addtonewsletter()
	{
			str=document.getElementById("inputCustom1EMail").value;
			str2=document.getElementById("inputCustom1registername").value;
			str3=document.getElementById("inputCustom1city").value;
  if (str=="")
  {
	  return;
  }
  if (str2=="")
  {
 	 return;
  }
  if (str3=="")
  {
	  return;
  }
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
  returnval=false;
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
		 document.getElementById('successmsg').innerHTML=xmlhttp.responseText;
    }
  }
  //alert(xmlhttp.onreadystatechange);
  //alert("addtonewsltr.php?email="+str+"&registername="+str2+"&city="+str3);
xmlhttp.open("GET","addtonewsltr.php?email="+str+"&registername="+str2+"&city="+str3,true);
xmlhttp.send();
setTimeout('ModalPopupsCustom1Cancel()',3000);

			}
			
function submitform(chk)
{

 if(chk==1)
  {
  Addtonewsletter();
 // ModalPopups.Close("idCustom1");
  }
  else if (chk==0)
  {
    alert("You are already subscribed for the newsletter");
	ModalPopups.Close("idCustom1");
  }
}


function ModalPopupsCustom1() 
	{
		ModalPopups.Custom("idCustom1",
			"<center>Newsletter Signup</center>",
			"<div style='padding: 10px; height:100px; background-color:gray;'><div style='color:white; font-size:11px; font-weight:bold;' id='successmsg' ></div>" + 
			"<form action='<?php echo $SITE_URL;?>' method='post' name='newsletter' ><table style='background-color:gray;'>" + 
			"<tr><td>*Name : </td><td><input type=text id='inputCustom1registername' style='width:200px;' name='registername'></td></tr>" + 
			"<tr><td>*E-Mail : </td><td><input type=text id='inputCustom1EMail' style='width:200px;' name='email'><input type='hidden' name='newsltr' value='1'></td></tr>" + 
			"<tr><td>*City : </td><td><input type=text id='inputCustom1city' style='width:200px;' name='city'></td></tr>" + 
			"</table></form>" + 
			"</div>", 
				{
					//width: 500,
					//buttons: "ok,cancel,no",
					buttons: "ok,cancel",
					okButtonText: "Submit",
					//noButtonText: "X",
					cancelButtonText: "Close",
					onOk: "ModalPopupsCustom1Save()",
					onCancel: "ModalPopupsCustom1Cancel()"
					//onNo: "ModalPopupsCustom1Cancel()"
				}
			);
							
				ModalPopups.GetCustomControl("inputCustom1registername").focus(); 
		}
				
function ModalPopupsCustom1Save() 
{
	var RegisterName = ModalPopups.GetCustomControl("inputCustom1registername");
	var EMail = ModalPopups.GetCustomControl("inputCustom1EMail");
	var City = ModalPopups.GetCustomControl("inputCustom1city");
	
	if(RegisterName.value == "")
	{
		alert("Please Enter Name.");
		RegisterName.focus();
	}
	else if(EMail.value == "")
	{
		alert("Please Enter E-Mail Address.");
		EMail.focus();
	}
	else if(City.value == "")
	{
		alert("Please Enter Your City.");
		City.focus();
	}
	else
	{
		if(echeck(EMail.value))
		{
			AlreadyExist(EMail.value);
		}
	}
}

function ModalPopupsCustom1Cancel() 
{
	//alert('You pressed Cancel');
	ModalPopups.Cancel("idCustom1");
}
/////////////newsletter popup end////////////////////////
