/*
PROJECT: mysticseaport.org
SCRIPT NAME: mysticseaport.js
PURPOSE: site-wide javascript for CMS application
PROGRAMMER: G Szabo (gszabo@globalcloud.net)
CREATION DATE: 5/4/2004
VERSION HISTORY:
*/

function fcnCheckoutButton() {
	location.href="/index.cfm?fuseaction=rosenfeld.checkout";
}

function fcnURLConfirmDeletion(URL) {
	var confirmDelete = confirm("Click OK to confirm delete.");
	if(confirmDelete) {
		location.href = URL
	}
}	

//used on frm_checkout.cfm
function fcnValidateLogin() {
	var aParams = new Array();

	if(document.getElementById("vchEmail").value == "") {
		alert("Please enter your username.  This is the email address that you used to register with our site.");
		document.getElementById("vchEmail").focus();
		return false;
	}

	if(document.getElementById("vchPassword").value == "") {
		alert("Please enter your password.");
		document.getElementById("vchPassword").focus();	
		return false;
	}
	
	aParams[0] = document.getElementById("vchEmail").value;
	aParams[1] = document.getElementById("vchPassword").value;
	
	fcnJSRSValidateLogin(aParams);
}	  

//used on frm_checkout.cfm
function frmVerifyUpdateRegistration() {
	var msg = "", focusFld = "";
	
	if (document.getElementById("vchFName").value == ""){
		msg += "\nPlease enter your First Name";
		if (focusFld == "")
			focusFld = "vchFName";
	}
	if (document.getElementById("vchLName").value == ""){
		msg += "\nPlease enter your Last Name";
		if (focusFld == "")
			focusFld = "vchLName";
	}
	if(document.getElementById("vchEmail").value == "") {
		msg += "\nPlease enter your Email address";
		if (focusFld == "")
			focusFld = "vchEmail";
	}
	if(document.getElementById("vchBillAddress1").value == "") {
		msg += "\nPlease enter your Billing Street Address 1";
		if (focusFld == "")
			focusFld = "vchBillAddress1";
	}
	if(document.getElementById("vchBillCity").value == "") {
		msg += "\nPlease enter your Billing City";
		if (focusFld == "")
			focusFld = "vchBillCity";
	}	
	if(document.getElementById("vchBillZip").value == "") {
		msg += "\nPlease enter your Billing Zip/Postal Code";
		if (focusFld == "")
			focusFld = "vchBillZip";
	}	
	if(document.getElementById("vchShipAddress1").value == "") {
		msg += "\nPlease enter your Shipping Street Address 1";
		if (focusFld == "")
			focusFld = "vchShipAddress1";
	}
	if(document.getElementById("vchShipCity").value == "") {
		msg += "\nPlease enter your Shipping City";
		if (focusFld == "")
			focusFld = "vchShipCity";
	}	
	if(document.getElementById("vchShipZip").value == "") {
		msg += "\nPlease enter your Shipping Zip/Postal Code";
		if (focusFld == "")
			focusFld = "vchShipZip";
	}		
	if(document.getElementById("nchPhone2").value == "") {
		msg += "\nPlease enter your Shipping Phone";
		if (focusFld == "")
			focusFld = "nchPhone2";
	}		
	
	if (msg != ""){
		document.getElementById(focusFld).focus();
		alert(msg);
		return false;
	}else{
		//post form
		return true;
	}
}

function frmVerifyNewRegistration() {
	var msg = "", focusFld="";
	
	if (document.getElementById("vchFName").value == ""){
		msg += "Please enter your First Name";
		if (focusFld == "")
			focusFld = "vchFName";
	}
	if (document.getElementById("vchLName").value == ""){
		msg += "\nPlease enter your Last Name";
		if (focusFld == "")
			focusFld = "vchLName";
	}
	if(document.getElementById("vchEmail").value == "") {
		msg += "\nPlease enter your Email address";
		if (focusFld == "")
			focusFld = "vchEmail";
	}
	if(document.getElementById("vchPassword").value == "") {
		msg += "\nPlease enter a Password";
		if (focusFld == "")
			focusFld = "vchPassword";
	}
	if(document.getElementById("vchPasswordVerify").value == "") {
		msg += "\nPlease enter a Confirm Password which matches your Password";
		if (focusFld == "")
			focusFld = "vchPasswordVerify";
	}
	if (document.getElementById("vchPassword").value != "" && document.getElementById("vchPasswordVerify").value != ""){
		if(document.getElementById("vchPassword").value != document.getElementById("vchPasswordVerify").value) {
	       msg += "\nThe passwords you typed in did not match";
		   focusFld = "vchPassword";
		}
	}
	if(document.getElementById("vchBillAddress1").value == "") {
		msg += "\nPlease enter your Billing Street Address 1";
		if (focusFld == "")
			focusFld = "vchBillAddress1";
	}
	if(document.getElementById("vchBillCity").value == "") {
		msg += "\nPlease enter your Billing City";
		if (focusFld == "")
			focusFld = "vchBillCity";
	}	
	if(document.getElementById("vchBillState").value == 0) {
		msg += "\nPlease select your Billing State/Province";
		if (focusFld == "")
			focusFld = "vchBillState";
	}
	if(document.getElementById("vchBillZip").value == "") {
		msg += "\nPlease enter your Billing Zip/Postal Code";
		if (focusFld == "")
			focusFld = "vchBillZip";
	}	
	if(document.getElementById("vchShipAddress1").value == "") {
		msg += "\nPlease enter your Shipping Street Address 1";
		if (focusFld == "")
			focusFld = "vchShipAddress1";
	}
	if(document.getElementById("vchShipCity").value == "") {
		msg += "\nPlease enter your Shipping City";
		if (focusFld == "")
			focusFld = "vchShipCity";
	}	
	if(document.getElementById("vchShipState").value == 0) {
		msg += "\nPlease select your Shipping State/Province";
		if (focusFld == "")
			focusFld = "vchShipState";
	}	
	if(document.getElementById("vchShipZip").value == "") {
		msg += "\nPlease enter your Shipping Zip/Postal Code";
		if (focusFld == "")
			focusFld = "vchShipZip";
	}		
	if(document.getElementById("nchPhone2").value == "") {
		msg += "\nPlease enter your Shipping Phone";
		if (focusFld == "")
			focusFld = "nchPhone2";
	}
	
	if (msg != ""){
		document.getElementById(focusFld).focus();
		alert(msg);
		return false;	
	}else{
		//post form
		return true;
	}
}

//cancel button on frm_checkout.cfm 
function fcnReturnToCart() {
	location.href = "/index.cfm?fuseaction=rosenfeld.cart&mode=0&startRow=1";
}

//called on frm_checkout.cfm?step=2
function fcnProcessOrder(obj, UUID) {
	var aParams = new Array();
	var cvv2 = document.getElementById("cvv2").value;

	if(!fcnFixIntByVal(cvv2)) {
		alert("CVV2 is required and must be all numeric.");
		document.getElementById("cvv2").focus();
		return false;
	} else {
		if(CheckCardNumber(obj)) {
			//update form with disabled controls
			document.getElementById("divPlaceOrderButton").innerHTML = '<input type="button" value="  Place Order " class="submit" disabled>';
			document.getElementById("divCancelButton").innerHTML = '<input type="button" value="  Cancel  " class="submit" disabled>';
			document.getElementById("divAddRemoveButton").innerHTML = '<input type="button" value="  Add/Remove Items  " class="submit" disabled>';
	
			//build JSRS parameter array
			aParams[0] = UUID;
			aParams[1] = document.getElementById("vchCC").value; //cc no
			aParams[2] = document.getElementById("intExpMonth").value; //expiration month
			aParams[3] = document.getElementById("intExpYear").value; //expiration year
			aParams[4] = cvv2;
			
			fcnJSRSProcessOrder(aParams);
		}
	}
}

function changeShipType(shipType){
	var aParams = new Array();
	aParams[0] = shipType;
	fcnJSRSChangeShipType(aParams);
}

//used on frm_shop.cfm
function fcnAddShopProductToCart(intProductId, intQuantity) {
	var aParams = new Array();
	aParams[0] = intProductId.toString();
	aParams[1] = intQuantity.toString();
	fcnJSRSAddShopProduct(aParams);
}

function fcnHelp(str) {
	alert(str);
}
