<!--//
var async = true;
var def_country = 'US';  // Default Country
var alt_country = 'CA'; // Alternate Country
var ALERT_TITLE = "Attention!";
var ALERT_BUTTON_TEXT = "Ok";

if (navigator.appVersion.indexOf("MSIE")!=-1) {
	var bName = 'MSIE';
	var temp = navigator.appVersion.split("MSIE");
	var bVer = parseFloat(temp[1]);
} else {
	var bName = navigator.appName;
	var bVer = parseFloat(navigator.appVersion);
}

function getstamp()	{
	date = new Date();
	return date.getTime();
}

//function loadDoc(url, postdata, cb_func) {
//Start garth - track wood upgrade price to delete from original, sale, prices
function loadDoc(url, postdata, cb_func, lessprice) {
//End Garth
var req;
	req = false;
    if (window.XMLHttpRequest) {
    	try { req = new XMLHttpRequest(); } catch(e) { req = false; }
    } else if (window.ActiveXObject) {
       	try { req = new ActiveXObject("Msxml2.XMLHTTP"); } 
		catch(e) { 
			try { req = new ActiveXObject("Microsoft.XMLHTTP"); }
			catch(e) { req = false; }
		}
    }
	if(req) {
		req.open("POST", url, async);
		req.onreadystatechange = function() { 
			if (req.readyState == 4 && req.status == 200 && cb_func != "") {
//				eval("cb_"+cb_func+"(req.responseText);");
//Start Garth - track wood upgrade price to delete from original, sale, prices
				eval("cb_"+cb_func+"(req.responseText,lessprice);");
//End Garth
			}
		}
		req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		req.send(postdata);
	}
}

function selectAll (frm, item) {
	var e = frm.elements;
	var re = new RegExp("^"+item);
	for (i=0;i<e.length;i++) {
		if (e[i].id != '' && e[i].id.match(re)) {
			e[i].checked = true;
		}
	}
}

function del_event (id) {
	if (jsconfirm()) location.href = 'index.php?l=account&d=deletereg&id='+id+'&tab=5';
}

function jsconfirm (note) {
	if (note == undefined) note = 'Are you sure you want to complete this action?';
	if (confirm(note)) {
		return true;
	} else {
		return false;
	}
}


function cb_updateWood(txt){
    var woodAddition = 1*txt;
	if (document.getElementById("wood_price")) document.getElementById("wood_price").innerHTML = formatCurrency(woodAddition);

}


function cb_updatePrice (txt,lessprice) {
	//alert(txt);
	var result = txt.split("||");
	var thetextarea = document.getElementById("engravingbox");
	var pricepercharacter = document.getElementById("pricepercharacter").value;
	var oversize_price = 1*document.getElementById("oversize_price").value.substr(1); //added 05/17/2009 - Garth
	var free50 = document.product_form.free50.value;
	if (typeof(lessprice) == 'undefined')
	  {
	  //not wood radio
	  if (document.getElementById("wood_price"))
	    {
		lessprice = 1*document.getElementById("wood_price").innerHTML.substr(1);
		}
		else
		{
		lessprice = 0;
		}
	  }
	  else
	  {
      cb_updateWood(lessprice); //is wood radio
	  }
	if (result[0])document.getElementById("product_price").innerHTML = formatCurrency((1*result[0].substr(1))-lessprice);
	if ((result[1])&&document.getElementById("list_price")) document.getElementById("list_price").innerHTML = formatCurrency((1*result[1].substr(1))-lessprice);
	if ((result[2])&&document.getElementById("sale_price")) document.getElementById("sale_price").innerHTML = formatCurrency((1*result[2].substr(1))-lessprice);
	
	if ((thetextarea)&&(pricepercharacter)&&document.getElementById("engraving_price"))
	  {
      numLetters = thetextarea.value.split(' ').join('').length;
      if (free50=='1'){
       if (document.getElementById("engraving_notice")) document.getElementById("engraving_notice").innerHTML = '(First 50 characters included.)';
      (numLetters>50)?numLetters-=50:numLetters=0;
      }
      else
      {
       if (document.getElementById("engraving_notice")) document.getElementById("engraving_notice").innerHTML = '';
      }
      var engravingprice = numLetters * pricepercharacter;

      document.getElementById("engraving_price").innerHTML = formatCurrency(engravingprice);
	  
	  }
	  ((result[2])&&document.getElementById("sale_price"))?thesubtotal=result[2]:thesubtotal=result[0];
	  thesubtotal = 1*thesubtotal.substr(1);//remove $
	  if(engravingprice)thesubtotal+=engravingprice;
  	  if (document.getElementById("oversizepacking")) thesubtotal += oversize_price;
	  document.getElementById("subtotal_price").innerHTML = formatCurrency(thesubtotal);

   // if ((result[5])&&document.getElementById("subtotal_price")) document.getElementById("subtotal_price").innerHTML = result[5];
}

function showhideCharge(txt) {
	var result = txt.split("||");
	document.getElementById("oversize_charge1").innerHTML = result[0];
	document.getElementById("oversize_charge2").innerHTML = result[0];
	document.getElementById("oversize_charge3").innerHTML = result[0];
	document.getElementById("oversize_charge4").innerHTML = result[0];
	document.getElementById("cart_subtotal").innerHTML = result[1];
	document.getElementById("cart_total").innerHTML = result[1];
}

//Start Garth - showShipping()
function showShipping(shippingselect)
  {
  if(document.getElementById("subtotal")&&document.getElementById("subtotal2"))						 
    {
	shippingvalue = shippingselect.options[shippingselect.selectedIndex].value;
	document.getElementById("subtotal2").innerHTML = formatCurrency((document.getElementById("subtotal").innerHTML.substr(1)*1)+(shippingvalue.substr(shippingvalue.indexOf("-> ")+3)*1));
	}
  setShippingChoice(shippingselect.selectedIndex);
}
//End Garth - showShipping()

function postalAPO(txt){
		if(txt=='1'){
			document.getElementById('apo_shipping').style.display = 'none';
			document.getElementById('apo_rate').style.display = 'none';
		document.getElementById('estimate_shipping').style.display = 'inline';
		document.getElementById('shipping_estimate').style.display = 'inline';
		}
		else
		{
			document.getElementById('estimate_shipping').style.display = 'none';
			document.getElementById('shipping_estimate').style.display = 'none';
		document.getElementById('apo_shipping').style.display = 'inline';
		document.getElementById('apo_rate').style.display = 'inline';
		}


	}

function cb_getResult (txt) {
	document.getElementById("message").innerHTML = txt;
}

function cb_revResult (txt) {
	eval(txt);
}

function cb_payResult (txt) {
	if (txt != "ok") {
		document.getElementById("message").innerHTML = txt;
	} else {
		document.forms['payment'].submit();
	}
}

function rowVisibility (strVisibility, intRowIndex) {
	if (navigator.product == "Gecko" && navigator.productSub && navigator.productSub > "20041010" && (navigator.userAgent.indexOf("rv:1.8") != -1 || navigator.userAgent.indexOf("rv:1.9") != -1)) {
		document.getElementById("cc_table").rows[intRowIndex].style.visibility = strVisibility;
	} else if (strVisibility == "visible") {
		if(document.all && document.compatMode && document.compatMode == "CSS1Compat" && !window.opera) {
			document.getElementById("cc_table").rows[intRowIndex].style.display = "block";
		} else if (document.getElementById && document.getElementById("cc_table").rows) {
			document.getElementById("cc_table").rows[intRowIndex].style.display = "table-row";
		}
	} else if (strVisibility == "collapse") {
		document.getElementById("cc_table").rows[intRowIndex].style.display = "none";
	}
}

function cc_type (val) {
	if (val == 'Solo' || val == 'Switch') {
		rowVisibility('visible', 5);
		rowVisibility('visible', 6);
	} else {
		rowVisibility('collapse', 5);
		rowVisibility('collapse', 6);
	}
}

function clearMessages () {
	document.getElementById("message").innerHTML = '';
}

//function updatePrice (frm, url) {
//Start Garth - track wood upgrade price to delete from original, sale, prices
function updatePrice (frm, url, lessprice) {
//End Garth
    var e = frm.elements;
	var opts = [];
	var post;
	for (i=0; i<e.length; i++) {
		if (e[i].type == 'select-one') {
			opts.push(e[i].name+"="+e[i].value);
		}
		if ((e[i].type == 'radio' || e[i].type == 'checkbox') && e[i].checked) {
			opts.push(e[i].name+"="+e[i].value);
		}
	}
	post = opts.join("&");
//    loadDoc(url, post, 'updatePrice');
//Start garth - track wood upgrade price to delete from original, sale, prices
     loadDoc(url, post, 'updatePrice', lessprice);
//End Garth
}

function check_payment (url) {
	var e = document.forms['payment'].elements;
	var data = [];
	var post;
	for (i=0; i<e.length; i++) data.push(e[i].name+"="+e[i].value);
	post = data.join("&");
	loadDoc(url, post, 'payResult');
}

function edit_event (id) {
	loadDoc('index.php?l=edit_registry', 'id='+id, 'revResult');
}

function hold_order () {
	loadDoc('checkout.php?l=hold_order', '', 'revResult');
}

function ajaxPost (frm, url, result) {
	if (!result) result = 'getResult';
	var e = frm.elements;
	var data = [];
	var post;
	for (i=0; i<e.length; i++) {
		if ((e[i].type == 'checkbox' && e[i].checked) || e[i].type != 'checkbox') {
			data.push(e[i].name+"="+e[i].value);
		}
	}
	post = data.join("&");
	loadDoc(url, post, result);
}

function pause (form_name, perform) {
	form = document.forms[form_name];
	ajaxPost(form, 'index.php?l=loading', 'revResult');
	setTimeout("ajaxPost(form, '"+perform+"', 'revResult')", 2000);
}

function toggle_country (value, type) {
	if (value != def_country && value != alt_country && value != "") {
		document.getElementById(type+'_other').style.display = 'inline';
		document.getElementById(type+'_state').style.display = 'none';
		document.forms['customer_info'].elements['userinfo['+type+'_oset]'].value = '1';
	} else {
		document.getElementById(type+'_other').style.display = 'none';
		document.getElementById(type+'_state').style.display = 'inline';
		document.forms['customer_info'].elements['userinfo['+type+'_oset]'].value = '0';
	}
}

function reset_forms (items, form) {
	for (x in items) {
		var titem = items[x];
		var fitem = document.forms[form].elements[titem];
		if (fitem.selectedIndex != null)
			fitem.selectedIndex = 0;
		else
			fitem.value = '';
	}
}

function bill_to_ship (form) {
	if (form.elements['userinfo[same]'].checked) {
		form.elements['userinfo[ship_first_name]'].value		= form.elements['userinfo[bill_first_name]'].value;
		form.elements['userinfo[ship_last_name]'].value			= form.elements['userinfo[bill_last_name]'].value;
		form.elements['userinfo[ship_company_name]'].value		= form.elements['userinfo[bill_company_name]'].value;
		form.elements['userinfo[ship_address1]'].value			= form.elements['userinfo[bill_address1]'].value;
		form.elements['userinfo[ship_address2]'].value			= form.elements['userinfo[bill_address2]'].value;
		form.elements['userinfo[ship_city]'].value				= form.elements['userinfo[bill_city]'].value;
		form.elements['userinfo[ship_state]'].selectedIndex		= form.elements['userinfo[bill_state]'].selectedIndex;
		form.elements['userinfo[ship_other]'].value				= form.elements['userinfo[bill_other]'].value;
		form.elements['userinfo[ship_zip]'].value				= form.elements['userinfo[bill_zip]'].value;
		form.elements['userinfo[ship_country]'].selectedIndex	= form.elements['userinfo[bill_country]'].selectedIndex;
		toggle_country(form.elements['userinfo[ship_country]'].value, 'ship');
	}
}

function popupImage (full_url, url) {
	 window.open(full_url+'index.php?l=product_images&'+url,'popupImage','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,copyhistory=no,width=100,height=100,screenX=150,screenY=150,top=150,left=150');
}

function reload_image (prefix, num) {
	var stamp = getstamp();
	document.images['verify_image'+num].src = prefix+'include/classes/class.iverify.php?'+stamp;
	if (bName == "MSIE" && bVer == 6) {
		alert('Image Reloaded Successfully!');
	}
}

function toggle_div (fname) {
	if (document.getElementById(fname).style.display == 'block')
		document.getElementById(fname).style.display = 'none';
	else 
		document.getElementById(fname).style.display = 'block';
}


function toggle_menu (fname,iname) {
	if (document.getElementById(fname).style.display == 'block')
	{
		document.getElementById(fname).style.display = 'none';
		document.getElementById(iname).src = 'themes/texas_trophies/images/menuplus.gif';
	}
	else
	{
		document.getElementById(fname).style.display = 'block';
		document.getElementById(iname).src = 'themes/texas_trophies/images/menuminus.gif';
	}
}

function toggle_menu_soho (fname,iname) {
	alert('pow');
	if (document.getElementById(fname).style.display == 'block')
	{
		document.getElementById(fname).style.display = 'none';
		document.getElementById(iname).src = 'themes/texas_trophies/images/menuplus.gif';
	}
	else
	{
		document.getElementById(fname).style.display = 'block';
		document.getElementById(iname).src = 'shop/themes/texas_trophies/images/menuminus.gif';
	}
}

function CalcKeyCode(aChar) {
  var character = aChar.substring(0,1);
  var code = aChar.charCodeAt(0);
  return code;
}

function checkNumber(val) {

  if(val.value.length==2)
    {
	rCode = CalcKeyCode(val.value.charAt(1));
	if(rCode < 48 || rCode > 57 )
	  {
	  val.value=val.value.charAt(0);
	  }
	}
  lCode = CalcKeyCode(val.value.charAt(0));
  if(lCode < 49 || lCode > 57 )
	{
	if(val.value.length==2)
	  {
	  val.value=val.value.charAt(1);
	  }
	  else
	  {
	  val.value=1;
	  }
	}
  return false;
}



function formatCurrency(num)
  {
num = num.toString().replace(/\$|\,/g,'');
if(isNaN(num))
num = "0";
sign = (num == (num = Math.abs(num)));
num = Math.floor(num*100+0.50000000001);
cents = num%100;
num = Math.floor(num/100).toString();
if(cents<10)
cents = "0" + cents;
for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
num = num.substring(0,num.length-(4*i+3))+','+
num.substring(num.length-(4*i+3));
return (((sign)?'':'-') + '$' + num + '.' + cents);
  }

function unclearThis(val)
  {
  if(!val.value)
    {
	val.value = '0';
	}
  }
function clearThis(val)
  {
  if(val.value<1)
    {
	val.value="";
	}
  }

//Start Garth - Cookie to remember shipping choice
function Set_Cookie( name, value, expires, path, domain, secure ) 
{
// set time, it's in milliseconds
var today = new Date();
today.setTime( today.getTime() );

/*
if the expires variable is set, make the correct 
expires time, the current script below will set 
it for x number of days, to make it for hours, 
delete * 24, for minutes, delete * 60 * 24
*/
if ( expires )
{
expires = expires * 1000 * 60 * 60 * 24;
}
var expires_date = new Date( today.getTime() + (expires) );

document.cookie = name + "=" +escape( value ) +
( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + 
( ( path ) ? ";path=" + path : "" ) + 
( ( domain ) ? ";domain=" + domain : "" ) +
( ( secure ) ? ";secure" : "" );
}

// this function gets the cookie, if it exists
function Get_Cookie( name ) {
	
var start = document.cookie.indexOf( name + "=" );
var len = start + name.length + 1;
if ( ( !start ) &&
( name != document.cookie.substring( 0, name.length ) ) )
{
return null;
}
if ( start == -1 ) return null;
var end = document.cookie.indexOf( ";", len );
if ( end == -1 ) end = document.cookie.length;
return unescape( document.cookie.substring( len, end ) );
}

// this deletes the cookie when called
function Delete_Cookie( name, path, domain ) {
if ( Get_Cookie( name ) ) document.cookie = name + "=" +
( ( path ) ? ";path=" + path : "") +
( ( domain ) ? ";domain=" + domain : "" ) +
";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}

function setShippingChoice (shippingchoice){
Delete_Cookie('shipping', '/', '');
// remember, these are the possible parameters for Set_Cookie:
// name, value, expires, path, domain, secure

Set_Cookie( 'shipping', shippingchoice, '', '/', '', '' );
// and these are the parameters for Delete_Cookie:
// name, path, domain
// make sure you use the same parameters in Set and Delete Cookie.
}



//End Garth

//-->
