/*
**	jscript.js - Java scripts for Purrfect Jewels Web Site
**
**	Revision History
**		Date		Initials	Description
**		--------------------------------------------
**		05/01/02	MJE		Initial Creation
**						Added to_page function for navigation
**      02/17/05    MJE     Changed Add2Cart, 2Checkout, 2shopcart
**                          routines to display pop-temp.html
**	
*/


/*
**	Name: popup
**	Parameter: mylink, windowname
**	Purpose: Popup another browser with mylink
*/
function popup(mylink, windowname)
{
	if (! window.focus)return true;
	var href;
	if (typeof(mylink) == 'string')
		href=mylink;
	else
		href=mylink.href;

	window.open(href, windowname);
	return false;
}

function popup_orig(mylink, windowname)
{
	if (! window.focus)return true;
	var href;
	if (typeof(mylink) == 'string')
		href=mylink;
	else
		href=mylink.href;

	window.open(href, windowname, 'width=400,height=400,scrollbars=yes');
	return false;
}


/*
**	Name: getSelectValue
**	Parameter: selectObject - Select object to get value from 
**	Purpose: Helper function to get value of select object passed in
*/
function getSelectValue( selectObject )
{
	return selectObject.options[selectObject.selectedIndex].value;
}


function showCheckOutErrMsg()
{
	var strErr = "";
	strErr = "Please make sure all the required form elements (ones with red labels)\n";
	strErr += "are filled in and that all email addresses are correctly specified.\n";;
	strErr += "For example: me@myisp.com or me@myisp.net.";

	alert(strErr);
}

function showConfirmErrMsg()
{
	var strErr = "";

	strErr = "Please make sure Credit card type, Name-on-card, Card-Number, and ";
	strErr += "Expiration Month/Year are correctly filled out.";

	alert(strErr);
}

/*
**	Name: initObjects
**	Parameter: None.
**	Purpose: Initializes all forms	
*/
function initObjects()
{
	formArray = new Array();

	/* Purrfect Jewels */
	formArray[0] = document.frmSculpturedCirclet;
	formArray[1] = document.frmTeardropSwirl;
	formArray[2] = document.frmFormalAttirePj;
	formArray[3] = document.frmPurrfectCatch;
	formArray[4] = document.frmPurrfectPearls;
	formArray[5] = document.frmPositivelyPearls;
	formArray[6] = document.frmHeavenlyHeart;
	formArray[7] = document.frmPharaohsFavorite;
	formArray[8] = document.frmPurrfectlyElegant;
	formArray[9] = document.frmMarquiseMagic;

	
	/* Canine Collectables */
	formArray[10] = document.frmFiercelyFigaro;
	formArray[11] = document.frmFinelyFigaro;
	formArray[12] = document.frmDebonair;
	formArray[13] = document.frmFormalAttire;
	formArray[14] = document.frmCanineClassic;
	formArray[15] = document.frmBestInShow;
	formArray[16] = document.frmDynasty;
	formArray[17] = document.frmTailorMade;
	formArray[18] = document.frmDiamondHeart;
	formArray[19] = document.frmDiamondHeartSmall;
	formArray[20] = document.frmDiscoBall;
	formArray[21] = document.frmDiscoBallSmall;
	formArray[22] = document.frmSophisticateLarge;
	formArray[23] = document.frmSophisticateSmall;

	/* Bowdacious */
	formArray[24] = document.frmBowdaciousBraids;
	formArray[25] = document.frmBowdaciousSequins;
	formArray[26] = document.frmBowdaciousButtonsBows;
	formArray[27] = document.frmBowdaciousPearlsBows;
}

/*
**	Name: initCheckOutShipObjects
**	Parameter: None.
**	Purpose: Initializes all Checkout Form Objects
**	Used in Checkout_custinfo.html
*/
function initCheckOutShipObjects()
{
	formCheckOutShipArray = new Array();

	// Ship Textboxes
	formCheckOutShipArray[0] = document.frmCheckOutShip.ShipFirstName;
	formCheckOutShipArray[1] = document.frmCheckOutShip.ShipLastName;
	formCheckOutShipArray[2] = document.frmCheckOutShip.ShipPhone;
	formCheckOutShipArray[3] = document.frmCheckOutShip.ShipAddress;
	formCheckOutShipArray[4] = document.frmCheckOutShip.ShipCity;
	formCheckOutShipArray[5] = document.frmCheckOutShip.ShipZip;

	// Ship Combos
	formCheckOutShipArray[6] = document.frmCheckOutShip.ShipStateSelect;
	formCheckOutShipArray[7] = document.frmCheckOutShip.ShipCountry;

	// Emails
	formCheckOutShipArray[8] = document.frmCheckOutShip.ShipEmail;

	// Extra Stuff
	formCheckOutShipArray[9] = document.frmCheckOutShip.ShipFax;
	formCheckOutShipArray[10] = document.frmCheckOutShip.ShipCompany;
	formCheckOutShipArray[11] = document.frmCheckOutShip.ShipProvince;

	// Pet Info 1
	formCheckOutShipArray[12] = document.frmCheckOutShip.PetNameOne;
	formCheckOutShipArray[13] = document.frmCheckOutShip.PetTypeOne;
	formCheckOutShipArray[14] = document.frmCheckOutShip.PetBreedOne;
	formCheckOutShipArray[15] = document.frmCheckOutShip.PetAgeOne;
	formCheckOutShipArray[16] = document.frmCheckOutShip.PetBirthMonthOne;

	// Pet Info 2
	formCheckOutShipArray[17] = document.frmCheckOutShip.PetNameTwo;
	formCheckOutShipArray[18] = document.frmCheckOutShip.PetTypeTwo;
	formCheckOutShipArray[19] = document.frmCheckOutShip.PetBreedTwo;
	formCheckOutShipArray[20] = document.frmCheckOutShip.PetAgeTwo;
	formCheckOutShipArray[21] = document.frmCheckOutShip.PetBirthMonthTwo;

	// Shipping Option
	formCheckOutShipArray[22] = document.frmCheckOutShip.ShippingOptions;
}


/*
**	Name: initCheckOutBillObjects
**	Parameter: None.
**	Purpose: Initializes all Checkout Form Objects
**	Used in Checkout_custinfo.html
*/
function initCheckOutBillObjects()
{
	formCheckOutBillArray = new Array();

	// Bill Textboxes
	formCheckOutBillArray[0] = document.frmCheckOutBill.BillFirstName;
	formCheckOutBillArray[1] = document.frmCheckOutBill.BillLastName;
	formCheckOutBillArray[2] = document.frmCheckOutBill.BillPhone;
	formCheckOutBillArray[3] = document.frmCheckOutBill.BillAddress;
	formCheckOutBillArray[4] = document.frmCheckOutBill.BillCity;
	formCheckOutBillArray[5] = document.frmCheckOutBill.BillZip;

	// Bill Combos
	formCheckOutBillArray[6] = document.frmCheckOutBill.BillStateSelect;
	formCheckOutBillArray[7] = document.frmCheckOutBill.BillCountry;

	// Bill Email
	formCheckOutBillArray[8] = document.frmCheckOutBill.BillEmail;

	// Extra Stuff
	formCheckOutBillArray[9] = document.frmCheckOutBill.BillFax;
	formCheckOutBillArray[10] = document.frmCheckOutBill.BillCompany;
	formCheckOutBillArray[11] = document.frmCheckOutBill.BillProvince;
}


/*
**	Name: initConfirmObjects
**	Parameter: NA.
**	Purpose: Initializes frmConfirm Objects
**	Used: Checkout_confirm.html
*/
function initConfirmObjects()
{
	formConfirmArray = new Array();

	formConfirmArray[0] = document.frmConfirm.CardType;
	formConfirmArray[1] = document.frmConfirm.NameOnCard;
	formConfirmArray[2] = document.frmConfirm.CardNumber;
	formConfirmArray[3] = document.frmConfirm.CardExpireMonth;
	formConfirmArray[4] = document.frmConfirm.CardExpireYear;
}


/*
**	Name: isSelected
**	Parameter: combobox - Combobox to be validated.
**	Purpose: Validates frmCheckOut form elements
**	Used: Checkout_custinfo.html
*/
function isSelected(combobox)
{
	var selVal = getSelectValue(combobox);

	if( selVal == "" || selVal == null ) {
		return false;
	} else {
		return true;
	}
}

/*
**	Name: CheckOutFormIsValid
**	Parameter: None.
**	Purpose: Validates frmCheckOut form elements
**	Used: Checkout_custinfo.html
*/
function ConfirmFormIsValid()
{
	for(i=1 ; i<=2 ; i++)
	{
		if( isFilled( formConfirmArray[i] ) == false )
		{
			showConfirmErrMsg();
			return false;
		}
	}

	for(i=3 ; i<=4 ; i++)
	{
		if( isSelected( formConfirmArray[i] ) == false )
		{
			showConfirmErrMsg();
			return false;
		}
	}

	//alert("Confirm is valid");
	return true;
}

/*
**	Name: CheckOutFormIsValid
**	Parameter: None.
**	Purpose: Validates frmCheckOut form elements
**	Used: Checkout_custinfo.html
*/
function CheckOutShipFormIsValid()
{
	for(i=0 ; i<=5 ; i++)
	{
		if( isFilled(formCheckOutShipArray[i]) == false ) {
			showCheckOutErrMsg();
			return false;
		}
	}

	for(i=6 ; i<=7 ; i++)
	{
		if( isSelected(formCheckOutShipArray[i]) == false ) {
			showCheckOutErrMsg();
			return false;
		}
	}

	if( isEmail(formCheckOutShipArray[8]) == false ) {
		showCheckOutErrMsg();
		return false;
	}

	return true;
	//alert("ShipForm is valid");
	//return true;
}


/*
**	Name: CheckOutFormIsValid
**	Parameter: None.
**	Purpose: Validates frmCheckOut form elements
**	Used: Checkout_custinfo.html
*/
function CheckOutBillFormIsValid()
{
	if( isFilled(formCheckOutBillArray[0]) == false &&
	    isFilled(formCheckOutBillArray[1]) == false &&
	    isFilled(formCheckOutBillArray[2]) == false &&
	    isFilled(formCheckOutBillArray[3]) == false &&
	    isFilled(formCheckOutBillArray[4]) == false &&
	    isFilled(formCheckOutBillArray[5]) == false &&
	    isSelected(formCheckOutBillArray[6]) == false )
	{
		//alert("BillForm is valid");
		return true;
	} else {
		for(i=0 ; i<=5 ; i++)
		{
			if( isFilled(formCheckOutBillArray[i]) == false ) {
				showCheckOutErrMsg();
				return false;
			}
		}

		for(i=6 ; i<=7 ; i++)
		{
			if( isSelected(formCheckOutBillArray[i]) == false ) {
				showCheckOutErrMsg();
				return false;
			}
		}

		if( isEmail(formCheckOutBillArray[8]) == false ) {
			showCheckOutErrMsg();
			return false;
		}
		//alert("BillForm is valid");
		return true;
	}
}


/*
**	Name: isFilled
**	Parameter: elem - Form element to be checked for validity.
**	Purpose: Validates frmCheckOut form elements
**	Used: Checkout_custinfo.html
*/
function isFilled(elem)
{
	if( elem.value == "" || elem.value == null ) {
		return false;
	} else {
		return true;
	}
}


/*
**	Name: isEmail
**	Parameter: elem - Form element to be checked for validity.
**	Purpose: Validates frmCheckOut form elements
**	Used: Checkout_custinfo.html
*/
function isEmail(elem)
{
	if( elem.value.indexOf("@") != "-1" &&
		elem.value.indexOf(".") != "-1" && elem.value != "" ) {
		return true;
	} else {
		return false;
	}
}


/*
**	Name: to_page
**	Parameter: newLocation, is a string name of new page to go to.
**	Purpose: Navigate from one page to newLocation page preserving SCID
*/
function to_page( newLocation )
{
	var strURL = "";
	var ShopCartId = null;
	ShopCartId = window.document.frmMaster.SCID.value;
	strURL = "http://www.purrfectjewels.com/cgi-bin/genpg?";
	strURL += "SCID=";
	strURL += ShopCartId;
	strURL += "&SCREEN=";
	strURL += newLocation;

	window.document.location.href = strURL;
	//alert(strURL);
}


/*
**	Name: Add2Cart
**	Parameter: index - index into formArray for appropriate form (Collection of forms) 
**	Purpose: Adds product to shopping cart 
*/

function Add2Cart( index )
{
    popup("http://www.purrfectjewels.com/pop-temp.html", null);
}

/* function Add2Cart_orig( index )
{
	var strURL = "";
	var ShopCartId = null;
	var prodBase = "";
	var prodSize = "";
	var prodOption = "";
	var flagOption = -1;
	var valid = 1;
	var qty = 0;
	var prodList = "";
	var strError = "";
	var prodCode = "";
	var screen = "";

	qty = formArray[index].qtyTxt.value;
	prodBase = formArray[index].prodCodeBase.value;
	//prodSize = getSelectValue(formArray[index].prodCodeSize);
	flagOption = formArray[index].prodHasOption.value;
	ShopCartId = window.document.frmMaster.SCID.value;
	screen = formArray[index].screen.value;

	if( isNaN(qty) == true || qty == "" || prodBase == "NA" || qty == 0 )
	{
		valid *= 0;
	}

	if( flagOption == 1 )
	{
		prodOption = getSelectValue(formArray[index].prodCodeOption);
		if( prodOption == "NA" )
		{
			valid *= 0;
		}
	}

	if( valid == 0 )
	{
		strError = "Please make sure you entered a valid number in the quantity box.  Also, ";
		strError += "make sure you choose the correct size and all available options ";
		strError += "like (Color and Catch Style).";

		alert(strError);
	} else {
		prodCode = prodBase;
		//prodCode += "-";
		//prodCode += prodSize;

		if( flagOption == 1 )
		{
			prodCode += "-";
			prodCode += prodOption;
		}

		strURL = "http://www.purrfectjewels.com/cgi-bin/alter_cart?";
		strURL += "SCID=";
		strURL += ShopCartId;
		strURL += "&SCREEN=";
		strURL += screen;
		strURL += "&SC_ACTION=ADD";
		strURL += "&PLIST=";
		strURL += prodCode;
		strURL += ":";
		strURL += qty;

		//alert(strURL);
		window.document.location.href = strURL;
	}
} */

/*
**	Name: to_shopcart()
**	Parameter: NA
**	Purpose: Views Products in shopping cart
*/
function to_shopcart()
{
    popup("http://www.purrfectjewels.com/pop-temp.html", null);
}

/* function to_shopcart_orig()
{
	var strURL = "";
	var ShopCartId = null;
	ShopCartId = window.document.frmMaster.SCID.value;

	strURL = "http://www.purrfectjewels.com/cgi-bin/2shopcart?";
	strURL += "SCID=";
	strURL += ShopCartId;

	window.document.location.href=strURL;
} */

/*
**	Name: to_checkout()
**	Parameter: NA
**	Purpose: Javascript function to take you to the checkout section
*/
function to_checkout()
{
    popup("http://www.purrfectjewels.com/pop-temp.html", null);
}

/* function to_checkout_orig()
{
	var strURL = "";
	var ShopCartId = null;
	ShopCartId = window.document.frmMaster.SCID.value;

	strURL = "http://www.purrfectjewels.com/cgi-bin/2checkout?";
	strURL += "SCID=";
	strURL += ShopCartId;

	window.document.location.href=strURL;
} */

