function checkEmail()
	{
	var strEmail, strError, countAtRate, countDot, i;
	var checkAtRate, checkDot;
	var ValidChars,CountValidChars;
	ValidChars="abcdefghijklmnopqrstuvwxyz0123456789_.@ABCDEFGHIJKLMNOPQRSTUVWXYZ-";
	strEmail = checkEmail.arguments[0];
	countAtRate=0;
	countDot=0;
	CountValidChars=0;
	if (strEmail.length >= 7)
		{
		for(i=0;i<strEmail.length;i++)
			{
			if(strEmail.charAt(i)=="@")
				countAtRate++;
			if(strEmail.charAt(i)==".")
				countDot++;
			CountValidChars=0;
			for(j=0;j<ValidChars.length;j++)
				{
				if(strEmail.charAt(i)==ValidChars.charAt(j))
					{
					CountValidChars++;
					}
				}
			if(CountValidChars==0)
				{
				strError=0;
				break;
				}
			}
		}
	checkAtRate=strEmail.indexOf("@",1);
	checkDot=strEmail.indexOf(".",1);
	for(i=1;i<countDot;i++)
		checkDot=strEmail.indexOf(".",checkDot+1);
	if(countAtRate==1 && countDot > 0 && strEmail.length >=7 && strError != 0)
		strError=1;
	else
		strError=0;
	if(checkDot>=strEmail.length-2)
		strError=0;
	if(strEmail.charAt(0)=="@" || strEmail.charAt(strEmail.length-1)=="@")
		strError=0;
	if(strEmail.charAt(0)=="." || strEmail.charAt(strEmail.length-1)==".")
		strError=0;
	if(checkDot < checkAtRate)
		strError=0;

	return strError;
}

/*------------------------------------------------------------------------*/

function chkSpace(txtfield)
{
	var i,j;
	j=0;
	txtfield=eval(txtfield)
	var txtval=txtfield.value;
	for(i=0;i<txtval.length;i++)
	{
		j++
		if(txtval.substr(i,1)!=" ")
			break;
	}
	txtval=txtval.substr(j-1,txtval.length);
	if(txtval==" ")
	   txtval="";

	txtfield.value=txtval;
	return(txtval);

}

/*------------------------------------------------------------------------*/

function checkInt(txtfield)
{
	txtfield=eval(txtfield)
	txtval=txtfield.value;
	var newVal=parseInt(txtval);
	if (isNaN(newVal))
		txtfield.value=0;
	else if (newVal<0)
		txtfield.value=0;
	else
		txtfield.value=newVal;
}

/*------------------------------------------------------------------------*/

function checkCur(ObjName)
{
	ObjectName=eval("document.frm."+ObjName);
	ObjVal = '' + ObjectName.value;
	if(ObjVal=="") ObjVal="0";
		for(i=0;i<ObjVal.length;i++)
		    ObjVal=ObjVal.replace(",","");
		for(i=0;i<ObjVal.length;i++)
		    ObjVal=ObjVal.replace("-","");

	if(isNaN(ObjVal)==true)
   	{
		ObjectName.value="0.00"
   	}
	else
	{
		var NegSign="";
      	if(ObjVal.substr(0,1)=="-") {NegSign="-";}
   		ObjVal=parseFloat(ObjVal);
   		PInt=parseInt(ObjVal);
   		PtValue=".00";
   		PInt=Math.abs(PInt);
   		ObjVal=Math.abs(ObjVal);
   		PInt='' + PInt;
   		ObjVal=''+ ObjVal;
   		if(PInt.length!=ObjVal.length)
   		{
			PtValue='' + ObjVal.substr(ObjVal.indexOf("."),ObjVal.length);
		}
		if (PInt.length > 3)
   	    {
			var mod = PInt.length % 3;
       		var output = (mod > 0 ? (PInt.substring(0,mod)) : '');
       		for (i=0 ; i < Math.floor(PInt.length / 3); i++)
       		{
				if ((mod == 0) && (i == 0))
					output += PInt.substring(mod+ 3 * i, mod + 3 * i + 3);
				else
					output+= '' + PInt.substring(mod + 3 * i, mod + 3 * i + 3);
	   		}
       		ObjectName.value=NegSign+output+PtValue;
		}
		else ObjectName.value=NegSign+PInt+PtValue;
 	}
}

/*------------------------------------------------------------------------*/

function compose()
{
	var1="mailer.asp?em="+compose.arguments[0];
	window.open(var1,"Mailer","directories=no,scrollbars=yes,status=no,resizable=no,height=410,width=750,top=1,left=1");

}

/*------------------------------------------------------------------------*/

function changeST()
{
	if(document.frm.country.options[document.frm.country.selectedIndex].value!="USA")
	{
		if(document.frm.country.options[document.frm.country.selectedIndex].value!="CANADA")
		document.frm.state.selectedIndex=0;
	}

}

function changeST1()
{
	if(document.frm.country.options[document.frm.country.selectedIndex].value!="US")
		document.frm.state.selectedIndex=0;
}

function changeST2()
{
	if(document.frm.s_country.options[document.frm.s_country.selectedIndex].value!="US")
		document.frm.s_state.selectedIndex=0;
}



/*------------------------------------------------------------------------*/

function checkPhone(e)
{

	var whichCode = (window.Event) ? e.which : e.keyCode;
	if(whichCode<48 || whichCode>57)
	window.event.returnValue=false;
}

/*------------------------------------------------------------------------*/

function addEmp()
{
	var var1=addEmp.arguments[0];
	window.open(var1,"AddEmp","directories=no,scrollbars=yes,status=yes,resizable=no,height=410,width=730,top=1,left=1");
}

/*------------------------------------------------------------------------*/

function mPlan()
{
	var var1=mPlan.arguments[0];
	window.open(var1,"MPlan","directories=no,scrollbars=yes,status=yes,resizable=no,height=220,width=730,top=1,left=1");
}

/*------------------------------------------------------------------------*/

function cnClose()
{
		window.close();
}
/*----------------------------*/
function Addcat()
{
	var var1=Addcat.arguments[0];
	window.open(var1,"Addcat","directories=no,scrollbars=yes,status=yes,resizable=no,height=125,width=400");

}
/*----------------------------*/
function Addresource()
{
	var var1=Addresource.arguments[0];
	window.open(var1,"Addresource","directories=no,scrollbars=yes,status=yes,resizable=no,height=500,width=600");

}
/*----------------------------*/
function subcat()
{
document.frm.method="Post";
document.frm.action="AddNewCategory.asp";
document.frm.submit();
}

/*----------------------------*/

function getChkStatus(chkField)
{
	var dt=0;
	for(i=0;i<chkField.length;i++)
	{
		if(chkField[i].checked)
		dt++;
	}

	if(dt==0)
		return 0;
	else
		return 1;

}

/*----------------------------*/

function changeSt()
{
	if(document.frm.country.options[document.frm.country.selectedIndex].value!="USA")
	{
		if(document.frm.country.options[document.frm.country.selectedIndex].value!="CANADA")
			document.frm.state.selectedIndex=1;
	}
}
/*----------------------------*/
function changeST1()
{
	if(document.frm.country.options[document.frm.country.selectedIndex].value!="US")
		document.frm.state.selectedIndex=0;
}
/*----------------------------*/

function ReferSite()
{
	var errMsg="";
	ObjForm=document.frm;
	if(chkSpace(ObjForm.YName)=="")
		errMsg="- Your Name";
	if(checkEmail(ObjForm.YEmail.value)==0)
		errMsg+="\n- Your Email Address";
	if(chkSpace(ObjForm.FName)=="")
		errMsg+="\n- Your Friend's Name";
	if(checkEmail(ObjForm.FEmail.value)==0)
		errMsg+="\n- Your Friend's Email Address";
	if(errMsg=="")
	{
		ObjForm.method="post";
		ObjForm.action="friend.asp?FuncMod=ReferSite";
		ObjForm.submit();
	}
	else
	{
		alert("Following Fields are incomplete:\n___________________________\n"+errMsg)
		errMsg="";
	}

}

/*----------------------------*/

var prevWnd=null;
function ImagePreview(fieldval)
{
	if(prevWnd!=null)
		prevWnd.close;

    prevWnd=window.open("","prvw","width=500,height=400,scrollbars=yes,resizable=yes,status=0,top=0,left=0");

    prevWnd.document.open();
	{
	    prevWnd.document.writeln('<html><title>Large Image Preview</title><body>');
	    prevWnd.document.writeln('<center><img src='+fieldval+'></center><br><center><a href=javascript:window.close()><font size=2 face=verdana>Close Preview</font></a></center>');
	}
	prevWnd.focus();
}

/*----------------------------*/

function ViewHelp()
{
		window.open("Help.htm","Help","width=480,height=600,scrollbars=yes,resizable=no,status=0,top=0,left=0");
}

/*----------------------------*/

function ViewShapeLibrary()
{
		window.open("ShapeLibrary.htm","ShapeLibrary","width=680,height=600,scrollbars=yes,resizable=no,status=0,top=0,left=0");
}

/*----------------------------*/

function ViewAccessoryInfo()
{
		window.open("AccessoryDetail.aspx?AccessID="+arguments[0],"AccessoryDetail","width=550,height=350,scrollbars=yes,resizable=no,status=0,top=0,left=0");
}

/*----------------------------*/

function ViewAttachmentUpgradeInfo()
{
		window.open("AttachmentUpgradeDetail.aspx?UpgradeID="+arguments[0],"AttachmentUpgradeDetail","width=550,height=350,scrollbars=yes,resizable=no,status=0,top=0,left=0");
}

/*----------------------------*/

function ViewShippingHelp()
{
		window.open("ShipPolicy.htm","ShipPolicy","width=550,height=375,scrollbars=yes,resizable=no,status=0,top=0,left=0");
}

/*----------------------------*/

function ViewCVVHelp()
{
		window.open("CVV.htm","CVV","width=750,height=275,scrollbars=yes,resizable=no,status=0,top=0,left=0");
}


function CheckMinQty(txtfield,MinOrderValue)
{
	txtfield=eval(txtfield)
	txtval=txtfield.value;
	var newVal=parseInt(txtval);
	if (isNaN(newVal))
		txtfield.value=MinOrderValue;
	else if (newVal<0)
		txtfield.value=MinOrderValue;
	else
	{
		if(newVal<MinOrderValue)
		{
			alert("You cannot order less than "+MinOrderValue);
			newVal=MinOrderValue;
			txtfield.focus();
		}
		txtfield.value=newVal;
	}
}

function RemoveCartItem()
{
	if(confirm("Item is about to be deleted. Are you sure?"))
		window.location.href="?Action=RemoveItem&ItemSessionID="+arguments[0];
}

/*----------------------------*/

function ValidateProductPage()
{
	var ErrMsg="";
	ObjForm=document.FrmProduct;
	if(ObjForm.CmbPinType.selectedIndex==0)
		ErrMsg+="Choose your Pin Size\n";
	if(document.getElementById("CmbShape"))
	{
		if(ObjForm.CmbShape.selectedIndex==0)
			ErrMsg+="Choose your Pin Shape\n";
	}
	if(ObjForm.CmbFinish.selectedIndex==0)
		ErrMsg+="Choose your Pin Finish\n";
	if(document.getElementById("CmbAttachmentList"))
	{
		if(ObjForm.CmbAttachmentList.length>1)
		{
			if(ObjForm.CmbAttachmentList.selectedIndex==0)
				ErrMsg+="Choose your Pin Attachment\n";
		}
	}
	if(document.getElementById("RdoAttachmentList"))
	{
		if(ObjForm.RdoAttachmentList.length>1)
		{
			if(ObjForm.RdoAttachmentList.selectedIndex==0)
				ErrMsg+="Choose your Pin Attachment\n";
		}
	}	
	if(document.getElementById("CmbAccessoryList"))
	{
		if(ObjForm.CmbAttachmentUpgrade.selectedIndex>0 && ObjForm.CmbAccessoryList.selectedIndex>0)
			ErrMsg+="Both Attachment Upgrade and Accessory cannot be selected,\n";
	}

	if(ErrMsg=="")
		return true;
	else
	{
		alert(ErrMsg);
		return false;
	}




}

/*----------------------------*/

function checkUpsellQty(txtfield,MinOrderQty)
{
	txtfield=eval(txtfield)
	txtval=txtfield.value;
	if(txtval!="")
	{
		var newVal=parseInt(txtval);
		if (isNaN(newVal))
			txtfield.value=0;
		else if (newVal<0)
			txtfield.value=0;
		else
			txtfield.value=newVal;
	}
	if(txtfield.value=="0")
		txtfield.value="";
	if(parseInt(txtfield.value)<MinOrderQty)
		txtfield.value=MinOrderQty;
}

function CheckNoQty()
{
	var checkData="";
	if(document.getElementById("TxtQty1"))
		checkData+=""+document.getElementById("TxtQty1").value;
	if(document.getElementById("TxtQty2"))
		checkData+=""+document.getElementById("TxtQty2").value;
	if(checkData=="")
	{
		alert("Please enter the quantity of your order")
		return false;
	}
}

function ValidateProductSummarPage()
{
	var ErrMsg="";
	ObjForm=document.FrmProduct;
	if(document.getElementById("CmbAttachmentList"))
	{
		if(ObjForm.CmbAttachmentList.length>1)
		{
			if(ObjForm.CmbAttachmentList.selectedIndex==0)
				ErrMsg+="Choose your Pin Attachment\n";
		}
	}
	if(document.getElementById("CmbAccessoryList"))
	{
		if(ObjForm.CmbAttachmentUpgrade.selectedIndex>0 && ObjForm.CmbAccessoryList.selectedIndex>0)
			ErrMsg+="Both Attachment Upgrade and Accessory cannot be selected,\n";
	}

	if(ErrMsg=="")
		return true;
	else
	{
		alert(ErrMsg);
		return false;
	}
}