// JavaScript Document
<!-- Begin
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);
}
//  End -->



function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Invalid E-mail ID")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid E-mail ID")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

 		 return true					
	}


function clearValues()
{
	var thisForm = document.forms['cproi'];
	
	thisForm.avgmonthlyTotSales.value = '';
	thisForm.avgmonthlyCBs.value = '';
	thisForm.avgmonthlyvisits.value = '';
	thisForm.avgmonthlyNetleads.value = '';
	thisForm.backInStorePercent.value = '';
	thisForm.grossPerVehicle.value = '';
	
	
	
}


function validatePage()
{
  var thisForm = document.forms['cproi'];
  if (thisForm.dealershipName.value=='')
  {
    alert("Please enter a dealerhip name.") ;
   clearValues();
    return false ;
  }
  
  if (thisForm.contactName.value=='')
  {
    alert("Please provide the contact name for this dealership.") ;
   clearValues();	
    return false ;
  }

  if (thisForm.phoneNumber.value=='')
  {
    alert("Please enter the phone number for this dealerhip name.") ;
   clearValues();	
    return false ;
  }  

  if (thisForm.email.value=='')
  {
    alert("Please enter an email address for the contact person for this dealerhip.") ;
   clearValues();	
    return false ;
  }
  else
  {
	  var emailID=thisForm.email;
	
	if ((emailID.value==null)||(emailID.value=="")){
		alert("Please Enter your Email ID")
		emailID.focus()
		return false
	}
	if (echeck(emailID.value)==false){
		emailID.value=""
		emailID.focus()
		return false
	}
  }

   calculatePage();
  return true;

	
}



function digitsOnly(inputStr)
{
	//var strLen = inputStr.length
	NumberStr = '0123456789';
	
	if(inputStr.indexOf('.') > 0)
	{
		var noDec = inputStr.substr(0,inputStr.indexOf('.'));
	}
	else
	{
  	   var noDec = inputStr;
	}
	//alert("no dec "+noDec);
	
	

	var tempStr="";
	
//	for(d=0; d<inputStr.length; d++)
	for(d=0; d<noDec.length; d++)
	
	{
//		alert("digits: "+ noDec.substr(d, 1));		

		if(NumberStr.indexOf(noDec.substr(d, 1)) >= 0)
		{
			tempStr += noDec.substr(d, 1);
			//alert(noDec.substr(d, (d+1)));
		}
	}
//	alert("clean digits: "+tempStr);
	return tempStr;
}  



function calculatePage()
{

    var thisForm = document.forms['cproi'];
	fLength = thisForm.length;	
 
    var t1 = thisForm.avgmonthlyTotSales.value;
	if(isNaN(t1))
	{
		alert("Enter numbers only.");
	}	
	var t2 = thisForm.avgmonthlyCBs.value;
	if(isNaN(t2))
	{
		alert("Enter numbers only.");
	}		
	var t3 = thisForm.avgmonthlyvisits.value;
	if(isNaN(t3))
	{
		alert("Enter numbers only.");
	}		
	var t4 = thisForm.avgmonthlyNetleads.value;
	if(isNaN(t4))
	{
		alert("Enter numbers only.");
	}		
	var t5 = thisForm.avgmonthlyrejects.value;
	if(isNaN(t5))
	{
		alert("Enter numbers only.");
	}		
	var t6 = thisForm.avgMonthlyPLProspects.value;
	
	var t7 = thisForm.backInStorePercent.value;
	if(isNaN(t7))
	{
		alert("Enter numbers only.");
	}
	
	var t9 = thisForm.extraGross.value;
//	alert(t9);	
	var t10 = thisForm.grossPerVehicle.value;
	if(isNaN(t10))
	{
		alert("Enter numbers only.");
	}		
	var t11 = thisForm.costProgram.value;
	var t12 = thisForm.costProgramTot.value;
	var t13 = thisForm.ROI.value;


	//	alert(t6=(t5*21.8))

	thisForm.avgMonthlyPLProspects.value = (Math.round(t5*0.218));
	
	if(t5 != '' && t6 != '' && t7 != '')
	{
	
	  thisForm.additionalSales.value = Math.round(t6*(t7/100));
	}
	
	var t8 = thisForm.additionalSales.value;
	
	//thisForm.thisForm.extraGross.value = (t8*t10);
	
	
	if(t10 != '')
	{
		thisForm.extraGross.value = formatCurrency((Math.round(t8)*t10));

	}
	if(t8 != '')
	{
		thisForm.costProgram.value = Math.round(t6);
		thisForm.costProgramTot.value = Math.round(t6)*3.0;
//		thisForm.ROI.value = (thisForm.costProgramTot.value+0/thisForm.extraGross.value+0);

		var tempVal = digitsOnly(thisForm.extraGross.value);
		
		thisForm.ROI.value = Math.round((tempVal/parseFloat(thisForm.costProgramTot.value))*100);
//		alert("costProgramTot "+thisForm.costProgramTot.value);
	}
	


	
	if(t13 != '')
	{
		// target = ifram
//      thisForm.action = 'dll';
//      thisForm.target = 'iframename';

//thisForm.submit();			




setEmailValues();


	}
	
	
//	 thisForm.action = 'emailForm.php';
//	 thisForm.action = 'index.html';
//     thisForm.submit();	
	

	
	
	

	
}

function setEmailValues()
{
	
//	alert("setting email values");
	var thisForm = document.forms['hiddenVals'];
	
	thisForm.Dealership_Name.value = document.cproi.dealershipName.value;
	thisForm.Contact_Name.value = document.cproi.contactName.value;
	thisForm.Phone_Number.value = document.cproi.phoneNumber.value;
	thisForm.Email_Address.value = document.cproi.email.value;
	thisForm.Average_Monthly_Showroom_Visits.value = document.cproi.avgmonthlyvisits.value;
	thisForm.Average_Monthly_Total_Sales.value = document.cproi.avgmonthlyTotSales.value;
	thisForm.Average_Monthly_Internet_Leads.value = document.cproi.avgmonthlyNetleads.value;
	thisForm.Average_Monthly_Credit_Bureaus_Pulled.value = document.cproi.avgmonthlyCBs.value;
	thisForm.Average_Monthly_Credit_Rejects.value = document.cproi.avgmonthlyrejects.value;
	thisForm.Average_Monthly_Pipeline_PreQual_Prospects.value = document.cproi.avgMonthlyPipelineProspects.value;
	thisForm.Estimated_Percent_Back_In_Store_To_Close.value = document.cproi.backInStorePercent.value;
	thisForm.Additional_Extra_Monthly_Sales.value = document.cproi.additionalSales.value;
	thisForm.Estimate_Gross_Per_Vehicle.value = document.cproi.grossPerVehicle.value;
	thisForm.Total_Extra_Gross.value = document.cproi.extraGross.value;
	thisForm.Total_Monthly_Program_Cost.value = document.cproi.costProgram.value;
	thisForm.Total_Monthly_Program_Cost_Total.value = document.cproi.costProgramTot.value;
	thisForm.Credit_Pipeline_ROI.value = document.cproi.ROI.value;

	document.hiddenVals.action = 'http://www.promaxonline.com/scripts/EmailUs.dll';
	document.hiddenVals.target = 'hiddenFormVals';
	document.hiddenVals.submit();
	
}


