function processCart(mode)
{
	document.frmcart.mode.value = mode;
	document.frmcart.submit();
}

function addtocart(mode,id,type)
{
//alert(type); return false;

	document.frmmerch.mode.value = mode;
	document.frmmerch.id.value = id;
	document.frmmerch.type.value = type;
	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++;
		}
	}
}




//popup for login-----------------------------------------------------------
function ModalPopupsCustom1() {
					ModalPopups.Custom("idCustom1",
						"LOGIN TO JOHNNY COOPER",
						"<form action='index.php?pg=login' name='login' method='post'>"+
						"<div style='padding: 0px 25px 5px 10px; background:#272D36; font-size:12px; color:#666666;'>" + 
						"<table>" + 
						"<tr><td><div style='width:105px; text-align:right; color:#ffffff;'>User Name :</div></td><td><input type=text id='username' style='width:300px; margin:5px 0 5px 10px; background:#000000; color:#ffffff; border:#5F697F   solid 1px; padding:5px 3px 5px 3px;' name='userName' onkeypress='submitonenter(event,\"ModalPopupsCustom1Save\")'></td></tr>" + 
						"<tr style='width:300px; text-align:right; color:#ffffff;'><td>Password :</td><td><input type=password id='passwrd' style='width:300px; margin:5px 0 5px 0; background:#000000; color:#ffffff; border:#5F697F   solid 1px; padding:5px 3px 5px 3px;' name='password' onkeypress='submitonenter(event,\"ModalPopupsCustom1Save\")'></td></tr>" + 
						
						"</table></form>" + 
						"</div>", 
						{
							width: 500,
							buttons: "ok,cancel",
							okButtonText: "LOGIN",
							cancelButtonText: "CANCEL",
							onOk: "ModalPopupsCustom1Save()",
							onCancel: "ModalPopupsCustom1Cancel()"
						}
					);
							
							
					//ModalPopups.GetCustomControl("inputCustom1Name").focus(); 
				}
				function submitonenter(even,submithandler)
				{
					 if(even.keyCode==13)
					 {
						
						  ModalPopupsCustom1Save()
					 }
				}
				function ModalPopupsCustom1Save() {
					var custom1Name = ModalPopups.GetCustomControl("username"); 
					var passwrdmy = ModalPopups.GetCustomControl("passwrd"); 
					
					var loginunamelu = custom1Name.value;
					var loginpasslu = passwrdmy.value;
					
					
					
					if(loginunamelu.replace(/^\s+|\s+$/g,"") == "")
					{
						alert("Please submit a username to this form");
						custom1Name.focus();
					}
					else if(loginpasslu.replace(/^\s+|\s+$/g,"") == "")
					{
						alert("Please submit a password to this form");
						passwrdmy.focus();
					}
					else
					{
						document.login.submit();
						
						ModalPopups.Close("idCustom1");
					}
				}
function ModalPopupsCustom1Cancel() {
					//alert('You pressed Cancel');
					ModalPopups.Cancel("idCustom1");
				}
//-----------------------------------------------------------------------------------------------


//---------------------popup for register=========================================================
				function ModalPopupsAlert1() {
					ModalPopups.Custom("iAlert1",
						"REGISTER WITH JOHNNY COOPER",
						"<form action='index.php?pg=register' name='register' method='post'>"+
						"<div style='margin:5px; text-align:right; background:#272D36; font-size:12px; color:#666666; padding:0px 5px 0px 5px;'>" + 
						"<table>" + 
						"<tr><td style='width:105px; color:#ffffff; !important'>First Name :</td><td><input type=text id='firstname' style='width:300px; background:#000000;  margin:5px 0 5px 0; color:#ffffff; border:#5F697F   solid 1px; padding:5px 3px 5px 3px;' name='firstname'><br class='clear'/></td></tr>"+
						"<tr><td style='width:105px; color:#ffffff; !important'>Last Name :</td><td><input type=text id='lastname' name='lastname' style='width:300px; color:#ffffff;  margin:5px 0 5px 0; background:#000000; border:#5F697F  solid 1px; padding:5px 3px 5px 3px;'><br class='clear'/></td></tr>"+
						"<tr><td style='width:105px; color:#ffffff; !important'><font color='#FF0000'>*</font> User Name :</td><td><input type=text id='username' style='width:300px; margin:5px 0 5px 10px; background:#000000; color:#ffffff; border:#5F697F   solid 1px; padding:5px 5px 5px 3px;' name='username'><br class='clear'/></td></tr>" + 
						"<tr><td style='width:105px; color:#ffffff; !important'><font color='#FF0000'>*</font> Email :</td><td><input type=text id='email'  name= 'email' style='width:300px; background:#000000;  margin:5px 0 5px 0; color:#ffffff; border:#5F697F   solid 1px; padding:5px 3px 5px 3px;'><br class='clear'/></td></tr>" + 						
						"<tr><td style='width:105px; color:#ffffff; !important'><font color='#FF0000'>*</font> Password :</td><td><input type=password name='password' id='password' style='width:300px; margin:5px 0 5px 0; color:#ffffff; background:#000000; border:#5F697F  solid 1px; padding:5px 3px 5px 3px;'><br class='clear'/></td></tr>"+
						"</table></form>" + 
						"</div>"
						, 
						{
							width: 500,
							buttons: "ok,cancel",
							okButtonText: "REGISTER",
							cancelButtonText: "CANCEL",
							onOk: "ModalPopupsCustom2Save()",
							onCancel: "ModalPopupsCustom2Cancel()"
						}
					);
							
					//ModalPopups.GetCustomControl("inputCustom1Name").focus(); 
				}
				
					function ModalPopupsCustom2Save() {
					var custom1Name = ModalPopups.GetCustomControl("username"); 
					var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
					
					var unamecustomerlu = custom1Name.value;
					var unameemaillu = ModalPopups.GetCustomControl("email").value;
					var unamepasswordlu = ModalPopups.GetCustomControl("password").value;
					
					if(unamecustomerlu.replace(/^\s+|\s+$/g,"") == "")
					{
						alert("Please submit a username to this form");
						custom1Name.focus();
					}
				
					else if(unameemaillu.replace(/^\s+|\s+$/g,"")==""){
						alert("Please submit a email to this form");
						ModalPopups.GetCustomControl("email").focus();
					}
					else if(unamepasswordlu.replace(/^\s+|\s+$/g,"")==""){
						alert("Please submit a password to this form");
						ModalPopups.GetCustomControl("password").focus();
					}					
					else
					{
						 var str='';
						if(echeck(ModalPopups.GetCustomControl("email").value))
						{
							str=AlreadyExist(ModalPopups.GetCustomControl("email").value,ModalPopups.GetCustomControl("username").value);
						}
						

					}
					
					
					
					
/*					else if(ModalPopups.GetCustomControl("email").value!=""){
						email = ModalPopups.GetCustomControl("email");					
						var varpat="/^[A-Za-z][A-Za-z0-9]+([_\.-][A-Za-z0-9]+)*@[A-Za-z0-9]+([_\.-][A-Za-z0-9]+)*\.([A-Za-z]){2,4}$/i";
						if(!varpat.test(email.value)){
								
								alert("Please submit a valid email to this form");
								email.focus();
						}
						else{
							document.register.submit();
							ModalPopups.Close("iAlert1");							
						}
					
					}	
*/					/*else
					{
						document.register.submit();
						ModalPopups.Close("iAlert1");
					}*/
				}
				
				function ModalPopupsCustom2Cancel() {
					//alert('You pressed Cancel');
					ModalPopups.Cancel("iAlert1");
				}
				function ModalPopupsConfirmNo() {
					//alert('You pressed No');
					ModalPopups.Cancel("idCustom2");
				}
//=--------------------------------------------------------------------------------------------------	

/*
Post comment form
*/
function ModalPopupsAlert2(blogid,replyid,ResultStr) {
					ModalPopups.Custom("iAlert2",
						"POST COMMENT",
						"<form action='index.php?pg=postcomment' name='post_comment' method='post'>"+
						"<input type='hidden' name='blogid' value='"+blogid+"'>"+
						"<input type='hidden' name='replyid' value='"+replyid+"'>"+
						"<div style='padding:10px; font-size:12px; color:#666666; padding:5px 3px 5px 3px; background-color:#272D36'>" + 
						"<table>" + 
						"<tr><td style='color:#ffffff;'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Comment&nbsp;&nbsp;</td><td><textarea id='Comment' name='Comment' style='width:300px; margin:5px 0 5px 0; background:#000000; color:#ffffff; border:#5F697F   solid 1px; padding:5px 3px 5px 3px;'></textarea></td></tr>" + 
						"<tr><td>" +
                "</td><td valign='middle'><input type='text' name='imageText' id='imageText' style='width:191px; margin:0px 0 0px 0; background:#000000; color:#ffffff; border:#5F697F   solid 1px; padding:5px 3px 5px 3px;'  />&nbsp;<img id='captchaImg' src='captcha.php?rqImg="+ResultStr+"'  align='absbottom' alt='' />" +
                "<input type='hidden' name='captext' id='captext' value='"+ResultStr+"'/>&nbsp;<img src='images/refresh.jpg' align='absbottom'  alt='CAPTCHA' border='0' style='cursor:pointer;' onclick='javascript: newImage(\"1\");'/>&nbsp;</td></tr>" + 
						"</table>" +
						"</div>"+
						"</form>", 
						{
							width: 500,
							buttons: "ok,cancel",
							okButtonText: "SUBMIT",
							cancelButtonText: "CANCEL",
							onOk: "ModalPopupsCustom3Save()",
							onCancel: "ModalPopupsCustom3Cancel()"
						}
					);
							
					//ModalPopups.GetCustomControl("inputCustom1Name").focus(); 
				}
					function ModalPopupsCustom3Save() {
					
					var captext = ModalPopups.GetCustomControl("captext").value; 
					var imageText = ModalPopups.GetCustomControl("imageText").value; 
					var Comment=ModalPopups.GetCustomControl("Comment").value;
					if(Comment.replace(/^\s+|\s+$/g,"")=="")
					{
						 alert("Please enter comment");
					}
					else if(captext!=imageText)
					{
						alert("Enter the Verification code exactly as shown in this image. (Case Sensitive)");
					}
				    
					else
					{
						//alert("Your name is: " + custom1Name.value);
						document.post_comment.submit();

					}
				}
				
				function ModalPopupsCustom3Cancel() {
					//alert('You pressed Cancel');
					ModalPopups.Cancel("iAlert2");
				}
function newImage(rqImg)
{
	//alert(textId);	
	if(rqImg==1)
	{
		rtext=randomString_blog();
		document.getElementById("captext").value=rtext;
		document.getElementById("captchaImg").src='captcha.php?rqImg='+rtext+'';
	}
	if(rqImg==2)
	{	
		rtext=randomString_blog();
		document.getElementById("rcaptext").value=rtext;
		document.getElementById("rcaptchaImg").src='captcha.php?rqImg='+rtext+'';
	}
}
function randomString_blog() {
	var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";
	var string_length = 5;
	var randomstring = '';
	for (var i=0; i<string_length; i++) {
		var rnum = Math.floor(Math.random() * chars.length);
		randomstring += chars.substring(rnum,rnum+1);
	}
	return randomstring;
}

function fillInfo_new(control,basefield,selectedfield,flag)
{
	if(basefield=='US' || basefield=='CA')
	{
		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='';
		}
	}
	
}
function submitform(chk)
{
 if(chk==0)
  {
	  Addtonewsletter();
  }
  else if (chk==1)
  {
    alert("You are already subscribed for the newsletter");
	ModalPopups.Close("iAlert3");
  }
}
function AlreadyExist(str,username)
{
	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)
    {
		 if(xmlhttp.responseText!='')
		 {
		alert(xmlhttp.responseText);
		 }
		 else
	     { 
		 document.register.submit();
							  ModalPopups.Close("iAlert1");
		// return '';
		 }
    }
  }
  //alert(xmlhttp.onreadystatechange);
xmlhttp.open("GET","register.php?action=check&email="+str+"&username="+username,true);
xmlhttp.send();

			}
			
////////////////////////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 ID")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Invalid E-mail ID")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid E-mail ID")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

 		 return true					
	}
function submitform(chk)
{
 if(chk==0)
  {
	  registersubmit();
  }
  else if (chk==1)
  {
    alert("You are already registered");
	ModalPopups.Close("iAlert3");
  }
}	
function registersubmit()
	{
			str=document.getElementById("email").value;
if (str=="")
  {
  //document.getElementById("divAlbum").innerHTML="";
  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)
    {
		 if(xmlhttp.responseText==1)
		 document.getElementById('succmessage').innerHTML="You have successfully registered.Now you can post the comments.";
		 if(xmlhttp.responseText==2)
		 document.getElementById('errorregMessage').innerHTML="You were not registered.Please try again.";
    }
  }
 data="&username="+document.getElementById('username').value+"&password="+document.getElementById('password').value+"&firstname="+document.getElementById('firstname').value+"&lastname="+document.getElementById('lastname').value+"&email="+document.getElementById('email').value+"&action=submit"; 
 //alert(data);
  //alert(xmlhttp.onreadystatechange);
xmlhttp.open("POST","register.php",true);
xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlhttp.setRequestHeader("Content-length", data.length);
xmlhttp.send(data);
//setTimeout("ModalPopups.Cancel('iAlert3');",2000);
}
