function openCvc2() {
	window.open("cvc2.php","NewWindow","WIDTH=400,HEIGHT=400,toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=yes");
}
function showDonationRecurring(p) {
	newwindow=window.open('donation_recurring.html#'+p,'name','height=400,width=400,toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=yes');
}

function enlargeProductPhoto(p) {
	newwindow=window.open('product_photo.php?p='+p+'&t=3','name','height=500,width=760,toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=yes');
}

function printThisPage() {
window.print();  
}
function redirectMe(strURL) {
document.location=strURL;  
}


function autoSelectGsShip() {
document.chkfrm.gift_set_shipping_method.selectedIndex=1;
document.chkfrm.gss.value=10;
}



function optionToInputField(fieldName,inputFieldName,formName) {
    var field = document.getElementById(fieldName);
    var fieldSel = field.selectedIndex;
    var fieldValue = field.options.item(fieldSel).value;
    var fieldInt=0;
    if(fieldValue=='3Day')
        fieldInt=20;
    if(fieldValue=='2Day')
        fieldInt=30;
    if(fieldValue=='7Day')
        fieldInt=10;

	document[formName][inputFieldName].value = fieldInt;
}




function turtleTotal() {
var donation_amt=parseFloat(document.chkfrm.amt.value);
var gift_set=parseFloat(document.chkfrm.gs.value);
var gift_set_shipping=parseFloat(document.chkfrm.gss.value);
var donationTotal=0;
var subTotal=0;
subTotal=((gift_set+gift_set_shipping)+donation_amt);

var donationTotal = Math.floor(subTotal*100+0.00000000001);
cents = donationTotal%100;
donationTotal = Math.floor(donationTotal/100).toString();
if(cents<10)
cents = "0" + cents;
for (var i = 0; i < Math.floor((donationTotal.length-(1+i))/3); i++)
donationTotal = donationTotal.substring(0,donationTotal.length-(4*i+3))+','+
donationTotal.substring(donationTotal.length-(4*i+3));
donationTotal = donationTotal + '.' + cents;

document.chkfrm.amtTotal.value=donationTotal;


}



function changeFieldValue(fieldNum,offVar) {
	document.chkfrm[fieldNum].value = offVar;
}
function addFieldValue(fieldNum,offVar,title,qtyVar,sizeVar,listingPrice,pTotal,lid) {
	
	var qtyField;
	var currTotalField;
	qtyField = document.chkfrm[qtyVar].value;
	var sizeField;
	sizeField = document.chkfrm[sizeVar].value;
	//var newVal = offVar+','+title+','+qtyField+','+sizeField+'::';
	var newVal = qtyField+','+sizeField+','+title+','+listingPrice+'::';
	document.chkfrm[fieldNum].value += newVal;

	document.chkfrm['pA'].value += offVar+',';



	qtyField = parseInt(qtyField);

	var itemTotal = 0;
	var totalField;
	totalField = parseFloat(document.chkfrm[pTotal].value);
	var listingPrice;
	//listingPrice = parseFloat(listingPrice);


itemTotal = Math.floor((listingPrice*qtyField)*100+0.00000000001);
cents = itemTotal%100;
itemTotal = Math.floor(itemTotal/100).toString();
if(cents<10)
cents = "0" + cents;
for (var i = 0; i < Math.floor((itemTotal.length-(1+i))/3); i++)
itemTotal = itemTotal.substring(0,itemTotal.length-(4*i+3))+','+
itemTotal.substring(itemTotal.length-(4*i+3));
itemTotal = itemTotal + '.' + cents;




	var remLink;
	var bananaVal
	bananaVal = qtyField+'V9'+sizeField+'V9'+title+'VZ'+itemTotal+'V9V0';
	remLink = "<table cellpadding=0 cellspacing=0 border=0><td width=30><img src=gfx/1x1.gif width=30 height=1></td><td width=40>&nbsp;</td><td width=40>&nbsp;</td><td width=278>&nbsp;</td><td width=10>&nbsp;</td><td width=60>&nbsp;</td><td width=20>&nbsp;</td></tr><tr><td>&nbsp;<a href=javascript:// onClick=\"remFieldValue(\'"+bananaVal+"\',\'"+itemTotal+"\',\'"+offVar+"\');\"><img src=gfx/rembutton.gif border=0></a></td><td>";
	var newValHTML = remLink+qtyField+'</td><td>'+sizeField+'</td><td>'+title+'</td><td><img src=gfx/1x1.gif width=1 height=20></td><td align=right>'+itemTotal+'</td><td></td></tr></table>';
	var full = document.chkfrm['vdHTML'].value;
	document.chkfrm['vdHTML'].value += newValHTML;
	document.getElementById(lid).innerHTML=full+newValHTML;

	var currentShip = parseFloat(document.chkfrm['vq'].value);
	currentShip = currentShip+1;
	document.chkfrm['vq'].value = currentShip;

	updateTotal(itemTotal);



}


function subtractFromTotal(itemTotal) {

currentTotal = parseFloat(document.chkfrm['pTotal'].value);

itemTotal = Math.floor((currentTotal-itemTotal)*100+0.00000000001);
cents = itemTotal%100;
itemTotal = Math.floor(itemTotal/100).toString();
if(cents<10)
cents = "0" + cents;
for (var i = 0; i < Math.floor((itemTotal.length-(1+i))/3); i++)
itemTotal = itemTotal.substring(0,itemTotal.length-(4*i+3))+','+
itemTotal.substring(itemTotal.length-(4*i+3));
itemTotal = itemTotal + '.' + cents;


	document.chkfrm['pTotal'].value = itemTotal;

	var newTotal = 0;
	updateTotal(newTotal);



}




function updateTotal(newTotal) {

var shipCost = 0;
var currentShip = 0;
currentShip = document.chkfrm['vq'].value;
if(currentShip>0) {
	shipCost = '3.00';
	document.getElementById('dynDonationShipping').innerHTML = '3.00';
}
else {
	document.getElementById('dynDonationShipping').innerHTML = '0.00';
}

var lid = 'dynDonationSTotal';
var currSTotal = 0;
currSTotal = parseFloat(document.chkfrm['pTotal'].value);
newTotal = parseFloat(newTotal);
var sTotal = 0;

sTotal = Math.floor((currSTotal+newTotal)*100+0.00000000001);
cents = sTotal%100;
sTotal = Math.floor(sTotal/100).toString();
if(cents<10)
cents = "0" + cents;
for (var i = 0; i < Math.floor((sTotal.length-(1+i))/3); i++)
sTotal = sTotal.substring(0,sTotal.length-(4*i+3))+','+
sTotal.substring(sTotal.length-(4*i+3));
sTotal = sTotal + '.' + cents;

document.getElementById(lid).innerHTML=sTotal;
document.chkfrm['pTotal'].value=sTotal;







lid = 'dynDonationGTotal';
var currTotal = 0;
currTotal = parseFloat(document.chkfrm['pTotal'].value);
shipCost = parseFloat(shipCost);
var gTotal = 0;
//gTotal = currTotal+newTotal;

gTotal = Math.floor((currTotal+shipCost)*100+0.00000000001);
cents = gTotal%100;
gTotal = Math.floor(gTotal/100).toString();
if(cents<10)
cents = "0" + cents;
for (var i = 0; i < Math.floor((gTotal.length-(1+i))/3); i++)
gTotal = gTotal.substring(0,gTotal.length-(4*i+3))+','+
gTotal.substring(gTotal.length-(4*i+3));
gTotal = gTotal + '.' + cents;

document.getElementById(lid).innerHTML=gTotal;
//document.chkfrm['pTotal'].value=gTotal;







}





function remFieldValue(removeValue,itemTotal,offVar) {
	var lid = 'dynDonationUpsell';
	var currVal;
	var xVal;
	var removeValue;
	var removeValueHTML = '</td><td>';
	var remPipe = /V9/g;
	var remRight = /VZ/g;
	var remEnd = /V0/g;
	var removeValueX = removeValue;
	removeValueX = removeValueX.replace(remRight,'</td><td><img src=gfx/1x1.gif width=1 height=20></td><td align=right>');
	removeValueX = removeValueX.replace(remPipe,'</td><td>');
	removeValueX = removeValueX.replace(remEnd,'</td></tr></table>');
	removeValueHTML += removeValueX;

	var removeValueHTMLFull = '<table cellpadding=0 cellspacing=0 border=0><td width=30><img src=gfx/1x1.gif width=30 height=1></td><td width=40>&nbsp;</td><td width=40>&nbsp;</td><td width=278>&nbsp;</td><td width=10>&nbsp;</td><td width=60>&nbsp;</td><td width=20>&nbsp;</td></tr><tr><td>&nbsp;<a href=javascript:// onClick="remFieldValue(\''+removeValue+'\',\''+itemTotal+'\',\''+offVar+'\');"><img src=gfx/rembutton.gif border=0></a>'+removeValueHTML+'';
	var finalValueHTML = document.chkfrm['vdHTML'].value;


	//var rg = new RegExp(removeValueHTMLFull,"g"); 


	var dummy = finalValueHTML.replace(removeValueHTMLFull,'');
	document.chkfrm['vdHTML'].value = dummy;

	document.getElementById(lid).innerHTML=dummy;


	offVar += ',';
	var pAVal = document.chkfrm['pA'].value;
	pAVal = pAVal.replace(offVar,'');
	document.chkfrm['pA'].value = pAVal;

	removeValue = removeValue.replace(remPipe,',');
	removeValue = removeValue.replace(remEnd,'::');

	currVal = document.chkfrm['vd'].value;
	xVal = currVal.replace(removeValue,'');
	document.chkfrm['vd'].value = xVal;


	var currentShip = parseFloat(document.chkfrm['vq'].value);
	currentShip = currentShip-1;
	document.chkfrm['vq'].value = currentShip;



	subtractFromTotal(itemTotal);


}


function focusField(fieldName) {
	document.chkfrm[fieldName].focus();
}

function othAmtCheckRepHTML(lid) {

		clear_radio_buttons();

		document.getElementById('donationLevel5').innerHTML = '<table width=448 cellpadding=0 cellspacing=0 border=0><tr><td width=20 class=content align=center><input type=radio name=donationLevel value=5 checked onClick="changeFieldValue(\'donationLevel\',\'5\'); changeFieldValue(\'amt\',\'\'); changeLayerBgColor(\'donationLevel1\',\'#FFFFFF\'); changeLayerBgColor(\'donationLevel2\',\'#FFFFFF\'); changeLayerBgColor(\'donationLevel3\',\'#FFFFFF\'); changeLayerBgColor(\'donationLevel4\',\'#FFFFFF\'); changeLayerBgColor(\'donationLevel5\',\'#C4C8D4\'); changeLayerBgColor(\'donationLevel6\',\'#FFFFFF\'); changeLayerBgColor(\'donationLevel7\',\'#FFFFFF\');"></td><td width=10><img src=gfx/1x1.gif width=10 height=1></td><td class=content><b>Other</a></b><br>Please enter amount in the \'Amount to Donate\' field below.</td></tr></table>';

}
function clear_radio_buttons() {
     for (var i = 0; i < document.chkfrm.donationLevel.length; i++) {
          document.chkfrm.donationLevel[i].checked = false;
     }
}

function changeDonationEditFields() {

	var lid = 'dynDonationDonor';

	document.chkfrm['baddchg'].value = 1;
	var eCompanyName = document.chkfrm['cfn'].value;
	var eFirstName = document.chkfrm['bfn'].value;
	var eLastName = document.chkfrm['bln'].value;
	var eBillingAddr = document.chkfrm['badd'].value;
	var eBillingCity = document.chkfrm['bcity'].value;
	var eBillingState = document.chkfrm['bstate'].value;
	var eBillingZipcode = document.chkfrm['bzip'].value;
	var eBillingEmail = document.chkfrm['bemail'].value;
	var eCardType = document.chkfrm['bcardtype'].value;
	var eCardNum = document.chkfrm['cnum'].value;
	var eCardExpMo = document.chkfrm['cexpdatemo'].value;
	var eCardExpYr = document.chkfrm['cexpdateyr'].value;
	var eCardCVC2 = document.chkfrm['cvc2'].value;

	eCompanyName = eCompanyName.replace(/(<([^>]+)>)/ig,""); 
	eFirstName = eFirstName.replace(/(<([^>]+)>)/ig,""); 
	eLastName = eLastName.replace(/(<([^>]+)>)/ig,""); 
	eBillingAddr = eBillingAddr.replace(/(<([^>]+)>)/ig,""); 
	eBillingCity = eBillingCity.replace(/(<([^>]+)>)/ig,""); 
	eBillingState = eBillingState.replace(/(<([^>]+)>)/ig,""); 
	eBillingZipcode = eBillingZipcode.replace(/(<([^>]+)>)/ig,""); 
	eBillingEmail = eBillingEmail.replace(/(<([^>]+)>)/ig,""); 
	eCardType = eCardType.replace(/(<([^>]+)>)/ig,""); 
	eCardNum = eCardNum.replace(/(<([^>]+)>)/ig,""); 
	eCardExpMo = eCardExpMo.replace(/(<([^>]+)>)/ig,""); 
	eCardExpYr = eCardExpYr.replace(/(<([^>]+)>)/ig,""); 
	eCardCVC2 = eCardCVC2.replace(/(<([^>]+)>)/ig,""); 

	document.chkfrm['cfn'].value = eCompanyName;
	document.chkfrm['bfn'].value = eFirstName;
	document.chkfrm['bln'].value = eLastName;
	document.chkfrm['badd'].value = eBillingAddr;
	document.chkfrm['bcity'].value = eBillingCity;
	document.chkfrm['bstate'].value = eBillingState;
	document.chkfrm['bzip'].value = eBillingZipcode;
	document.chkfrm['bemail'].value = eBillingEmail;
	document.chkfrm['bcardtype'].value = eCardType;
	document.chkfrm['cnum'].value = eCardNum;
	document.chkfrm['cexpdatemo'].value = eCardExpMo;
	document.chkfrm['cexpdateyr'].value = eCardExpYr;
	document.chkfrm['cvc2'].value = eCardCVC2;

	var dynDonationDonorHTML = "<table width=478 cellpadding=0 cellspacing=0 border=0><tr><td colspan=2><img src=gfx/1x1.gif width=1 height=14></td></tr><tr><td width=30 align=center valign=top><a href=javascript:// onClick=\"swap(1,'dynDonationEdit');\"><img src=gfx/editbutton.gif border=0></a></center></td><td width=428>"+eCompanyName+"<br>"+eFirstName+"&nbsp;"+eLastName+"<br>"+eBillingAddr+"<br>"+eBillingCity+"&nbsp;"+eBillingState+"&nbsp;&nbsp;"+eBillingZipcode+"<br>"+eBillingEmail+"<br><br>"+eCardType+"&nbsp;:&nbsp;"+eCardNum+"<br>"+eCardExpMo+" "+eCardExpYr+"</td><td width=20>&nbsp;</td></tr><tr><td colspan=7><img src=gfx/1x1.gif width=1 height=14></td></tr></table>";

	document.getElementById(lid).innerHTML=dynDonationDonorHTML;
}



var DHTML = (document.getElementById || document.all || document.layers);

function swap(flag,lid)
{
	if (!DHTML) return;
	var x = new getLayerObj(lid);
	x.style.visibility = (flag) ? 'visible' : 'hidden';
}

function resizeDiv(lid,amt) {

	var x = new getLayerObj(lid);
	x.style.height = amt + 'px';

}



function updateGrandTotalStore(lid) {

var currSTotal=0;
var addToToal=0;
var sTotal=0;

currSTotal=parseFloat(document.chkfrm['grandTotalCurr'].value);
addToTotal=parseFloat(document.chkfrm['amt'].value);
//addToTotal=parseFloat(amt);

sTotal = Math.floor((currSTotal+addToTotal)*100+0.00000000001);
cents = sTotal%100;
sTotal = Math.floor(sTotal/100).toString();
if(cents<10)
cents = "0" + cents;
for (var i = 0; i < Math.floor((sTotal.length-(1+i))/3); i++)
sTotal = sTotal.substring(0,sTotal.length-(4*i+3))+','+
sTotal.substring(sTotal.length-(4*i+3));
sTotal = '$' + sTotal + '.' + cents;

document.getElementById(lid).innerHTML=sTotal;
sTotal=null;
//if(addToTotal>1)
document.getElementById('donationQtyDiv').innerHTML='1';
document.getElementById('donationSizeDiv').innerHTML='n/a';
document.getElementById('donationTitleDiv').innerHTML='Donation to Pro Peninsula';
document.getElementById('donationAmountDiv').innerHTML=addToTotal+'.00';

}




function getLayerObj(name) {
  if (document.getElementById)  {
  	this.obj = document.getElementById(name);
	this.style = document.getElementById(name).style;
  }
  else if (document.all)  {
	this.obj = document.all[name];
	this.style = document.all[name].style;
  }
  else if (document.layers)  {
   	this.obj = document.layers[name];
   	this.style = document.layers[name];
  }
}




function changeLayerBgColor(lid,col)
{
	if (!DHTML) return;
	var x = new getLayerObj(lid);
	x.style.backgroundColor = col;
}


function updateSLTotalOther() {

var newTotal = parseFloat(document.chkfrm['amt'].value);
if(newTotal>0) {
}
else {
changeLayerBgColor('donationLevel5','#FFFFFF');
document.chkfrm.donationChkAmt.checked=false;
document.chkfrm.amt.value="";
}
updateSLTotal();
}



function updateSLTotal() {
var lid='grandTotal';
var newTotal = document.chkfrm['amt'].value;
if(newTotal=="") {
    newTotal = '0.00';
}
else {
    newTotal = parseFloat(newTotal);
}
var tixOption = document.getElementById("tix");
var tixCount = parseInt(tixOption.options[tixOption.selectedIndex].value);
var currTotal = (tixCount*60.00);
var grandTotal = (currTotal + newTotal);
currTotal=parseFloat(currTotal);
newTotal=parseFloat(newTotal);
grandTotal = Math.floor((currTotal+newTotal)*100+0.00000000001);
cents = grandTotal%100;
grandTotal = Math.floor(grandTotal/100).toString();
if(cents<10)
cents = "0" + cents;
for (var i = 0; i < Math.floor((grandTotal.length-(1+i))/3); i++)
grandTotal = grandTotal.substring(0,grandTotal.length-(4*i+3))+','+
grandTotal.substring(grandTotal.length-(4*i+3));
grandTotal = '$' + grandTotal + '.' + cents;
var contentHTML = '<b>Total Amount to Charge: ' + grandTotal + '</b>';
document.getElementById(lid).innerHTML=contentHTML;
}

function updateDivContent(lid,contentHTML) {
document.getElementById(lid).innerHTML=contentHTML;
}



function moveLayerVertical(lid,dist)
{
	if (!DHTML) return;
	var x = new getLayerObj(lid);
	x.style.top =+ dist+'px';

}

function changeLayerPosByScreen(width,height,lid) {
	if (!DHTML) return;
	


  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement &&
      ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }



	var scrWidth = (myWidth - (width+200))/2;
	var scrHeight = (myHeight - height)/2;
	
	
	var x = new getLayerObj(lid);
	x.style.top = scrHeight;
	x.style.left = scrWidth;
	x.style.height = height;
	x.style.width = width;
}



function transferBillingInfo() {
	document.chkfrm.scfn.value = document.chkfrm.cfn.value;
	document.chkfrm.sfn.value = document.chkfrm.bfn.value;
	document.chkfrm.sln.value = document.chkfrm.bln.value;
	document.chkfrm.sadd.value = document.chkfrm.badd.value;
	document.chkfrm.scity.value = document.chkfrm.bcity.value;
	document.chkfrm.sstate.value = document.chkfrm.bstate.value;
	document.chkfrm.szip.value = document.chkfrm.bzip.value;
	document.chkfrm.sphone.value = document.chkfrm.bphone.value;
}



function submitOnce(theform){
if (document.all||document.getElementById){
for (i=0;i<theform.length;i++){
var tempobj=theform.elements[i]
if(tempobj.type.toLowerCase()=="submit"||tempobj.type.toLowerCase()=="reset")
tempobj.disabled=true
}
}
}



function expandCollapse(obj,lid,ctrlVarOpen,ctrlVarClose) {
	var el = document.getElementById(obj);
	if ( el.style.display != "none" ) {
		el.style.display = 'none';
		document.getElementById(lid).innerHTML = '<a href=javascript:// onclick="expandCollapse(\''+obj+'\',\''+lid+'\',\''+ctrlVarOpen+'\',\''+ctrlVarClose+'\');">'+ctrlVarOpen+'</a>';
	}
	else {
		el.style.display = '';
		document.getElementById(lid).innerHTML = '<a href=javascript:// onclick="expandCollapse(\''+obj+'\',\''+lid+'\',\''+ctrlVarOpen+'\',\''+ctrlVarClose+'\');">'+ctrlVarClose+'</a>';
	}
}
