// // Submits a form request by specifing the name of the form and submit button
// for the HTML architecture to execute. //

function submitFormSubRequest(formName, buttonName) 
{	 
     document.forms[formName].bmAction.value = buttonName;
     document.forms[formName].bmSubmit.value = buttonName;
     document.forms[formName].submit();
}
function submitenter(field,e, formName, buttonName)
{
	var keycode;
	if (window.event) keycode = window.event.keyCode;
	else if (e) keycode = e.which;
	else return true;
	if (keycode == 13)
	{
	     document.forms[formName].bmAction.value = buttonName;
	     document.forms[formName].bmSubmit.value = buttonName;
	     document.forms[formName].submit();

		return false;
	}
	else
	return true;
}

function setButtonNameAndSubmitRequest(buttonName,formName,action) {
	document.forms[formName].elements[buttonName].name=action;
	submitRequest(formName,action);
}

function setTwoObjectsValueAndSubmitRequest(obj1, obj1Value, obj2, obj2Value, formName, action) {	
	setObjectValue(obj1,obj1Value,formName);
	setObjectValue(obj2,obj2Value,formName);
	submitRequest(formName,action);
}

function setTwoObjectsValueAndSubmitOrderRequest(size, obj1Value, obj2, obj2Value, formName, action) {	
	setCartItemObjectValue(size, obj1Value,obj2Value,formName);
	setObjectValue(obj2,obj2Value,formName);
	submitRequest(formName,action);
}

function setObjectValueAndSubmitRequest (obj,objValue,formName,action) {	
	setObjectValue (obj,objValue,formName);
	submitRequest(formName,action);
}

function setObjectValueAndSubmitRequestOnENTER (field, e, obj,objValue,formName,action) {	
	var keycode;
	if (window.event) keycode = window.event.keyCode;
	else if (e) keycode = e.which;
	else return true;
	if (keycode == 13)
	{
		setObjectValue (obj,objValue,formName);
		document.forms[formName].bmAction.value=action;	
		document.forms[formName].bmSubmit.value=action;	
		document.forms[formName].submit();
		return false;
	}
	else
	return true;
}

function setObjectValue(obj,objValue,formName) {
	var form = document.forms[formName];   
	form.elements[obj].value= objValue;
}

function setCartItemObjectValue(size, obj1Value,obj2Value,formName) {	
	var form = document.forms[formName];  
	if(size == 1){
		form.giftwrap.value = obj1Value;
	}else{
		form.giftwrap[obj2Value].value = obj1Value;
		if(obj1Value == "false")
			form.giftwrapcomment[obj2Value].value = "";
	}
}

function clearPaymentAndSubmitRequest(formName,action) {	
	
	if (document.forms[formName].elements['same_bill_ship'].checked==true){
		document.forms[formName].elements['BILL_TO_ADDRESS<>firstName'].value="";
		document.forms[formName].elements['BILL_TO_ADDRESS<>lastName'].value="";
		document.forms[formName].elements['BILL_TO_ADDRESS<>address1'].value="";
		document.forms[formName].elements['BILL_TO_ADDRESS<>address2'].value="";
		document.forms[formName].elements['BILL_TO_ADDRESS<>city'].value="";
		document.forms[formName].elements['BILL_TO_ADDRESS<>state_cd'].value=-1;
		document.forms[formName].elements['BILL_TO_ADDRESS<>postal'].value="";
		document.forms[formName].elements['BILL_TO_ADDRESS<>phone'].value="";
		document.forms[formName].elements['BILL_TO_ADDRESS<>ATR_PhoneExtension'].value="";
		document.forms[formName].elements['BILL_TO_ADDRESS<>country_cd'].selectIndex="";
	}
	document.forms[formName].bmAction.value=action;	
	document.forms[formName].bmSubmit.value=action;	
	document.forms[formName].submit();
}
function submitRequest(formName,action) {	
	document.forms[formName].bmAction.value=action;	
	document.forms[formName].bmSubmit.value=action;	
	document.forms[formName].submit();
}

function setObjectValueAndSubmitHyperLink(btn, obj,objValue,formName,action){
	document.forms[formName].elements[btn].name=action;
	setObjectValueAndSubmitRequest(obj,objValue,formName,action);
}

function submitHyperLink(btn,formName,action){
	document.forms[formName].elements[btn].name=action;
	submitRequest(formName,action);
}

function submitFormSelect(formName, selectName) 
{
     document.forms[formName].submit();
}

function open_imagezoomwindow(url, name){
	  window.open(url,name,"toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width=700,height=600");	
}

function open_giftwrapzoomwindow(url){
	  window.open(url,name,"toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width=600,height=500");	
}


function open_fully_configurable_window(url)
{
  	var options = 'location='     	+ 1 + "," +
				  'toolbar='  		+ 1 + "," +
				  'menubar='  		+ 1 + "," +
				  'directories=' 	+ 1 + "," +
				  'status=' 		+ 1 + "," +
				  "scrollbars=" 	+ 1 + "," +
				  "resizable="   	+ 1 + "," +
				  "left="        	+ 125 +  "," +
				  "top="         	+ 100 +  "," +
				  "width="       	+ 800 +  "," +
				  "height="      	+ 595 ;

	var mW = window.open(url,"configurable",options);
}

function redirect_url(url)
{
	window.location=url;
}

function open_checkinv_window(url, name){
	var newwindow = window.open(url,name,"toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=yes,resizable=0,width=800,height=600");
	if (window.focus) {
		newwindow.focus();
	}
}
function open_small_window(url){
  window.open(url,"smaller","toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=0,width=450,height=470");
}
function open_large_window(url){
  window.open(url,"larger","toolbar=1,location=1,directories=0,status=1,menubar=1,scrollbars=1,resizable=1,width=640,height=480");
 }

 function open_full_window(url){
  window.open(url,"larger","toolbar=1,location=1,directories=0,status=1,menubar=1,scrollbars=1,resizable=1,width=1000,height=600");
 }
function showAddress(address,mapObj) {
	if(!bBrowserCompatible)
		return;
	this.newAddress = address;
	//alert(address+" --> "+mapObj);
	var mapObj = document.getElementById(mapObj);
	var map = new GMap2(mapObj);
			//map.setCenter(new GLatLng(37.4419, -122.1419), 13);
			var geocoder = new GClientGeocoder();
	if (geocoder) {
		geocoder.getLatLng(
			address,
				function(point) {
					if (!point) {
						//alert(address + " not found");
						//hideDivElement(mapObj);
					} else {
						showDivElement(mapObj);
						map.setCenter(point, 13);
						var marker = new GMarker(point);
						map.addOverlay(marker);
						marker.openInfoWindowHtml(address);
					}
				}
		);
		GEvent.bind(map, "click", this, this.onMapClick);
	}
}

showAddress.prototype.onMapClick = function() {
	alert("googleMapAdd = "+googleMapAdd);
	alert("newAddress = "+this.newAddress);
	window.open(googleMapAdd+this.newAddress);
}

function showDivElement(item) {
	if(item != null) {
			if (navigator.appName == 'Netscape') {
			item.style.display = 'block';
			} else {
					item.style.display = 'inline-block';
			}
	}
}

function hideDivElement(item) {
	if(item != null) {
		item.style.display = 'none';
	}
}

function showAllMaps() {
	var showMap = null;
	for (var i = 0; i < addArr.length; i++) {
		showMap = new showAddress(addArr[i],mapArr[i]);
	}
}

function disableSelect(){
	if(document.form_payment_info.card_brand.value == "CTRetail")
	{
		document.form_payment_info.card_month.disabled = true;
		document.form_payment_info.card_year.disabled = true;
	} else {
		document.form_payment_info.card_month.disabled = false;
		document.form_payment_info.card_year.disabled = false;
	}
}
function disableSelect(formName){
	if(document.forms[formName].elements['CREDIT_CARD<>cardBrand_cd'].value == "CTRetail")
	{
		document.forms[formName].elements['CREDIT_CARD<>cardMonth_cd'].disabled = true;
		document.forms[formName].elements['CREDIT_CARD<>cardYear_cd'].disabled = true;
	} else {
		document.forms[formName].elements['CREDIT_CARD<>cardMonth_cd'].disabled = false;
		document.forms[formName].elements['CREDIT_CARD<>cardYear_cd'].disabled = false;
	}
}

function roll_over(img_name, img_src)
{
   document[img_name].src = img_src;
}

function submitSelectSkuHyperLink(btn, obj1,objValue1,obj2,objValue2,formName,action){
	document.forms[formName].elements[btn].name=action;
	setObjectValue(obj1,objValue1,formName,action);
	setObjectValueAndSubmitRequest(obj2,objValue2,formName,action);
}
function submitProductCompareHyperLink(btn, obj1, objValue1, obj2, objValue2, obj3, objValue3, formName, action) 
{
	document.forms[formName].elements[btn].name=action;
	setObjectValue(obj1,objValue1,formName,action);
	setObjectValue(obj2,objValue2,formName,action);
	setObjectValueAndSubmitRequest(obj3,objValue3,formName,action);
}

function getCookieData(labelName) {
    var labelLen = labelName.length;
    var cookieData = document.cookie;
    var cLen = cookieData.length;
    var i = 0;
    var cEnd;
    while (i < cLen) {
        var j = i + labelLen;
        if (cookieData.substring(i,j) == labelName) {
            cEnd = cookieData.indexOf(";",j);
            if (cEnd == -1) {
                cEnd = cookieData.length;
            }
            return unescape(cookieData.substring(j+1, cEnd));
        }
        i++;
    }
    return "";
}

function trimString(sInString) {
    sInString = sInString.replace( /^\s+/g, "" );
    return sInString.replace( /\s+$/g, "" );
}

function appendPostalCode(url){
    url = trimString(url);
    var postalCode = getCookieData("postal_code");
    if (url.charAt(url.length-1) == "="){
        url = url + postalCode;
    }
    open_fully_configurable_window(url);
}
function open_surchargewindow(url){
          var top = (screen.height - 500) / 2;
          var left = (screen.width - 400) / 2;
          window.open(url,name,"toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width=400,height=400,left="+left+",top="+top);
}

// javascript for product_compare.jsp begin
function deleteProduct(productId)
{
	document.form_delete_product.product_id.value=productId;
	document.form_delete_product.submit();
}

function deleteProductCompareArray(deleteArray)
{
	document.form_delete_product_compare_array.deleteAll.value=deleteArray;
	document.form_delete_product_compare_array.submit();
}

function deleteProductCompareArraySearch(deleteArray)
{
	document.form_delete_product_compare_array_search.deleteAll.value=deleteArray;
	document.form_delete_product_compare_array_search.submit();
}

function add_to_cart(sku_id, prd_id)
{
	document.form_prd_compare_add_to_cart.elements['ADD_CART_ITEM<>sku_id'].value=sku_id;
	document.form_prd_compare_add_to_cart.elements['ADD_CART_ITEM<>prd_id'].value=prd_id;
	document.form_prd_compare_add_to_cart.submit();
}
// javascript for product_compare.jsp end
function pageUrl(formName, buttonName, url){
	document.getElementById("pageUrl").value = url;
	submitFormSubRequest(formName, buttonName);	
}
