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++;
		}
	}
}
//popup for login-----------------------------------------------------------
function ModalPopupsCustom1() {
					ModalPopups.Custom("idCustom1",
						"Login to Eamomn McCrystal",
						"<form action='index.php?pg=login' name='login' method='post'>"+
						"<div style='padding: 0px 25px 5px 10px; background:#F5F5F5; font-size:12px; color:#666666;'>" + 
						"<table>" + 
						"<tr><td>User Name</td><td><input type=text id='username' style='width:300px; border:#cccccc  solid 1px; padding:5px 3px 5px 3px;' name='userName'></td></tr>" + 
						"<tr><td>Password</td><td><input type=password id='passwrd' style='width:300px; border:#cccccc  solid 1px; padding:5px 3px 5px 3px;' name='password'></td></tr>" + 
						"</table></form>" + 
						"</div>", 
						{
							width: 500,
							buttons: "ok,cancel",
							okButtonText: "LOGIN",
							cancelButtonText: "CANCEL",
							onOk: "ModalPopupsCustom1Save()",
							onCancel: "ModalPopupsCustom1Cancel()"
						}
					);
							
							
					//ModalPopups.GetCustomControl("inputCustom1Name").focus(); 
				}
				
				function ModalPopupsCustom1Save() {
					var custom1Name = ModalPopups.GetCustomControl("username"); 
					if(custom1Name.value == "")
					{
						alert("Please submit a name to this form");
						custom1Name.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 Eamomn McCrystal",
						"<form action='index.php?pg=register' name='register' method='post'>"+
						"<div style='margin:5px; text-align:left;  background:#F5F5F5; font-size:12px; color:#666666; padding:0px 3px 0px 3px;'>" + 
						"<table>" + 
						"<tr><td style='width:80px; !important'>User Name</td><td><input type=text id='username' style='width:300px; border:#cccccc  solid 1px; padding:5px 3px 5px 3px;' name='username'></td></tr>" + 
						"<tr><td style='width:80px; !important'>Password</td><td><input type=password name='password' id='password' style='width:300px; border:#cccccc  solid 1px; padding:5px 3px 5px 3px;'></td></tr>"+
						"<tr><td style='width:80px; !important'>First Name</td><td><input type=text id='firstname' style='width:300px; border:#cccccc  solid 1px; padding:5px 3px 5px 3px;' name='firstname'></td></tr>"+
						"<tr><td style='width:80px; !important'>Last Name</td><td><input type=text id='lastname' name='lastname' style='width:300px; border:#cccccc  solid 1px; padding:5px 3px 5px 3px;'></td></tr>"+
						"<tr><td style='width:80px; !important'>Email</td><td><input type=text id='email'  name= 'email' style='width:300px; border:#cccccc   solid 1px; padding:5px 3px 5px 3px;'></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"); 
					if(custom1Name.value == "")
					{
						alert("Please submit a name to this form");
						custom1Name.focus();
					}
					else if(ModalPopups.GetCustomControl("password").value==""){
						alert("Please submit a password to this form");
						ModalPopups.GetCustomControl("password").focus();
					}
					else if(ModalPopups.GetCustomControl("email").value==""){
						alert("Please submit a email to this form");
						ModalPopups.GetCustomControl("email").focus();
					}
/*					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");
				}
//=--------------------------------------------------------------------------------------------------				

	function ModalPopupsAlert3(blogid,replyid,ResultStr) {
					ModalPopups.Custom("iAlert3",
						"<center>Please enter your e-mail below to sign up for our newsletter.</center>",
						"<center><div id='successmsg'></div></center>"+
						"<div style='padding:10px; text-align:center; font-size:12px; color:#666666; padding:5px 3px 5px 3px;'>" + 
						"<table>" + 
						"<tr><td style='width:80px;  !important text-align:right;'> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Email</td><td ><input type=text id='Email' name='Email' style='width:300px; border:#cccccc  solid 1px; padding:5px 3px 5px 3px;'></td></tr>" + 
						"</table>" +
						"</div>", 
						{
							width: 500,
							buttons: "ok,cancel",
							okButtonText: "SUBMIT",
							cancelButtonText: "CANCEL",
							onOk: "ModalPopupsCustom4Save()",
							onCancel: "ModalPopupsCustom4Cancel()"
						}
					);
							
					//ModalPopups.GetCustomControl("inputCustom1Name").focus(); 
				}
					function ModalPopupsCustom4Save() {
					var custom1Name = ModalPopups.GetCustomControl("Email"); 
					var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
					
					if(custom1Name.value == "")
					{
						alert("Please submit a Email");
						//custom2Name.focus();
					}
					else
					{
						if(echeck(custom1Name.value))
						{
							AlreadyExist(custom1Name.value);
						}

					}
				}
				
				function ModalPopupsCustom4Cancel() {
					//alert('You pressed Cancel');
					ModalPopups.Cancel("iAlert3");
				}
				
/*
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:#f5f5f5'>" + 
						"<table>" + 
						"<tr><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Comment&nbsp;&nbsp;</td><td><textarea id='Comment' name='Comment' style='padding:10px; font-size:12px; color:#666666; padding:5px 3px 5px 3px; width:300px;'></textarea></td></tr>" + 
						"<tr><td>" +
                "</td><td><input type='text' name='imageText' id='imageText' style='padding:10px; font-size:12px; color:#666666; padding:5px 3px 5px 3px; width:191px;'  />&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=='')
					{
						 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;
}
////////////////////////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 AlreadyExist(str)
{
	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","signupnewsletter.php?action=check&email="+str,true);
xmlhttp.send();

			}
			
function Addtonewsletter()
	{
			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)
    {
		 document.getElementById('successmsg').innerHTML=xmlhttp.responseText;
    }
  }
  //alert(xmlhttp.onreadystatechange);
xmlhttp.open("GET","signupnewsletter.php?action=submit&email="+str,true);
xmlhttp.send();
setTimeout("ModalPopups.Cancel('iAlert3');",2000);
}
function submitform(chk)
{
 if(chk==0)
  {
	  Addtonewsletter();
  }
  else if (chk==1)
  {
    alert("You are already subscribed for the newsletter");
	ModalPopups.Close("iAlert3");
  }
}


var gAutoPrint = true; // Flag for whether or not to automatically call the print function
function printSpecial(){
	if(document.getElementById != null){
		var html = '<HTML>\n<HEAD>';
		if (document.getElementsByTagName != null){
			var headTags = document.getElementsByTagName("head");
			if (headTags.length > 0)
				html += headTags[0].innerHTML;
		}
		html += '\n</HE' + 'AD>\n<BODY style="background-color:#FFFFFF; color:#000000; font-size:11px;">\n';
		var printReadyElem = document.getElementById("printReady");
		if (printReadyElem != null){
			html += printReadyElem.innerHTML;
		}else{
			alert("Could not find the printReady section in the HTML");
			return;
		}
		html += '\n</BO' + 'DY>\n</HT' + 'ML>';
		var printWin = window.open("","printSpecial");
		printWin.document.open();
		printWin.document.write(html);
		printWin.document.close();
		if (gAutoPrint){
			printWin.print();
			printWin.close();
		}
	}else{
		alert("Sorry, the print ready feature is only available in modern browsers.");
	}
}
	
function fillInfo_new(control,basefield,selectedfield,flag)
{
	//alert(basefield);
	if(basefield=='US')
	{
		//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='';
		}
	}
	
}	

