//::pop-up window (complete settings)
//ex -> onClick="CiPopWin('./pageurl.asp','WindowName','500','300','no','no','no','no','no','no');return false"
var win = null;
function CiPopWin(mypage,myname,w,h,scroll,resize,toolbar,loc,status,menubar){
LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
settings = 'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',resizable='+resize+',toolbar='+toolbar+',location='+loc+',status='+status+',menubar='+menubar;
win = window.open(mypage,myname,settings)
if(win.window.focus){win.window.focus();}
}

//::Delivery PopUp Window
function DeliveryWindow(){
	CiPopWin('../html/disclaimer.html','DeliveryWindow','500','700','no','no','no','no','no','no');
}

//::Territory PopUp Window
function TerritoryWindow(){
	CiPopWin('../html/disclaimer2.html','TerritoryWindow','500','700','no','no','no','no','no','no');
}

//::Landice Warranty PopUp Window
function LandiceWarrantyWindow(){
	CiPopWin('http://landice.com/Pages/legacycertificate.html','LandiceWarrantyWindow','718','670','no','no','no','no','no','no');
}

//::Landice Frame PopUp Window
function LandiceFrameWindow(){
	CiPopWin('http://landice.com/Pages/frame.html','LandiceFrameWindow','660','630','yes','no','no','no','no','no');
}

//::Pricematch PopUp Window
function PricematchWindow(){
	CiPopWin('../html/pricematch.html','PricematchWindow','660','530','yes','no','no','no','no','no');
}

//::Financing Link
function FinancingLink(){
	alert('100% Interest Free' +
		  '\n============' +
		  '\n\nPlease contact us for more information at our toll free number: ' +
		  '\n\n1-800-797-6287\n\nor via e-mail at:\n\ncontact@dynamicfitness.com');
}

//::Limit Product Qty
function LimitProductQty(intQty){
	//intQty = document.getElementById('ProductDetail11_txtQty').value;
	if (intQty < 1 || intQty > 7) {
		alert('*** NOTICE ***\n\nDue to DEA restrictions, only 7 bottles may be sold per order.\n\nOrders placed over the legal limit will be automatically refunded.');
		document.getElementById('ProductDetail11_txtQty').focus();
		return false;
	}
	else {
		return true;
	}
}

//::Qty Limit Blur
function QtyLimitBlur(intProductID,intQty){
	switch (intProductID) {
		case 2:		//Vasopro
			if (intQty < 1 || intQty > 7) {
				alert('*** NOTICE ***\n\nDue to DEA restrictions, only 7 boxes may be sold per order.\n\nOrders placed over the legal limit will be automatically refunded.');
				document.getElementById('ProductDetail11_txtQty').focus();
				return false;
			}
			else {
				return true;
			}
			break;

		case 1340:	//Biotek Ephedrine HCL
			if (intQty < 1 || intQty > 12) {
				alert('*** NOTICE ***\n\nDue to DEA restrictions, only 12 boxes may be sold per order.\n\nOrders placed over the legal limit will be automatically refunded.');
				document.getElementById('ProductDetail11_txtQty').focus();
				return false;
			}
			else {
				return true;
			}
			break;

		case 1000:	//4'x6'x1/2" Black Rubber Mat
			if (intQty < 1 || intQty > 5) {
				alert('*** NOTICE ***\n\nFor orders over 5 mats, call for volume pricing and freight quote: 1-800-797-6287');
				document.getElementById('ProductDetail11_txtQty').focus();
				return false;
			}
			else {
				return true;
			}
			break;

		default:
			return true;
			break;
	}
}

//::Qty Limit KeyPress
function QtyLimitKeyPress(intProductID){
	switch (intProductID) {
		case 2:		//Vasopro
			AllowKeyChars('1234567');
			break;

		case 1340:	//Biotek Ephedrine HCL
			AllowKeyChars('1234567');
			break;

		case 1000:	//4'x6'x1/2" Black Rubber Mat
			AllowKeyChars('12345');
			break;
	}
}

//::Show Other Save Field
function ShowSaveField(strPg,strVal,intLoad){
	if (strPg == "Shipping") {
		strPreFix = "Ship";
	}
	else {
		strPreFix = "Bill";
	}
	
	if (intLoad == 1) {
		strLoadVal = document.getElementById(strPreFix+'_NickName').value;
		if (strLoadVal == "Home" || strLoadVal == "Work") {
			document.getElementById('chkSaveName').value = strLoadVal;
			strVal = strLoadVal;
		}
		else {
			document.getElementById('chkSaveName').value = "Other";
			strVal = "Other";
		}
		booClear = false;
	}
	else {
		booClear = true;
	}

	switch (strVal) {
		case "Other":
			document.getElementById(strPreFix+'_NickName').style.visibility = "visible";
			if (booClear) {
				document.getElementById(strPreFix+'_NickName').value = "";
			}
			break;
		default:
			document.getElementById(strPreFix+'_NickName').style.visibility = "hidden";
			document.getElementById(strPreFix+'_NickName').value = strVal;
			break;
	}
}

//::Allow Key Characters
//ex.	onKeypress="AllowKeyChars('123456789');"
function AllowKeyChars(strList){
	var strUnicode = event.charCode ? event.charCode : event.keyCode;
	var strKey = String.fromCharCode(strUnicode);
	arrList = strList.split("")
	for(var i=0; i<arrList.length; i++){
		if (strKey == arrList[i]) {
			event.returnValue = true;
			break;
		}
		else{
			event.returnValue = false;
		}
	}
}

//::Block Character
//ex.	onKeypress="BlockChar();"
function BlockChar(){
	if (event.keyCode==45) {
		event.returnValue = false;
	}
}

//::Invalid Characters
//ex.    InvalidCharacters('VALUE','\/:*?"<>|')
function InvalidCharacters(strValue,strChars){
	var invalidChar = "";
	arrItems = strValue.split("")
	for(var i=0; i<arrItems.length; i++){
		if ((strChars).indexOf(arrItems[i]) > -1) {
			invalidChar = arrItems[i];
			break;
		}
	}
	if (invalidChar != "" || strValue == "") {
		return true;
	}
	else{
		return false;
	}
}

//::Select All Function
//ex.	onClick="SelectAll(document.forms[0].FIELD);"
function SelectAll(fld){
	fld.focus();
	fld.select();
} 

//::QueryString Function
function QueryString(qstr){
	var tmp = self.document.location.search;
	if(tmp.indexOf(qstr) >= 0){
		tmp = tmp.substring((tmp.indexOf(qstr)+(qstr.length+1)),tmp.length);
		tmp = tmp.substring(0,(((tmp.indexOf('&')>=0)?tmp.indexOf('&'):tmp.length)));
	}
	else{tmp = '';}
	return unescape(tmp);
}

//::copy content to clipboard function
function CopyClipboard(str){
	clipboardData.setData("Text",str);
	//alert("Information has been successfully copied to your clipboard!\n\nYou may now paste the information where ever you'd like.");
}

//::Preview HTML
//ex.	onClick="PreviewHTML(document.forms[0].FIELD.value);"
function PreviewHTML(str){
	win = window.open("",'PreviewHTML','width=750,height=500,scrollbars=1,resizable=1,toolbar=1,location=0,status=1,menubar=0');
	win.document.close();
	win.document.write("" + str + "");
	win.window.focus();
}

//::Change Image Button Graphic
function ChangeButtonGraphic(val,btn) {
	if (IsNumeric(val)) {
		btn.src = "Images/BTN_GenerateHTML.gif";
	}
	else {
		btn.src = "Images/BTN_GenerateHTML_disabled.gif";
	}
}

//::Trim String Function
function Trim(str){
	str = str.replace(/\s+/,'');
	str = str.replace(/\s+$/,'');
	return str;
}

//::IsNumeric Function
function IsNumeric(val){
	for (i=0; i<val.length; i++){
		if (isNaN(val.charAt(i))){
			return false;
		}
	}
	return true;
}

//::Valid E-Mail
function ValidEmail(str){
	AccPos = str.indexOf('@');
	AccStr = str.substr(0,AccPos);
	AccLen = AccStr.length;
	DomPos = str.lastIndexOf('.');
	DomStr = str.substr(AccPos+1,(DomPos-AccPos)-1);
	DomLen = DomStr.length;
	ExtPos = DomPos + 1;
	ExtLen = str.length - ExtPos;
	ExtStr = str.substr(ExtPos,ExtLen);
	if(	   (AccPos != -1)
		&& (DomPos != -1)
		&& (AccLen >= 2)
		&& (DomLen >= 2)
		&& (ExtLen >= 2)
		&& (ExtLen <= 3)){
		return true;
	}
	else{return false}
}

//::Valid Phone
function ValidPhone(PhoneArea,PhonePre,PhoneSuf){
	if ((Trim(PhoneArea) == "") || 
		(Trim(PhonePre) == "") ||
		(Trim(PhoneSuf) == "") ||
		(PhoneArea.length != 3) || 
		(PhonePre.length != 3) ||
		(PhoneSuf.length != 4)){
		return false;
	}else{
		if (IsNumeric(PhoneArea) &&
			IsNumeric(PhonePre) &&
			IsNumeric(PhoneSuf) &&
			(PhoneArea.length == 3) && 
			(PhonePre.length == 3) &&
			(PhoneSuf.length == 4)){
			return true;
		}
	}
}

//::Valid Telephone
function ValidTelephone(str){
	str = Trim(str);
	str = str.replace("(","");
	str = str.replace(")","");
	str = str.replace(".","");
	str = str.replace(".","");
	str = str.replace("-","");
	str = str.replace("-","");
	str = str.replace(" ","");
	strLen = str.length;
	if((strLen == 10 || strLen == 7) && IsNumeric(str)){
		return true;
	}
	else{
		return false;
	}
}

//::Validate Login
function ValidateLogin() {
	missinginfo = "";
	var objForm = document.forms[0];

	if (!ValidEmail(objForm.TopNavigation1_tbEmail.value)) {
	missinginfo += "\n     -  E-Mail";
	}
	if (objForm.TopNavigation1_tbPassword.value == "") {
	missinginfo += "\n     -  Password";
	}

	if (missinginfo != "") {
	missinginfo = "The following information was entered incorrectly:\n" +
	missinginfo + "\n\nPlease re-enter the information and try again...";
	alert(missinginfo);
	return false;
	}
	else return true;
}

//::Validate Email List
function ValidateEmailList() {
	missinginfo = "";
	var objForm = document.forms[0];

	if (objForm.firstname.value == "") {
	missinginfo += "\n     -  First Name";
	}
	if (objForm.lastname.value == "") {
	missinginfo += "\n     -  Last Name";
	}
	if (!ValidEmail(objForm.emailaddress.value)) {
	missinginfo += "\n     -  E-Mail Address";
	}

	if (missinginfo != "") {
	missinginfo = "The following information was entered incorrectly:\n" +
	missinginfo + "\n\nPlease re-enter the information and try again...";
	alert(missinginfo);
	return false;
	}
	else {
		objForm.action = "HTML/EmailList.asp";
		return true;
	}
}
