//Roi Downtime... page
function setFormatForDowntime(){
	//Set total cost on main page.
	window.opener.document.getElementById('totcost_internet_downtime').value =document.getElementById('annual_admin_cost').value;
	//As because intrusion has some dependency on downtime.
	window.opener.document.getElementById('totcost_network_intrusion').value =document.getElementById('total_of_intrusion_after_downtime').value;
	//calculate when page load.
	calculateGrantTotal();
}
function openWindowLinkDowntime(){
	var fn = document.getElementById("fn").value;
	var mn = document.getElementById("mn").value;
	var options = "scrollbars=yes,resizable=yes,width=640";
	window.open("./RoiDowntime?fn="+fn+"&mn="+mn,"",options);
}

//Roi Intrusion... page
function setFormatForIntrusion(){
	//Set total cost on main page.
	window.opener.document.getElementById('totcost_network_intrusion').value =document.getElementById('total_annual_prod_loss_intrusion').value; 
	//calculate when page load.
	calculateGrantTotal();
}
function openWindowIntrusion(){
	var fn = document.getElementById("fn").value;
	var mn = document.getElementById("mn").value;
	var options = "scrollbars=yes,resizable=yes,width=640";
	window.open("./RoiIntrusion?fn="+fn+"&mn="+mn,"",options);
}

//Roi Surfing... page
function setFormatForSurfing(){
	//Set total cost on main page.
	window.opener.document.getElementById('totcost_indiscriminate_surfing').value =document.getElementById('tot_annualprod_loss').value; 
	//calculate when page load.
	calculateGrantTotal();
}
function openWindowIndiscriminateSurfing(){
	var fn = document.getElementById("fn").value;
	var mn = document.getElementById("mn").value;
	var options = "scrollbars=yes,resizable=yes,width=640";
	window.open("./RoiSurfing?fn="+fn+"&mn="+mn,"",options);
}

//Roi Virus... page
function setFormatForVirus(){
	//Set total cost on main page.
	window.opener.document.getElementById('totcost_antivirus').value =document.getElementById('tot_annualcost_comp_virus').value; 
	//calculate when page load.
	calculateGrantTotal();
}
function openWindowVirus(){
	var fn = document.getElementById("fn").value;
	var mn = document.getElementById("mn").value;
	var options = "scrollbars=yes,resizable=yes,width=640";
	window.open("./RoiVirus?fn="+fn+"&mn="+mn,"",options);
}

//Roi Spam... page
function setFormatForSpam(){
	//Set total cost on main page.
	window.opener.document.getElementById('totcost_spam').value =document.getElementById('tot_annualcost_comp').value; 
	//calculate when page load.
	calculateGrantTotal();
}
function openWindowSpam(){
	var fn = document.getElementById("fn").value;
	var mn = document.getElementById("mn").value;
	var options = "scrollbars=yes,resizable=yes,width=640";
	window.open("./RoiSpam?fn="+fn+"&mn="+mn,"",options);
}

//Roi Connectivity... page
function setFormatForConnectivity(){
//	document.getElementById('annual_cost_perRoadworrior').value=(parseFloat(document.getElementById('annual_cost_perRoadworrior').value));
//	document.getElementById('annual_remote_connectivity_cost1').value=(parseFloat(document.getElementById('annual_remote_connectivity_cost1').value));
//	document.getElementById('avg_cost_perHour').value=(parseFloat(document.getElementById('avg_cost_perHour').value));
//	document.getElementById('avg_cost_perMinute').value=(parseFloat(document.getElementById('avg_cost_perMinute').value));
//	
//	document.getElementById('avg_monthly_leaseLine_cost').value=(parseFloat(document.getElementById('avg_monthly_leaseLine_cost').value));
//	document.getElementById('annual_cost_ofLeaseLine').value=(parseFloat(document.getElementById('annual_cost_ofLeaseLine').value));
//	document.getElementById('annual_cost_branch_offices').value=(parseFloat(document.getElementById('annual_cost_branch_offices').value));
//	document.getElementById('annual_connectivity_cost_LAN').value=(parseFloat(document.getElementById('annual_connectivity_cost_LAN').value));
//	document.getElementById('annual_remote_connectivity_cost').value=(parseFloat(document.getElementById('annual_remote_connectivity_cost').value));
	//Set total cost on main page.
	window.opener.document.getElementById('totcost_connectivity').value = document.getElementById('annual_remote_connectivity_cost').value; 
	//calculate when page load.
	calculateGrantTotal();
}
function openWindowConnectivity(){
	var fn = document.getElementById("fn").value;
	var mn = document.getElementById("mn").value;
	var options = "scrollbars=yes,resizable=yes,width=640";
	window.open("./RoiConnectivity?fn="+fn+"&mn="+mn,"",options);
}
//***************

function setDialupConnection()
{	
	var combo = document.getElementById('dialup_connection');
 	var comboValue = combo.value;
 	
	if(comboValue == 'Yes'){					
		document.getElementById("user_connecting_roadwarriors").disabled =false;
    }
	else{	
		document.getElementById("user_connecting_roadwarriors").disabled =true;	
		document.getElementById("user_connecting_roadwarriors").value="0";	
	}
}
function setLeasedLine()
{
	var combo = document.getElementById('leased_line_connection');
	var comboValue = combo.value;						
	if(comboValue == 'Yes'){
		document.getElementById('no_of_branch_offices').disabled =false;
	}
	else{	
		document.getElementById('no_of_branch_offices').disabled =true;
		document.getElementById("no_of_branch_offices").value="0";
	}
}

//check for given text box holds the integer value or not.
//val indicate textbox and text is the name of text box.
function checkInt(textbox)
{	
	var val = trim(textbox.value); 
	if(isNaN(val))
	{
     	textbox.value='0';
     	textbox.focus();
	 	return false;
	}
	if(parseInt(val)<0){
     	textbox.value='0';
     	textbox.focus();
	 	return false;
	}
	if(val=='')
	{
	 	val='0';
	}
	if(parseInt(val)==0 ||
		(parseFloat(val)).toFixed(0)=='0'){
		val='0';
	}
	if(val==null){
		val='0';		
	}
	textbox.value=parseInt(val);
}
//check for given text box holds the float value or not.
//val indicate textbox and text is the name of text box.
function checkFloat(textbox)
{	
	var val = trim(textbox.value); 
	if(isNaN(val))
	{
     	textbox.value='0.0';
     	textbox.focus();
	 	return false;
	}
	if(parseFloat(val)<0.0){
     	textbox.value='0.0';
     	textbox.focus();
	 	return false;
	}
	if(val=='')
	{
	 	val='0.0';
	}
	if(parseFloat(val)=='0'){
		val='0.0';
	}
	if(val==null){
		val='0.0';		
	}
	textbox.value=val;
}

//Trim function:
function trim(str)
{
    if(!str || typeof str != 'string')
        return null;

    return str.replace(/^[\s]+/,'').replace(/[\s]+$/,'').replace(/[\s]{2,}/,' ');
}

//Roi ... Page
function calculateCalled(){
	document.getElementById('actionType').value="calculate";
	document.cyberoamsiteROI.submit();
}
function currencyChanged(){
	document.getElementById('actionType').value="currencyChanged";
	document.cyberoamsiteROI.submit();	
}
function hideROIDetails()
{
	document.getElementById('roiSpam').style.display='none';
	document.getElementById('roiVirus').style.display='none';
	document.getElementById('roiSurfing').style.display='none';
	document.getElementById('roiIntrusion').style.display='none';
	document.getElementById('roiLinkDowntime').style.display='none';
	document.getElementById('roiConnectivity').style.display='none'; 
}

function calculateGrantTotal(){
	var spam=parseFloat(window.opener.document.getElementById('totcost_spam').value);
	var virus=parseFloat(window.opener.document.getElementById('totcost_antivirus').value);
	var surfing=parseFloat(window.opener.document.getElementById('totcost_indiscriminate_surfing').value);		
	var intrusion=parseFloat(window.opener.document.getElementById('totcost_network_intrusion').value);
	var linkdown=parseFloat(window.opener.document.getElementById('totcost_internet_downtime').value);
	var connectivity=parseFloat(window.opener.document.getElementById('totcost_connectivity').value);
	window.opener.document.getElementById('total_cost_company').value=Math.round(spam+virus+surfing+intrusion+linkdown+connectivity);
	
	//calculation for Saving With Cyberoam
	var totalCostCompany =window.opener.document.getElementById("total_cost_company").value;
	var estimatedCostOfCyberoam = window.opener.document.getElementById("estimated_cost_ofCyberoam").value;
	var savingWithCyberoam1 = totalCostCompany - estimatedCostOfCyberoam;
	savingWithCyberoam = Math.round(savingWithCyberoam1 * 100)/100;
	window.opener.document.getElementById('saving_with_cyberoam').value = savingWithCyberoam;
	
	//calculation for Time to recoup investment
	var timeToRecoupInvestment = parseInt((estimatedCostOfCyberoam / (savingWithCyberoam1 / 365)));
	window.opener.document.getElementById('time_toRecoup_investment').value = timeToRecoupInvestment;
}