window.rateFactor = .0356;
function UpdatePriceDefault(){

	
		var newtotal=0;
		var currelement="";
		e_arr = document.frmoptions.list.value.split(",");
		
		for(x=0; x<e_arr.length-1; x++){
			eval("e=document.frmoptions."+e_arr[x]+";");
			for (y=0; y<e.length; y++){
				if (e[y].checked) newtotal+=parseFloat(e[y].value);
			}
		}
		
		/*
		for(x=0; x<es.length; x++){
			if (currelement!=es[x]){
				// do something here
				currelement=es[x];
			}
			if (es[x].substring(0,8)=="upgrade_"){
				alert("y=document.frmoptions."+es[x]+".length;");
				eval("y=document.frmoptions."+es[x]+".length;");
				alert(y);
				if (y.checked==true) {
					newtotal+=parseFloat(y.value);
				}
			}
		}
		*/
		
		newtotal+=parseFloat(document.frmoptions.base.value);
		leaseprice = newtotal * rateFactor;
		var formatter = new NumberFormat (newtotal);
		formatter.setPlaces(2);
		formatter.setCurrency(true);
		formatter.setCommas(true);
		var freshtotal = formatter.toFormatted();
		
		var leaseformatter = new NumberFormat(leaseprice);
		leaseformatter.setPlaces(0);
		leaseformatter.setCurrency(true);
		leaseformatter.setCommas(true);
		var leaseformat = leaseformatter.toFormatted();
		
		document.frmoptions.total.value = freshtotal;
		z = findObj("pricetag");
		z.innerHTML = freshtotal;
		zlease = findObj("leasetag");
		if(zlease) zlease.innerHTML = 'As low as '+leaseformat+' / Month';
		
		y = findObj("pricetag_top");
		y.innerHTML = freshtotal;
		ylease = findObj("leasetag_top");
		if(ylease) ylease.innerHTML = 'As low as '+leaseformat+' / month';
		
		x = findObj("pricetag_opt");
		if( x ){
			x.innerHTML = freshtotal;
		}
		xlease = findObj("leasetag_opt");
		if(xlease) xlease.innerHTML = 'As low as '+leaseformat+' / month';
		
		wlease = findObj("leasetag_base");
		if(wlease) wlease.innerHTML = 'As low as '+leaseformat+' / month';
	}
	
	function getPOptionsTotal(){
		var returnValue = 0;
	
		//Package Options
		//alert( document.frmoptions.opt_id_list.value );
		str_list = document.frmoptions.opt_id_list.value;
		
		if( str_list.length > 0 ){
			po_arr = str_list.split(",");
			for(x=0; x<po_arr.length; x++){
				eval( "pchk=document.frmoptions.ogo_id_"+ po_arr[x] +";" );
				eval( "e=document.frmoptions.ogo_price_"+ po_arr[x] +";" );
				eval( "qty=document.frmoptions.ogo_qty_"+ po_arr[x] +";" );
				
				//check qty for invalid input
				if(parseInt(qty.value)!=qty.value-0){
					qty.value = 1;
				}
				if( qty.value < 1 ){
					qty.value = 1;
				}
					
				if( pchk.checked == true ){
					returnValue += Number( e.value )*Number( qty.value );
					//alert( e.value +" "+ po_arr[x]+" "+returnValue );
				}
			}
		}
	
		return returnValue;
	}
	
	function UpdatePriceReal(){
	
		var newtotal=0;
		var currelement="";
		e_arr = document.frmoptions.list.value.split(",");
		
		for(x=0; x<e_arr.length-1; x++){
			eval("e=document.frmoptions."+e_arr[x]+";");
			for (y=0; y<e.length; y++){
				if (e[y].checked) newtotal+=parseFloat(e[y].value);
			}
		}
		
		newtotal+=parseFloat(document.frmoptions.base.value);
		
		newtotal+=parseFloat(getPOptionsTotal());
		leaseprice = newtotal * rateFactor;
		
		var formatter = new NumberFormat (newtotal);
		formatter.setPlaces(2);
		formatter.setCurrency(true);
		formatter.setCommas(true);
		var freshtotal = formatter.toFormatted();
		document.frmoptions.total.value = freshtotal;
		
		var leaseformatter = new NumberFormat(leaseprice);
		leaseformatter.setPlaces(0);
		leaseformatter.setCurrency(true);
		leaseformatter.setCommas(true);
		var leaseformat = leaseformatter.toFormatted();
		
		z = findObj("pricetag");
		z.innerHTML = freshtotal;
		zlease = findObj("leasetag");
		if(zlease) zlease.innerHTML = 'As low as '+leaseformat+' / Month';
		
		y = findObj("pricetag_top");
		y.innerHTML = freshtotal;
		ylease = findObj("leasetag_top");
		if(ylease) ylease.innerHTML = 'As low as '+leaseformat+' / month';
		
		x = findObj("pricetag_opt");
		if( x && x.innerHTML ){
			x.innerHTML = freshtotal;	
		}
		xlease = findObj("leasetag_opt");
		if(xlease) xlease.innerHTML = 'As low as '+leaseformat+' / month';
		
		wlease = findObj("leasetag_base");
		if(wlease) wlease.innerHTML = 'As low as '+leaseformat+' / month';
	}

	function UpdatePrice( switchFormField , newId ){
	
		switchFormField.value=newId;
	
		UpdatePriceReal();
	}
	
	/*
	SwitchImage
	accepts: 	iname, image name
				newsrc, switch to image.
	returns:	none.
	*/
	function SwitchImage(iname,newsrc){
		if ( newsrc!="" ) {
			x = findObj(iname);
			x.src = "/claycart/images/"+newsrc;
		}
	}
	
	/*
	SwitchImageX
	accepts: 	upgrade_id, upgrade id
				uo_id, upgrade option id
				newsrc, switch to image
				isRadio, is the radio or info link.
	returns:	none.
	*/
	function SwitchImageX( upgrade_id, uo_id, newsrc, isRadio ){
	
		upgrade_opt_ids = findObj("upgrade_opt_ids_"+upgrade_id);
		switch_img = findObj("ui_"+upgrade_id);
		save_img = findObj("upgrade_save_img_"+upgrade_id);
	
		//alert( save_img.value );
	
	
		newsrc_path = newsrc;
	
	/*
		if ( newsrc!="" ) {
			newsrc_path = "/claycart/images/"+newsrc;			
		}else{
			newsrc_path = "";
		}
	*/
		
		var u_opt_arr = upgrade_opt_ids.value.split(",");
		
		if( isRadio ){

			//loop through all upgrade options.
			bInfoAllDown = true;
			for(var x=0; x<=u_opt_arr.length-1; x++) {
			
				info_div = findObj( "opt_info_"+u_opt_arr[x] );
				
				if( info_div.innerHTML == "" ){
					//alert( "up " + u_opt_arr[x] );
					
				}else{
					//alert( "down " + u_opt_arr[x] );
					bInfoAllDown = false;
				}
			}
			
			if( bInfoAllDown ){
				if( newsrc_path != "" ) switch_img.src = newsrc_path;
			}
		
			if( newsrc_path != "" ) save_img.value = newsrc_path;
		
		}else{
		
			//loop through all upgrade options.
			bInfoAllDown = true;
			for(var x=0; x<=u_opt_arr.length-1; x++) {
			
				info_div = findObj( "opt_info_"+u_opt_arr[x] );
				
				if( info_div.innerHTML == "" ){
					//alert( "up " + u_opt_arr[x] );
					
				}else{
					//alert( "down " + u_opt_arr[x] );
					bInfoAllDown = false;
				}
			}
		
			if( bInfoAllDown ) {
				if( newsrc_path != "" ){
					switch_img.src = newsrc_path;
				}
			}else{
				switch_img.src = save_img.value;
				
			}
			
		
		}
	
	}
	
	function checkFields( thisForm ){
		var rtrn = false;
		

		if(	thisForm.pc_fname.value != "" && thisForm.pc_lname.value != "" && thisForm.pc_phone.value != "" && thisForm.pc_email.value != "" ){
			rtrn = true;
		}else{
			rtrn = false;
			alert("Must fill in required fields!");
		}

		
		return rtrn;
	}
	
	function fncSubmitFinalLeaseReview(thisForm){
		if(
		   thisForm.pc_fname.value == '' ||
		   thisForm.pc_lname.value == '' ||
		   thisForm.pc_company.value == '' ||
		   thisForm.pc_address1.value == '' ||
		   thisForm.pc_city.value == '' ||
		   thisForm.pc_state.value == '' ||
		   thisForm.pc_zip.value == '' ||
		   thisForm.pc_phone.value == '' ||
		   thisForm.pc_email.value == '' ||
		   thisForm.pc_years.value == ''
		   ){
			alert("Must fill in required fields!");
		}else{
			thisForm.submit();
		}
	}
	
	function fncSubmitFinalReview( thisForm ) {
		if( checkFields( thisForm ) ){	
			thisForm.submit();
		}
	}

	function fncSubmitAddToCart( thisForm ){
	
		thisForm.submit_type.value = 'addtocart';
	
		//if( checkFields( thisForm ) ){
			thisForm.submit();
		//}
	}
		
	function fncSubmitReview( thisForm ){
	
		thisForm.submit_type.value = 'review';
	
		//if( checkFields( thisForm ) ){	
			thisForm.submit();
		//}
	}
	
	function fncSubmitLease( thisForm ){
	
		thisForm.submit_type.value = 'lease';
	
		//if( checkFields( thisForm ) ){	
			thisForm.submit();
		//}
	}
	
	function fncShowInformation( vDisplayName, vInfo, vPlus ){
		
		if( document.getElementById( vDisplayName ).innerHTML == "" ){
			document.getElementById( vDisplayName ).innerHTML = vInfo;
			
			/*
			if( vPlus != "" ){
				x = findObj(vPlus);
				x.src = "/img/icon_p_minus.gif";
			}
			*/
			
		}else{
			document.getElementById( vDisplayName ).innerHTML = "";
			
			/*
			if( vPlus != "" ){
				x = findObj(vPlus);
				x.src = "/img/icon_plus.gif";
			}
			*/
		}
		//alert( vInfo );
		
	}
	
	function closeOption( vUpOptId ){
	
		fncShowInformation( 'opt_info_'+vUpOptId, "", 'plus_'+vUpOptId );
	
	}
	function closeUpgrade( vUpId ){
	
		fncShowInformation( 'up_help_'+vUpId, "", "" );
	
	}
	function popProductInfoPage( products_id ){
	
		win_opened = window.open('/claycart/product_info_pop.php?pid='+ products_id +'&pk=t','product_view_popup','scrollbars=yes,resizable=yes,width=600,height=500,status=no');
		win_opened.focus();
	
	}

