function ShowTermsConditions(){
    
    window.open('http://www.loanraja.com/jsp/global/landing_terms.jsp','Conditions','menubar=no,scrollbars=yes,width=600,height=600,directories=no,location=0,resizable=0,status=no,toolbar=no');
    
}

function ShowPrivacy(){

    window.open('http://www.loanraja.com/jsp/global/landing_privacy.jsp','Privacy','menubar=no,scrollbars=yes,width=600,height=600,directories=no,location=0,resizable=0,status=no,toolbar=no');
}
function $(id) { return document.getElementById(id); }   

function isEmpty(elem, helperMsg){
    if(elem.value.length == 0){
        alert(helperMsg);
        elem.focus(); // set the focus to this input
        return true;
    }
    return false;
}

function validateDOB(field_dd, field_mm, field_yy){
    var dd = document.getElementById(field_dd);
    var mm = document.getElementById(field_mm);
    var yy = document.getElementById(field_yy);
    if (dd.value == ""){
        alert("Please select Date in Date of Birth");
        dd.focus();
        return false;
    }else if (mm.value == ""){
        alert("Please select Month in Date of Birth");
        mm.focus();
        return false;
    }else if (yy.value == ""){
        alert("Please select Year in Date of Birth");
        yy.focus();
        return false;
    }
    var incorrectDate = 0;
    if (mm.value == 1){//feb
        if (dd.value>29){
            incorrectDate = 1;
        }else if (dd.value==29 && yy.value%4!=0){
            incorrectDate = 1;
        }
    }
    if (mm.value==3 || mm.value==5 || mm.value==8 || mm.value==10){
        if (dd.value>30) incorrectDate = 1;
    }
    if (incorrectDate==1){
        alert("Please enter a valid Date value in Date of Birth");
        dd.focus();
        return false;
    }
    return true;
}

//we always truncate here
function calcAgeFromDOB(dd, mm, yy, curr_dd, curr_mm, curr_yy, field_age){
    var age = curr_yy - yy;
    if (curr_mm<mm){
        age = age - 1;
    }else if (curr_mm==mm){
        if (curr_dd<dd) age = age - 1;
    }
    document.getElementById(field_age).value = age;
}

function validateField(fieldname,fieldtype,regx,isMandate,displayname){
   //alert('displayname:'+displayname+'regx:'+regx+'isMandate:'+isMandate);
   var f=document.getElementById(fieldname);
   var ftype=document.getElementById(fieldname).type;
   
   // alert(f.value);
   switch (ftype){
        case 'text':
            f.value=f.value.replace(/^\s+|\s+$/g, '');
            if (isMandate!="false"){
                if (f.value ==""){
                    alert(displayname +' is mandatory');
                    f.focus();
                    return false;
                }else if(regx!=""){
                  // alert(f.value);
                   if(f.value.match(eval(regx))){
                       return true;
                   }else{
                       alert('Please enter proper value for '+displayname);
                       f.focus();
                       return false;
                   }
                 }
            }else{
                if (f.value !=""){
                    if(regx!=""){
                       if(f.value.match(eval(regx))){
                           return true;
                       }else{
                          alert('Please enter proper value for '+displayname);
                          f.focus();
                          return false;
                       }
                    }
                    return true;
                }
                return true;
            }
            break;
        case 'textarea':
                    f.value=f.value.replace(/^\s+|\s+$/g, '');
                    if (isMandate!="false"){
		                if (f.value ==""){
		                    alert(displayname +' is mandatory');
		                    f.focus();
		                    return false;
		                }else if(regx!=""){
		                  // alert(f.value);
		                   if(f.value.match(eval(regx))){
		                       return true;
		                   }else{
		                       alert('Please enter proper value for '+displayname);
		                       f.focus();
		                       return false;
		                   }
		                 }
		            }else{
		                if (f.value !=""){
		                    if(regx!=""){
		                       if(f.value.match(eval(regx))){
		                           return true;
		                       }else{
		                          alert('Please enter proper value for '+displayname);
		                          f.focus();
		                          return false;
		                       }
		                    }
                            return true;
                        }
                        return true;
                }
                break;
        case 'checkbox':
            break;
        case 'select-one':
             if (isMandate!="false"){
                if (f.value ==""){
                    alert('Please select '+displayname);
                    f.focus();
                    return false;
                }else if(f.value=="others"){
                    //$('txtOthers').
                }
            }else{
                return true;
            }           
            break;
   }
   return true;
}

function reconfirmMobile(divVerify,mobile){
    var appMsg=null;
    if(validateMobile(mobile)){
      //  alert($(mobile).value);
      //  $('loading').style.display='';
        var url=rootdomain+"/reconfirmmobile?cmobile="+$(mobile).value;
        httpRequest("POST",url,true,reConfirmationDone);
    }
}

function setDivStyle(divId){
    var divVerify=$(divId);
    if(divVerify){
         var x  =  document.body.scrollLeft;  
         var y  =  document.body.scrollTop; 
         divVerify.style.height=document.body.clientHeight+'px';
         divVerify.style.width=document.body.clientWidth+'px';
         divVerify.style.left=x+'px';
         divVerify.style.top= y+'px';
         divVerify.style.position='absolute';
      //   var innerwidth=(parseInt(document.body.clientWidth)/2);
         var innerWidth=parseInt(document.body.clientWidth)/2;
         $('innerVerifyAgain').style.width=innerWidth+'px';
    }
}

function get_radio_value(){
    for (var i=0; i < document.diffProduct.alsoApp.length; i++){
       if (document.diffProduct.alsoApp[i].checked){
          var rad_val = document.diffProduct.alsoApp[i].value;
          return rad_val;
       } 
    }
    return 0;
}
function populateDiffFields(){
    
    var selectedProduct=null;
    var btnRadio=$('alsoApp');
    var url=null; 
    //var frm=document.forms[0];

     selectedProduct=get_radio_value();
    // alert(selectedProduct);
     productId = selectedProduct;
     if (productId==0){
         var showalert = true;
         if (!btnRadio.length && btnRadio.checked){
             showalert = false;
             productId = btnRadio.value;
         }
         if (showalert){
             alert("Please select the product you want to apply for");
             return;
         }
     }
    // alert('selected product:'+productId);
     
    $('productId').value=productId;
    if(parseInt(productId)>0 ){
        url=rootdomain+"/getDiffFields?alsoApp="+productId;
    //  alert(url);
        httpRequest("GET",url,true,ShowFields);
    }
    else{
        alert("Invalid product selected");
    } 
}



   
function sendSMS(productId,cell){
    mobile=$(cell).value;
    var url=rootdomain+"/sendsms?productId="+productId+"&mobile="+mobile;
   // url='http://localhost:8080/LoanrajaWeb/sendsms?productId=1&mobile=9833557828';
   // alert(url);
   if ($('verify_off') && $('verify_on')){
	   $('verify_off').style.display='';
	   $('verify_on').style.display='none';
   }
    if(eval(productId)!=null){
        if (validateMobile(cell)){
         //   alert('moblie validated');
            httpRequest("POST",url,true,handleResponse);
        }
    }
}

function validateMobile(mobile)
{
    var mobno=$(mobile).value;
   if(mobno !=""){
        if (mobno.length==10){
        
            if (isNumeric($(mobile),"Mobile number should be numeric")){
                if (mobno.indexOf('9',0)==0){
                  //  $('MobileBoxText').style.visibility='hidden';
                            return true;
                }else{
                    alert('Please enter correct mobile number');
                    $(mobile).focus();
                    return false;
                }
            }else{
                return false;
            }
        }else{
            alert('Please enter 10 digit mobile number');
            return false;
        }
    }else{
        alert('Mobile is mandatory');
        $(mobile).focus();
        return false;
    }
}

function isNumeric(elem, helperMsg){
    var numericExpression = /^[0-9\.]+$/;
    if(elem.value.match(numericExpression)){
        return true;
    }else{
     //   alert(helperMsg);
        elem.focus();
        return false;
    }
}

function calculate(){
    
    var pAmt=$('pamt').value;
    var lTenure=$('tenure').value;
    var rate=$('rate').value;
    //if(pAmt.match(/^[0-9.]+$)){
     //  if(rate.match(/^[0-9.{5}]+\.[0-9]{2}   [0-9]*\.?[0-9]{2}+ //floating point number with 2 digits
    if(pAmt.value!="" && lTenure!="" && rate!=""){
       if(isNumeric($('pamt'),'') && isNumeric($('tenure'),'') && isNumeric($('rate'),'')){
         //  if(rate.match(eval('[0-9]{2}*\.?[0-9]{2}+')) && pAmt.match(eval('[0-9]*\.?[0-9]{2}+')) && lTenure.match(eval('/^[0-9]{2}+$'))){
           var url=rootdomain +"/calculateemi?principalAmt="+pAmt+"&interestRate="+rate+"&tenure="+lTenure;
           httpRequest("POST",url,true,ShowEMIResult);
       }else{
           $('emiResult').style.display='';
           $('emiResult').innerHTML="Values should be numeric";
       }
    }else{
       $('emiResult').style.display=''; 
       $('emiResult').innerHTML="you entered some wrong input";
    }
}

function validateHomePage(){
    if($('productId').value!=""){
        if($('f.4').value!=""){
            if(validateMobile('f.5')){
                $('errorMsg').style.display='none';
                $('errorMsg').innerHTML='';
                document.basicInfoFrm.submit();
               
              //  return true;
            }else{
               $('errorMsg').style.display='';
               $('errorMsg').innerHTML='Please enter mobile number';
             //   return false;
            }
        }else{
                $('errorMsg').style.display='';
                $('errorMsg').innerHTML='Please select your location';
              //  return false;
            }
    }else{
         $('errorMsg').style.display='';
         $('errorMsg').innerHTML='Please select product';
       //  return false;
    }
}

function sendBulkMails(){
   
 if($('friendlist').value!=""){
    var url=rootdomain+"/referFriend?friendlist="+$('friendlist').value.replace('\n', '%0A');
    httpRequest("POST",url,true,mailSent);
    }else{
        $('mailResponse').innerHTML='Please enter email addresses of your friends';
        $('mailResponse').style.display='';
    }    
}

function showMainPageReconfirm(frm){
        showhideDropDowns(frm,'true');
        $('MainPageReconfirm').style.display='';
        setDivStyle('MainPageReconfirm');
}

function showhideDropDowns(frm,flag){
    var ftype;
    if(flag=='true'){
        for (var i=0;i<frm.elements.length;i++){
            ftype=frm.elements[i].type;
            if(ftype=='select-one'){
                frm.elements[i].style.display='none';
        }
       }
    }else{
        for (var i=0;i<frm.elements.length;i++){
            ftype=frm.elements[i].type;
            if(ftype=='select-one'){
                frm.elements[i].style.display='';
            }
       }
       $('MainPageReconfirm').style.display='none';
       $('smscode').focus();
    }
}

function showTermsWarning(){
        var divId=  document.createElement('DIV');
        divId.Id='Reconfirm';
        divId.Name='termsWarning';
        divId.style.display='';
        $('content').appendChild(divId);
    
    divId.Class='ErrorMsg';
    divId.innerHTML='Please accept our terms & conditions policy';
    divId.align='center';
    
}
            






