function calculateCheck(){
     var totalDIY = document.getElementById('totalDIY').innerHTML;
     if (trimAll(totalDIY) === ''){
         $("#formbox .invalidCalculate").text("You haven't calculated anything.");
         isValid = false;
     }else
         $("#formbox .invalidCalculate").text("");
}

function sendPageToColleague(form){
    var toEmail = form.TOEMAIL.value;
    var fromEmail = form.FROMEMAIL.value;
    var firstName = form.NAME.value;
    var subject = "Your egnyte cloud solution quote";
    var personalMessage = form.MESSAGE.value;
    var comp = form.COMPANY.value;


    //email's inhouse server content
    var employeeDIY = document.getElementById('DIY_EmployeeVal').innerHTML;
    var computerDIY = document.getElementById('computerDIY').innerHTML;
    var cpuDIY = document.getElementById('cpuDIY').innerHTML;
    var hdwrDIY = document.getElementById('hdwrDIY').innerHTML;
    var osDIY = document.getElementById('osDIY').innerHTML;
    var backupDIY = document.getElementById('backupDIY').innerHTML;
    var sw1DIY = document.getElementById('sw1DIY').innerHTML;
    var upsDIY = document.getElementById('upsDIY').innerHTML;
    var costDIY = document.getElementById('costDIY').innerHTML;
    var firewallDIY = document.getElementById('firewallDIY').innerHTML;
    var firewallCostDIY = document.getElementById('firewallCostDIY').innerHTML;
    var hrlyRateDIY = document.getElementById('hrlyRateDIY').innerHTML;
    var hrsDIY = document.getElementById('hrsDIY').innerHTML;
    var totalDIY = document.getElementById('totalDIY').innerHTML;

    //email's egnyte server content
    var employeeCTE = document.getElementById('CTE_EmployeeVal').innerHTML;
    var powerCTE = document.getElementById('power').innerHTML;
    var standardCTE = document.getElementById('standard').innerHTML;
    var storageCTE = document.getElementById('storage').innerHTML;
    var backupCTE = document.getElementById('autoBackup').innerHTML;
    var costCTE = document.getElementById('totalCTE').innerHTML;

    var totalSave = document.getElementById('totalSavings').innerHTML;
    
 //   var webpage = document.getElementById('printDiv').innerHTML;
    var CONTACT_US_ERROR_MSG = "TO Emails cannot be blank.";
    var INVALID_EMAIL_ADDRESS = "Invalid email address.";
    var isValid = true;

    if (trimAll(comp) === ''){
        $("#formbox .invalidCompany").text("Required");
        isValid = false;
    }else
        $("#formbox .invalidCompany").text("");

    if (trimAll(firstName) === ''){
        $("#formbox .invalidName").text("Required");
        isValid = false;
    }else
        $("#formbox .invalidName").text("");

    if (trimAll(toEmail) === ''){
        $("#formbox .invalidToEmail").text("Required");
        isValid = false;
    }else if(false === validateEmail(toEmail)){
        $("#formbox .invalidToEmail").text("invalid");
        isValid = false;
    }else
        $("#formbox .invalidToEmail").text("");

    if (trimAll(fromEmail) === ''){
        $("#formbox .invalidFromEmail").text("Required");
        isValid = false;
    }else if(false === validateEmail(fromEmail)){
        $("#formbox .invalidFromEmail").text("invalid");
        isValid = false;
    }else
        $("#formbox .invalidFromEmail").text("");

    if(isValid === false)
        return false;

    
    if(trimAll(subject) === ""){
        subject='';
    }
    
    if(subject === ""){
            subject='  ';
    }
    egnyteUtils.loadScript("/wsgi/send_to_colleague?firstName=" + egnyteUtils.URLencode(firstName) 
	+ "&toAddy=" + toEmail + "&comp=" + comp
	+ "&subject=" + egnyteUtils.URLencode(subject) + "&message=" + personalMessage 
    + "&employeeDIY="+employeeDIY + "&computerDIY="+computerDIY +"&cpuDIY="+cpuDIY +"&hdwrDIY="+hdwrDIY
    + "&osDIY="+osDIY + "&backupDIY="+backupDIY + "&sw1DIY="+sw1DIY + "&upsDIY="+upsDIY
    + "&costDIY="+costDIY + "&firewallDIY="+firewallDIY + "&firewallCostDIY=" + firewallCostDIY
    + "&hrlyRateDIY="+hrlyRateDIY + "&hrsDIY="+hrsDIY + "&totalDIY="+totalDIY 
    + "&employeeCTE="+employeeCTE +"&powerCTE="+powerCTE+"&standardCTE="+standardCTE
    + "&storageCTE="+storageCTE + "&backupCTE="+backupCTE + "&costCTE="+costCTE
    + "&totalSave="+totalSave
	, "typeof(contactUsResponse) != 'undefined'");

        $("#formbox .title").css("display","none");
        $("#formbox .inner-form").css("display","none");
        $("#formbox .invalidCalculate").text("");
        $("#formbox .emailMsg").text("Your message has been sent. Thank you for using Egnyte!");

    return false;
}
// Functions to handle send request quote
function sendRequestQuote(form) {

	var telephone = form.TELEPHONE.value;
    var fromEmail = form.FROMEMAIL.value;
    var firstName = form.NAME.value;
    var personalMessage = form.MESSAGE.value;
    var comp = form.COMPANY.value;
    var noOfUsers = form.some10.value;
    var storage = form.some11.value;
	
	var isValid = true;

    if ($.trim(comp) === ''){
        $("#quote_formwindow .invalidCompany").text("Required");
        isValid = false;
    }else
        $("#quote_formwindow .invalidCompany").text("");

    if ($.trim(firstName) === ''){
        $("#quote_formwindow .invalidName").text("Required");
        isValid = false;
    }else {
        $("#quote_formwindow .invalidName").text("");
	}
	
	if ( $.trim(telephone) === '' ) {
        $("#quote_formwindow .invalidToEmail").text("Required");
        isValid = false;
    }
    else
        $("#quote_formwindow .invalidToEmail").text("");

    if ($.trim(fromEmail) === ''){
        $("#quote_formwindow .invalidFromEmail").text("Required");
        isValid = false;
    }else if(false === validateEmail(fromEmail)){
        $("#quote_formwindow .invalidFromEmail").text("Invalid");
        isValid = false;
    }else
        $("#quote_formwindow .invalidFromEmail").text("");

    if(isValid === false)
        return false;

    var url = "/wsgi/request_quote?firstName=" + firstName
	+ "&email=" + fromEmail + "&comp=" + comp + "&message=" + personalMessage 
	+ "&telephone=" + telephone  + "&noOfUsers=" + noOfUsers   + "&storage=" + storage   
    
    $.get(url, function(status){
    	calbckQuote(status);
    });
    return false;
}
function calbckQuote(status) {
	if(status == "true"){
		$("#formRequestDiv").css("display","none");
	    $("#quote_formwindow .invalidCalculate").text("");
   		$("#successRequestDiv").css("display","");
	}
	else {
		$('.invalidCalculate').text('An error has occured. Please contact support.');
	}
}
function closeRequestQuote()
{
	$("#successRequestDiv").css("display","none");
	$("#formRequestDiv").css("display","");
	$.fn.colorbox.close();
}

function validateEmail (emailStr) {
/* The following pattern is used to check if the entered e-mail address
   fits the user@domain format.  It also is used to separate the username
   from the domain. */
var emailPat=/^(.+)@(.+)$/;
/* The following string represents the pattern for matching all special
   characters.  We don't want to allow special characters in the address. 
   These characters include ( ) < @ , ; : \ " . [ ]    */
var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]";
/* The following string represents the range of characters allowed in a 
   username or domainname.  It really states which chars aren't allowed. */
var validChars="\[^\\s" + specialChars + "\]";
/* The following pattern applies if the "user" is a quoted string (in
   which case, there are no rules about which characters are allowed
   and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
   is a legal e-mail address. */
var quotedUser="(\"[^\"]*\")";
/* The following pattern applies for domains that are IP addresses,
   rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
   e-mail address. NOTE: The square brackets are required. */
var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
/* The following string represents an atom (basically a series of
   non-special characters.) */
var atom=validChars + '+';
/* The following string represents one word in the typical username.
   For example, in john.doe@somewhere.com, john and doe are words.
   Basically, a word is either an atom or quoted string. */
var word="(" + atom + "|" + quotedUser + ")";
// The following pattern describes the structure of the user
var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
/* The following pattern describes the structure of a normal symbolic
   domain, as opposed to ipDomainPat, shown above. */
var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");


/* Finally, let's start trying to figure out if the supplied address is
   valid. */

/* Begin with the coarse pattern to simply break up user@domain into
   different pieces that are easy to analyze. */
var matchArray=emailStr.match(emailPat);
if (!matchArray) {
  /* Too many/few @'s or something; basically, this address doesn't
     even fit the general mould of a valid e-mail address. */
    //alert("Email address seems incorrect (check @ and .'s)")
    return false;
}
var user=matchArray[1];
var domain=matchArray[2];

// See if "user" is valid 
if (!user.match(userPat)) {
    // user is not valid
    //alert("The part of your email address before the '@' doesn't seem to be valid.")
    return false;
}

/* if the e-mail address is at an IP address (as opposed to a symbolic
   host name) make sure the IP address is valid. */
var IPArray=domain.match(ipDomainPat);
if (IPArray) {
    // this is an IP address
      for (var i=1;i<=4;i++) {
        if (IPArray[i]>255) {
           // alert("Destination IP address is invalid!")
        return false;
        }
    }
    return true;
}

// Domain is symbolic name
var domainArray=domain.match(domainPat);
if (!domainArray) {
  //  alert("Part of your email address after the '@' doesn't seem to be valid")
    return false;
}

/* domain name seems valid, but now make sure that it ends in a
   three-letter word (like com, edu, gov) or a two-letter word,
   representing country (uk, nl), and that there's a hostname preceding 
   the domain or country. */

/* Now we need to break up the domain to get a count of how many atoms
   it consists of. */
var atomPat=new RegExp(atom,"g");
var domArr=domain.match(atomPat);
var len=domArr.length;
if (domArr[domArr.length-1].length<2 || 
    domArr[domArr.length-1].length>6) {
   // the address must end in a two letter or other TLD including museum
  // alert("The address must end in a top level domain (e.g. .com), or two letter country.")
   return false;
}

// Make sure there's a host name preceding the domain.
if (len<2) {
   var errStr="This address is missing a hostname!";
  // alert(errStr)
   return false;
}

    // If we've got this far, everything's valid!
    return true;
}

function sendCustomPlanRequest(requestType) {

	var telephone = $('#txtPhone').val();
    var fromEmail = $('#txtEmail').val();
    var fullName = $('#txtFirstName').val() + ' ' + $('#txtLastName').val();
    var personalMessage = $('#MESSAGE').val();
    var company = $('#txtCompanyName').val();
    
    var noOfUsers = 0, storage = 0;
 	var totalStorageAmt = 0, totalStorageUnit = STORAGE_UNIT.TB;
 	   
    CorporatePricing.setPlanDetails();		//	gets/set the corporate pricing plan. we need it for base (free) storage amt.      
    
    var corporateAccountInfoObj = getCorpDetailsFromCookie();
	if(corporateAccountInfoObj != null){
		var storageObj = getTotalStorage(corporateAccountInfoObj);
		noOfUsers = corporateAccountInfoObj.powerUsers;
		storage = storageObj.value + ' ' + storageObj.unit;
	}
       
    var url = "/wsgi/request_quote?firstName=" + fullName
	+ "&email=" + fromEmail + "&comp=" + company + "&message=" + personalMessage 
	+ "&telephone=" + telephone  + "&noOfUsers=" + noOfUsers   + "&storage=" + storage   
    
    $('div.continueButtonCls').hide();
    
    $.get(url, function(status){
    	if(status){
    		if(requestType == CORP_PLAN_REQUEST_TYPE.ACTIVATE_FREE_TRIAL){
    			window.location.href = 'corporate-plan-free-trial-activation-thankyou.html';
    		}
			else if(requestType == CORP_PLAN_REQUEST_TYPE.REQUEST_CUSTOM_QUOTE){
    			window.location.href = 'corporate-plan-price-quote-request-thankyou.html';
    		}
    	}
    	else{
    		$('div.continueButtonCls').show();
    	}
    });
    return false;
}

