﻿$(document).ready(function(){
                                      
    //When you click on a link with class of poplight and the href starts with a # 
    $('a.poplight').click(function() {
        var popID = $(this).attr('rel'); //Get Popup Name
        var popURL = $(this).attr('href'); //Get Popup href to define size
       
        //Pull Query & Variables from href URL
        var query= popURL.split('*');
        //var dim= query[1].split('&');
        var siteURL = query[1].split('>')[1]; //Gets the first query string value
        if ((siteURL == "")|| (siteURL == undefined)){
            siteURL = query[1].split('%3E')[1];
        }

        //Fade in the Popup and add close button
        $('#' + popID).fadeIn();
        //.css({ 'width': Number( '376' ) }).prepend('<a href="#" class="close"><img src="close_pop.png" class="btn_close" title="Close Window" alt="Close" /></a>')
        
        //Define margin for center alignment (vertical + horizontal) - we add 80 to the height/width to accomodate for the padding + border width defined in the css
        var popMargTop = ($('#' + popID).height() + 80) / 2;
        var popMargLeft = ($('#' + popID).width() + 40) / 2;
        
        //Apply Margin to Popup
        $('#' + popID).css({ 
            'margin-top' : -popMargTop,
            'margin-left' : -popMargLeft
        });
        
        //Fade in Background
        $('body').append('<div id="fade"></div>'); //Add the fade layer to bottom of the body tag.
        $('#fade').css({'filter' : 'alpha(opacity=60)'}).fadeIn(); //Fade in the fade layer 
        $('#wLink').attr('href',siteURL);
        $('#wLink1').attr('href',siteURL);

        $('#close').attr('href','#');
        return false;
    });
    
    
    //Close Popups and Fade Layer
    $('a#close, #fade').live('click', function() { //When clicking on the close or fade layer...
          $('#fade , .popup_block').fadeOut(function() {
            $('#fade').remove();  
    }); //fade them both out
        
        return false;
    });


    setTimeout(function() {                
                // Accordion
                $('#menu1 > div > a.collapsed + div + div').slideToggle('medium');
                $('#menu1 > div > a').click(function() {
                    $('#menu1 > div > a.expanded').not(this).toggleClass('expanded').toggleClass('collapsed').parent().find('> div').slideToggle('medium');                    
                    $(this).toggleClass('expanded').toggleClass('collapsed').parent().find('> div').slideToggle('medium');
                });
            }, 250);

     setTimeout(function() {                
                // Accordion
                $('#menu2 > div > a.collapsed + div').slideToggle('medium');
                $('#menu2 > div > a').click(function() {
                    $('#menu2 > div > a.expanded').not(this).toggleClass('expanded').toggleClass('collapsed').parent().find('> div').slideToggle('medium');                    
                    $(this).toggleClass('expanded').toggleClass('collapsed').parent().find('> div').slideToggle('medium');
                });
            }, 250);
});


/* Redirect to English */

function redirectToEnglish(element,pageURL)
{
    var URL = pageURL.replace("/sp/", "");
    element.href= "/" + URL;
}

/*function redirectToSpanish(element,pageURL)
{   
    var URL;
    URL = pageURL.replace("/new/", "/new/sp/");
    element.href= URL;
}*/

 
function DisplayChks(){
  if(document.getElementById('servicoRad') != null){
    if(document.getElementById('servicoRad').checked)
    {
        document.getElementById('servicioChks').style.display="";
        document.getElementById('ventasChks').style.display="none";
        
    }
    else{
    //alert(document.getElementById('servicioChks').style.display);
        document.getElementById('ventasChks').style.display="";
        document.getElementById('servicioChks').style.display="none";
        }
    }    
}
 
function init() {
     if(document.getElementById("captchaImage") != null){
         var rand_no = Math.random();                             
         document.getElementById("captchaImage").src="/oriental/validateCaptcha?rdmNo="+rand_no;     
    }
}
 
function isNumberKey(evt)
      {
         var charCode = (evt.which) ? evt.which : event.keyCode
         if (charCode > 31 && (charCode < 48 || charCode > 57))
            return false;
         return true;
      }

function genImage(){
    if(document.getElementById("captchaImage") != null){
        var rand_no = Math.random();
        document.getElementById("captchaImage").src="/oriental/validateCaptcha?rdmNo="+rand_no;
        document.getElementById("captchaText").focus();
    }
}
 

function PhoneValidation(phonenum)
{
   var sText = phonenum;
    var ValidChars = "0123456789-";
   var IsNumber=true;
   var Char;
 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
       }
      }
   return IsNumber;  
   }

function checkNumber(num){
var regex = /^[0-9]*$/;
var isnum = true;
 if (!(regex.test(num))) {
   isnum = false;
 } 
return isnum;
}
function checkEmailFormat(email)
{
var emailPattern =/^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$/; 
var isEmail = true;
    if(email!=""){
        if(!(email.match(emailPattern)))
        {
          isEmail= false;
        }
    }
return isEmail;
}

function dobFocus(){
    if (document.getElementById("dob").value == "MM/DD/YYYY"){
        document.getElementById("dob").value="";
        document.getElementById("dob").style.color= '#000000'; 
    }
    return false;
}

function dobBlur(){
    if (document.getElementById("dob").value == ""){
        document.getElementById("dob").value="MM/DD/YYYY";
        document.getElementById("dob").style.color= '#909090'; 
    }else if (document.getElementById("dob").value != ""){
           var re = /^(\d{1,2})\/(\d{1,2})\/(\d{4})$/;
            if(regs = document.getElementById("dob").value.match(re)) { 
            // month value between 1 and 12 
            if(regs[1] < 1 || regs[1] > 12) { 
                document.getElementById("dob").focus();
                alert("Invalid value for month: " + regs[1]); 
            } 
            // day value between 1 and 31 
            if(regs[2] < 1 || regs[2] > 31) { 
                document.getElementById("dob").focus();
                alert("Invalid value for day: " + regs[2]); 
            } 
            // year value between 1902 and 2011 
            if(regs[3] < 1902 || regs[3] > (new Date()).getFullYear()) { 
                document.getElementById("dob").focus();
                alert("Invalid value for year: " + regs[3] + " - must be between 1902 and " + (new Date()).getFullYear()); 
            } 
            }else{                
                alert("Please enter the valid Date of birth");    
                document.getElementById("dob").value=""
                document.getElementById("dob").focus();
            }           
       }
       return false;
}

function dobBlurSP(){
    if (document.getElementById("dob").value == ""){
        document.getElementById("dob").value="MM/DD/YYYY";
        document.getElementById("dob").style.color= '#909090'; 
    }else if (document.getElementById("dob").value != ""){
           var re = /^(\d{1,2})\/(\d{1,2})\/(\d{4})$/;
            if(regs = document.getElementById("dob").value.match(re)) { 
            // month value between 1 and 12 
            if(regs[1] < 1 || regs[1] > 12) { 
                alert("Valor no válido para el mes: " + regs[1]); 
                document.getElementById("dob").focus();
            } 
            // day value between 1 and 31 
            if(regs[2] < 1 || regs[2] > 31) { 
                alert("Valor no válido para el día: " + regs[2]); 
                document.getElementById("dob").focus();
            } 
            // year value between 1902 and 2011 
            if(regs[3] < 1902 || regs[3] > (new Date()).getFullYear()) { 
                alert("Valor no válido para el año: " + regs[3] + " - Debe estar entre 1902 y" + (new Date()).getFullYear()); 
                document.getElementById("dob").focus();
            } 
            }else{    
                alert("Por favor, introduzca la fecha de nacimiento válido");
                document.getElementById("dob").value="";                
                document.getElementById("dob").focus();
            }    
  }

}

/* CONSULTATION FORM (BOTH SPA AND ENG) STARTS */

function validateconsultation(form)
{
var myDays = -1;
for (j=form.availablity.length-1; j > -1; j--) {
if (form.availablity[j].checked) {
myDays = j; j = -1;
}
}

       if (document.getElementById("name").value==""){
        alert("Please enter Name field");
        document.getElementById("name").focus();
        return false;
       } else if (document.getElementById("paternalLastName").value==""){
        alert("Please enter Paternal Last Name");
        document.getElementById("paternalLastName").focus(); 
        return false;
       } else if (document.getElementById("maternalLastName").value==""){
        alert("Please enter Maternal Last Name");
        document.getElementById("maternalLastName").focus(); 
        return false;
       } else if (document.getElementById("address1").value==""){
        alert("Please enter the address1");
        document.getElementById("address1").focus(); 
        return false;
       } else if (document.getElementById("address2").value==""){
        alert("Please enter the address2");
        document.getElementById("address2").focus(); 
        return false;
       } else if (document.getElementById("city").value==""){
        alert("Please enter the city");
        document.getElementById("city").focus(); 
        return false;
       } else if (document.getElementById("zipcode").value==""){
        alert("Please enter the zip code");
        document.getElementById("zipcode").focus(); 
        return false;
       } else if(document.getElementById("email").value==""){
        alert("Please enter your Email Address");
        document.getElementById("email").value="";
        document.getElementById("email").focus();
        return false;
       } else if(!checkEmailFormat(document.getElementById("email").value)){
        alert("Please enter a valid email ID");
        document.getElementById("email").value="";
        document.getElementById("email").focus();
        return false;
       } else if((document.getElementById("dob").value=="") || (document.getElementById("dob").value=="MM/DD/YYYY")){
         alert("Please enter Date of birth Field");
         document.getElementById("dob").value="";
         document.getElementById("dob").focus();
         return false;
       } else if (!PhoneValidation(document.getElementById("telephone1").value)){
       alert("Please enter your Phone");
       document.getElementById("telephone1").value=""
       document.getElementById("telephone1").focus();
       return false;
      } else if (myDays == -1) {
        alert("Please select the available days");
        return false;
      } else if(document.getElementById("learnMode").value == ""){
        alert("Please select how you heard about our website?");
        document.getElementById("learnMode").focus();
        return false;       
      } else if(document.getElementById("captchaText").value == ""){
        alert("Please enter the text you see in the image");
        document.getElementById("captchaText").focus();
        return false;       
      } else
       {
        validateCaptchaImageContactUs(form.id);
        return false;       
       }
}

function validateconsultationSP(form)
{
var myDays = -1;
for (j=form.availablity.length-1; j > -1; j--) {
if (form.availablity[j].checked) {
myDays = j; j = -1;
}
}
      if (document.getElementById("name").value==""){
        alert("Por favor, introduzca campo Nombre");
        document.getElementById("name").focus(); 
       return false;
       } else if (document.getElementById("paternalLastName").value==""){
        alert("Por favor, introduzca apellido paterno");
        document.getElementById("paternalLastName").focus(); 
        return false;
       } else if (document.getElementById("maternalLastName").value==""){
        alert("Por favor, introduzca apellido materno");
        document.getElementById("maternalLastName").focus(); 
        return false;
       } else if (document.getElementById("address1").value==""){
        alert("Por favor, introduzca la dirección1");
        document.getElementById("address1").focus(); 
        return false;
       } else if (document.getElementById("address2").value==""){
        alert("Por favor, introduzca la dirección2");
        document.getElementById("address2").focus(); 
        return false;
       } else if (document.getElementById("city").value==""){
        alert("Por favor, introduzca la ciudad");
        document.getElementById("city").focus(); 
        return false;
       } else if (document.getElementById("zipcode").value==""){
        alert("Por favor introduce el código postal");
        document.getElementById("zipcode").focus(); 
        return false;
       } else if(document.getElementById("email").value==""){
        alert("Por favor, escriba su Correo Electrónico");
        document.getElementById("email").value="";
        document.getElementById("email").focus();
        return false;
       } else if(!checkEmailFormat(document.getElementById("email").value)){
        alert("Por favor, escriba su Correo Electrónico válida");
        document.getElementById("email").value="";
        document.getElementById("email").focus();
        return false;
       } else if((document.getElementById("dob").value=="") || (document.getElementById("dob").value=="MM/DD/YYYY")){
         alert("Por favor, introduzca la fecha de nacimiento de campo");
         document.getElementById("dob").value="";
         document.getElementById("dob").focus();
         return false;
       } else if (!PhoneValidation(document.getElementById("telephone1").value)){
       alert("Por favor,  escriba su Teléfono");
       document.getElementById("telephone1").value=""
       document.getElementById("telephone1").focus();
       return false;
      } else if (myDays == -1) {
        alert("Por favor, seleccione la disponibilidad");
        return false;
       } else if(document.getElementById("learnMode").value == ""){
        alert("Por favor, seleccione ¿Cómo se enteró acerca de nuestro sitio web?");
        document.getElementById("learnMode").focus();
        return false;       
      } else if(document.getElementById("captchaText").value == ""){
        alert("Por favor, escriba el texto que ve en la imagen");
        document.getElementById("captchaText").focus();
        return false;       
      } else
       {
        validateCaptchaImageContactUs(form.id);
        return false;       
        }
}
 
/* CONSULTATION FORM (BOTH SPA AND ENG) ENDS*/

/* CONTACT US FORM (BOTH SPA AND ENG) STARTS*/

function validatecontactus(form)
{
       if (document.getElementById("name").value==""){
        alert("Please enter Name field");
        document.getElementById("name").focus();
       return false;
       }
        else if((document.getElementById("telephone1").value=="") || (!PhoneValidation(document.getElementById("telephone1").value))){
        alert("Please enter valid Telephone field");
        document.getElementById("telephone1").value="";
        document.getElementById("telephone1").focus();
        return false;
       }
         else if(!checkNumber(document.getElementById("employeeNumber").value)){
           alert("Please enter number for Number of Employees Field");
           document.getElementById("employeeNumber").value="";
           document.getElementById("employeeNumber").focus();
           return false;
       }
         else if(!checkEmailFormat(document.getElementById("email").value)){
           alert("Please enter a valid email ID");
           document.getElementById("email").value="";
           document.getElementById("email").focus();
          return false;
       }
       else if(document.getElementById("captchaText").value == ""){
        alert("Please enter the text you see in the image");
        document.getElementById("captchaText").focus();
        return false;       
      }
       else
       {
        validateCaptchaImageContactUs(form.id);
        return false;       
       }
}

function validatecontactusSP(form)
{
      if (document.getElementById("name").value==""){
        alert("Por favor, introduzca campo Nombre");
        document.getElementById("name").focus(); 
       return false;
       }
       else if((document.getElementById("telephone1").value=="") || (!PhoneValidation(document.getElementById("telephone1").value))){
       alert("Por favor,  escriba su Teléfono");
       document.getElementById("telephone1").value=""
       document.getElementById("telephone1").focus();
       return false;
       }
      else if(!checkNumber(document.getElementById("employeeNumber").value)){
         alert("Por favor, introduzca el número de el número de empleados de campo");
         document.getElementById("employeeNumber").value="";
         document.getElementById("employeeNumber").focus();
         return false;
       }
        else if(!checkEmailFormat(document.getElementById("email").value)){
        alert("Por favor, escriba su Correo Electrónico");
        document.getElementById("email").value="";
        document.getElementById("email").focus();
        return false;
       }
       else if(document.getElementById("captchaText").value == ""){
        alert("Por favor, escriba el texto que ve en la imagen");
        document.getElementById("captchaText").focus();
        return false;       
      }
       else
       {
        validateCaptchaImageContactUs(form.id);
        return false;       
        }
}
 


function get_check_value_contactUs_form(){
    var counter = 0;  // counter for checked checkboxes
    var i       = 0;  // loop variable
    var checkCount     = ''; // final url string
    // get a collection of objects with the specified 'input' TAGNAME
    var input_obj = document.getElementsByTagName('input');
    // loop through all collected objects
    for (i=0; i < input_obj.length; i++){
        // if input object is checkbox and checkbox is checked then ...
        if (input_obj[i].type == 'checkbox' && input_obj[i].checked == true && input_obj[i].name=="salesValues"){
            // ... increase counter and concatenate checkbox value to the url string

            counter++;
            checkCount = checkCount + '&salesValues=' + input_obj[i].value;
        }
    }
    // display url string or message if there is no checked checkboxes
    if (counter > 0){
        // remove first '&' from the generated url string
        checkCount = checkCount.substr(1);
        // display final url string
        return checkCount;
        // or you can send checkbox values
        // window.location.href = 'my_page.php?' + url;
 
    }
    
}

function get_check_value_consultation_form(){
    var counter = 0;  // counter for checked checkboxes
    var i       = 0;  // loop variable
    var checkCount     = ''; // final url string
    // get a collection of objects with the specified 'input' TAGNAME
    var input_obj = document.getElementsByTagName('input');
    // loop through all collected objects
    for (i=0; i < input_obj.length; i++){
                // if input object is checkbox and checkbox is checked then ...
        if (input_obj[i].type == 'checkbox' && input_obj[i].checked == true && input_obj[i].name=="availablity"){
            // ... increase counter and concatenate checkbox value to the url string

            counter++;
            checkCount = checkCount + input_obj[i].value + ',';
        }
    }    
    // display url string or message if there is no checked checkboxes
    if (counter > 0){
        // remove first '&' from the generated url string
        checkCount = checkCount.substr(0,(checkCount.length-1));
        // display final url string
        return checkCount;
        // or you can send checkbox values
        // window.location.href = 'my_page.php?' + url;
 
    }
    
}


function get_radio_value_contactUs_form() {
var selection = document.contactUs.serviceType;
for (i=0; i<selection.length; i++)
  if (selection[i].checked == true)
  return selection[i].value;
}
//Function to get the Captcha Image
validateCaptchaImageContactUs =  function(fId) {

    xmlhttp = new getXMLObject(); 
    var querystring;
    if(xmlhttp){
        var siteLanguage = document.contactUs.siteLanguage.value;
        var pageName = document.contactUs.success_URL.value;
        var formName = document.contactUs.formName.value;
        
        
        var name = document.contactUs.name.value;
        var paternalLastName = document.contactUs.paternalLastName.value;        
        var maternalLastName = document.contactUs.maternalLastName.value;
        var address1 = document.contactUs.address1.value;
        var address2 = document.contactUs.address2.value;
        var city = document.contactUs.city.value;
        var state = document.contactUs.state.value;
        var zipcode = document.contactUs.zipcode.value;
        var telephone1 = document.contactUs.telephone1.value;
        
        var email = document.contactUs.email.value;
        var learnMode = document.contactUs.learnMode.value;
        
        var captchaText = document.getElementById("captchaText").value.toLowerCase();
        if(document.getElementById("contactType") != null){
            var contactType = document.contactUs.contactType.value;
            var time = document.contactUs.time.value;
            var dob = document.contactUs.dob.value;
            var availablity = document.contactUs.availablity.value;
            var messageField = document.contactUs.messageField.value;
         } else {
            var selectedBranch = document.contactUs.selectedBranch.value;
            var telephone2 = document.contactUs.telephone2.value;
            var businessName = document.contactUs.businessName.value;
            var employeeNumber = document.contactUs.employeeNumber.value;
         }
        
        
        var url = "/oriental/Captcha.do";
        
        //xmlhttp.onreadystatechange=handleImageResponse;
        querystring = "siteLanguage="+siteLanguage+"&pageName="+pageName+"&formName="+formName;
        querystring = querystring + "&name="+name+"&paternalLastName="+paternalLastName+"&maternalLastName="+maternalLastName+"&address1="+address1+"&address2="+address2+"&zipcode="+zipcode;
        querystring = querystring + "&city="+city+"&state="+state+"&telephone1="+telephone1+"&email="+email+"&learnMode="+learnMode;
        if(document.getElementById("contactType") != null){   
            querystring = querystring + "&contactType="+contactType+"&time="+time+"&dob="+dob+"&availablity="+get_check_value_consultation_form()+"&messageField="+messageField;
        }else{
            querystring = querystring + "&selectedBranch="+selectedBranch+"&serviceType="+get_radio_value_contactUs_form()+"&"+get_check_value_contactUs_form();
            querystring = querystring + "&telephone2="+telephone2+"&businessName="+businessName+"&employeeNumber="+employeeNumber;
        }
        querystring = querystring + "&captchaText="+captchaText;
        xmlhttp.open("POST", url, false);
        xmlhttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
        xmlhttp.send(querystring);
        //alert(trim(xmlhttp.responseText));
        handleImageResponsecontactUs();
    }
}


/* CONTACT US FORM (BOTH SPA AND ENG) ENDS */


/* CONTACT US IRA FORM (BOTH SPA AND ENG) STARTS*/
function validatecontactusIRASP(form) {
    if (document.getElementById("name").value==""){
         alert("Por favor, introduzca campo Nombre"); 
         document.getElementById("name").focus();
         return false; 
     } else if (document.getElementById("paternalLastName").value==""){ 
         alert("Por favor, introduzca campo Apellido Materno ");
         document.getElementById("paternalLastName").focus();
         return false; 
     } else if (document.getElementById("maternalLastName").value==""){
         alert("Por favor, introduzca campo Apellido Materno ");
         document.getElementById("maternalLastName").focus();
           return false; 
     } else if((document.getElementById("telephone1").value=="") || (!PhoneValidation(document.getElementById ("telephone1").value))){ 
             alert("Por favor,  escriba su Teléfono");
             document.getElementById("telephone1").value="";
             document.getElementById("telephone1").focus();
             return false; 
    }
      else if((document.getElementById("email").value=="") || (!checkEmailFormat(document.getElementById("email").value))){
           alert("Por favor, escriba su Correo Electrónico");
           document.getElementById("email").value="";
           document.getElementById("email").focus();
           return false;
       }
      else if(document.getElementById("captchaText").value == ""){
        alert("Por favor, escriba el texto que ve en la imagen");
        document.getElementById("captchaText").focus();
        return false;       
      }
       else
       {
        validateCaptchaImageContactUsIRA(form.id);
        return false; 
       }
}

function validatecontactusIRA(form) {
    if (document.getElementById("name").value==""){
         alert("Please enter Name field"); 
         document.getElementById("name").focus();
         return false; 
     } else if (document.getElementById("paternalLastName").value==""){ 
         alert("Please enter Paternal Last Name field");
         document.getElementById("paternalLastName").focus(); 
         return false; 
     } else if (document.getElementById("maternalLastName").value==""){
          alert("Please enter Maternal Last Name field");
          document.getElementById("maternalLastName").focus();
           return false; 
     } else if((document.getElementById("telephone1").value=="") || (!PhoneValidation(document.getElementById ("telephone1").value))){ 
             alert("Please enter valid Telephone field"); 
             document.getElementById("telephone1").value="";
             document.getElementById("telephone1").focus();
             return false; 
      }
        else if((document.getElementById("email").value=="") || (!checkEmailFormat(document.getElementById("email").value))){
           alert("Please enter a valid email ID");
           document.getElementById("email").value="";
           document.getElementById("email").focus(); 
           return false;
       }
       else if(document.getElementById("captchaText").value == ""){
        alert("Please enter the text you see in the image");
        document.getElementById("captchaText").focus();
        return false;       
      }
       else
       {
        validateCaptchaImageContactUsIRA(form.id);
        return false;       
       }
}

function get_check_value_contactUsIRA_form(){
    var counter = 0;  // counter for checked checkboxes
    var i       = 0;  // loop variable
    var checkCount     = ''; // final url string
    // get a collection of objects with the specified 'input' TAGNAME
    var input_obj = document.getElementsByTagName('input');
    // loop through all collected objects
    for (i=0; i < input_obj.length; i++){
        // if input object is checkbox and checkbox is checked then ...
        if (input_obj[i].type == 'checkbox' && input_obj[i].checked == true){
            // ... increase counter and concatenate checkbox value to the url string
            counter++;
            checkCount = checkCount + '&interestProduct=' + input_obj[i].value;
        }
    }
    // display url string or message if there is no checked checkboxes
    if (counter > 0){
        // remove first '&' from the generated url string
        checkCount = checkCount.substr(1);
        // display final url string
        return checkCount;
        // or you can send checkbox values
        // window.location.href = 'my_page.php?' + url;
 
    }
    
}

validateCaptchaImageContactUsIRA =  function(fId) {
    xmlhttp = new getXMLObject(); 
    var querystring;
    if(xmlhttp){
        var siteLanguage = document.contactUsIRA.siteLanguage.value;
        var pageName = document.contactUsIRA.success_URL.value;
        var formName = document.contactUsIRA.formName.value;
        
        var selectedBranch = document.contactUsIRA.selectedBranch.value;
        var name = document.contactUsIRA.name.value;
        var paternalLastName = document.contactUsIRA.paternalLastName.value;        
        var maternalLastName = document.contactUsIRA.maternalLastName.value;
        var address1 = document.contactUsIRA.address1.value;
        var address2 = document.contactUsIRA.address2.value;
        var city = document.contactUsIRA.city.value;
        var state = document.contactUsIRA.state.value;
        var zipcode = document.contactUsIRA.zipcode.value;
        var telephone1 = document.contactUsIRA.telephone1.value;
        var telephone2 = document.contactUsIRA.telephone2.value;        
        var email = document.contactUsIRA.email.value;
        
        var amount = document.contactUsIRA.amount.value;
        var learnMode = document.contactUsIRA.learnMode.value;
        var captchaText = document.getElementById("captchaText").value.toLowerCase();
         if(document.getElementById("iraType") != null){                                      
            var iraType = document.getElementById("iraType").value;
        }
         
        
        //alert(fId);
        var url = "/oriental/Captcha.do";
        //alert(checkCount);        
        //xmlhttp.onreadystatechange=handleImageResponse;
        querystring = "siteLanguage="+siteLanguage+"&pageName="+pageName+"&formName="+formName;
        querystring = querystring + "&selectedBranch="+selectedBranch+"&iraType="+iraType;
        querystring = querystring + "&name="+name+"&paternalLastName="+paternalLastName+"&maternalLastName="+maternalLastName+"&address1="+address1+"&address2="+address2+"&zipcode="+zipcode;
        querystring = querystring + "&city="+city+"&state="+state+"&telephone1="+telephone1+"&telephone2="+telephone2+"&email="+email+"&"+get_check_value_contactUsIRA_form()+"&amount="+amount;
        querystring = querystring + "&learnMode="+learnMode+"&captchaText="+captchaText;
        
        //alert(querystring);
        xmlhttp.open("POST", url, false);
        xmlhttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
        xmlhttp.send(querystring);
        //alert(trim(xmlhttp.responseText));
        handleImageResponsecontactUs();
    }
}

/* CONTACT US IRA FORM (BOTH SPA AND ENG) ENDS*/


/* Privacy Policy FORM (BOTH SPA AND ENG) STRATS*/

function validatePrivacyFormOnSubmitSP(theForm) {
// validate Checkbox buttons
//For Joint Account Checkbox
myOption1 = -1;
myOption2 = -1;
for (i=theForm.jointAccountCheck.length-1; i > -1; i--) {
if (theForm.jointAccountCheck[i].checked) {
myOption1 = i; i = -1;
}
}
//For Limit Checkbox
for (j=theForm.limitCheck .length-1; j > -1; j--) {
if (theForm.limitCheck[j].checked) {
myOption2 = j; j = -1;
}
}
if (myOption1 == -1) {
alert("Favor de escoger una opci\363n");
return false;
}else if (myOption2 == -1) {
alert("Favor de escoger una opci\363n");
return false;
}else if (theForm.nameField.value==""){
alert("Favor de escribir su nombre");
theForm.nameField.focus();
return false;
}else if (theForm.addressField.value==""){
alert("Favor de escribir su direcci\363n");
theForm.addressField.focus();
return false;
}else if (theForm.citystatezipField.value==""){
alert("Favor de escribir su ciudad, estado y c\363digo postal");
theForm.citystatezipField.focus();
return false;
}else if (theForm.accNumberField.value==""){
alert("Favor de escribir su n\372mero de cuenta");
theForm.accNumberField.focus();
return false;
}else if(theForm.captchaText.value == ""){
    alert("Por favor, escriba el texto que ve en la imagen");
    theForm.captchaText.focus();
    return false;       
 }
else{
    validateCaptchaImagePrivacyForm(theForm.id);
    return false;
}
}

function validatePrivacyFormOnSubmit(theForm) {
// validate Checkbox buttons
//For Joint Account Checkbox
myOption1 = -1;
myOption2 = -1;
for (i=theForm.jointAccountCheck.length-1; i > -1; i--) {
if (theForm.jointAccountCheck[i].checked) {
myOption1 = i; i = -1;
}
}
//For Limit Checkbox
for (j=theForm.limitCheck .length-1; j > -1; j--) {
if (theForm.limitCheck[j].checked) {
myOption2 = j; j = -1;
}
}
if (myOption1 == -1) {
alert("Please choose one option");
return false;
}else if (myOption2 == -1) {
alert("Please choose one option");
return false;
}else if (theForm.nameField.value==""){
alert("Please write your name");
theForm.nameField.focus();
return false;
}else if (theForm.addressField.value==""){
alert("Please write your address");
theForm.addressField.focus();
return false;
}else if (theForm.citystatezipField.value==""){
alert("Please write your City, State, Zip");
theForm.citystatezipField.focus();
return false;
}else if (theForm.accNumberField.value==""){
alert("Please write your account number");
theForm.accNumberField.focus();
return false;
}else if(theForm.captchaText.value == ""){
    alert("Please enter the text you see in the image");
    theForm.captchaText.focus();
    return false;       
 }
else {
    validateCaptchaImagePrivacyForm(theForm.id);
    return false;
}
}


function get_radio_value_privacy_form() {
var selection = document.privacypolicyForm.jointAccountCheck;
for (i=0; i<selection.length; i++)
  if (selection[i].checked == true)
  return selection[i].value;
}
function get_check_value_privacy_form(){
    var counter = 0;  // counter for checked checkboxes
    var i       = 0;  // loop variable
    var checkCount     = ''; // final url string
    // get a collection of objects with the specified 'input' TAGNAME
    var input_obj = document.getElementsByTagName('input');
    // loop through all collected objects
    for (i=0; i < input_obj.length; i++){
        // if input object is checkbox and checkbox is checked then ...
        if (input_obj[i].type == 'checkbox' && input_obj[i].checked == true){
            // ... increase counter and concatenate checkbox value to the url string
            counter++;
            checkCount = checkCount + '&limitCheck=' + input_obj[i].value;
        }
    }
    // display url string or message if there is no checked checkboxes
    if (counter > 0){
        // remove first '&' from the generated url string
        checkCount = checkCount.substr(1);
        // display final url string
        return checkCount;
        // or you can send checkbox values
        // window.location.href = 'my_page.php?' + url;
 
    }
    
}

validateCaptchaImagePrivacyForm =  function(fId) {
    xmlhttp = new getXMLObject(); 
    var querystring;
    if(xmlhttp){
        var siteLanguage = document.privacypolicyForm.siteLanguage.value;
        var pageName = document.privacypolicyForm.success_URL.value;
        var formName = document.privacypolicyForm.formName.value;
        
        var nameField = document.privacypolicyForm.nameField.value;
        var addressField = document.privacypolicyForm.addressField.value;        
        var citystatezipField = document.privacypolicyForm.citystatezipField.value;        
        var accNumberField = document.privacypolicyForm.accNumberField.value;
        var captchaText = document.getElementById("captchaText").value.toLowerCase();
         
        
        //alert(fId);
        var url = "/oriental/Captcha.do";
        //alert(checkCount);        
        //xmlhttp.onreadystatechange=handleImageResponse;
        querystring = "siteLanguage="+siteLanguage+"&pageName="+pageName+"&formName="+formName;
        querystring = querystring + "&nameField ="+nameField +"&jointAccountCheck="+get_radio_value_privacy_form()+"&"+get_check_value_privacy_form()+"&addressField="+addressField+"&citystatezipField="+citystatezipField+"&accNumberField="+accNumberField;
        querystring = querystring + "&captchaText="+captchaText;
        
        //alert(querystring);
        xmlhttp.open("POST", url, false);
        xmlhttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
        xmlhttp.send(querystring);
        //alert(trim(xmlhttp.responseText));
        handleImageResponsecontactUs();
    }
}




/* PLAN AND LEARN FORMS (BOTH SPA AND ENG) STARTS*/

function validateplanandlearnSP(form)
{
      if (document.getElementById("name").value==""){
        alert("Por favor, introduzca campo Nombre");
        document.getElementById("name").focus();
       return false;
       }
       else if((document.getElementById("telephone1").value=="") || (!PhoneValidation(document.getElementById("telephone1").value))){
       alert("Por favor,  escriba su Teléfono");
       document.getElementById("telephone1").value="";
       document.getElementById("telephone1").focus();
       return false;
       }
        else if(!checkEmailFormat(document.getElementById("email").value)){
        alert("Por favor, escriba su Correo Electrónico");
        document.getElementById("email").value="";
        document.getElementById("email").focus();
        return false;
      }
      else if(document.getElementById("captchaText").value == ""){
        alert("Por favor, escriba el texto que ve en la imagen");
        document.getElementById("captchaText").focus();
        return false;       
      }
       else
       {
       validateCaptchaImageplanandlearnForm(form.id);
       return false; 
       }
}


function validateplanandlearn(form)
{
       if (document.getElementById("name").value==""){
        alert("Please enter Name field");
        document.getElementById("name").focus();
       return false;
       }
        else if((document.getElementById("telephone1").value=="") || (!PhoneValidation(document.getElementById("telephone1").value))){
        alert("Please enter valid Telephone field");
        document.getElementById("telephone1").value="";
        document.getElementById("telephone1").focus();
        return false;
       }
        else if(!checkEmailFormat(document.getElementById("email").value)){
           alert("Please enter a valid email ID");
           document.getElementById("email").value="";
           document.getElementById("email").focus();
          return false;
       }
       else if(document.getElementById("captchaText").value == ""){
        alert("Please enter the text you see in the image");
        document.getElementById("captchaText").focus();
        return false;       
      }
       else
       {        
        validateCaptchaImageplanandlearnForm(form.id);
        return false; 
       }
}


validateCaptchaImageplanandlearnForm =  function(fId) {
    xmlhttp = new getXMLObject(); 
    var querystring;
    if(xmlhttp){
        //alert(xmlhttp);
        var siteLanguage = document.planandlearnForm.siteLanguage.value;
        var pageName = document.planandlearnForm.success_URL.value;
        var formName = document.planandlearnForm.formName.value;
        var customerInfo = document.planandlearnForm.customerInfo.value;
        var stage = document.planandlearnForm.stage.value;
        var name = document.planandlearnForm.name.value;
        var telephone1 = document.planandlearnForm.telephone1.value;
        var telephone2 = document.planandlearnForm.telephone2.value;
        var email = document.planandlearnForm.email.value;
        
        var captchaText = document.getElementById("captchaText").value.toLowerCase();
              
        //alert(fId);
        var url = "/oriental/Captcha.do";
        //alert(checkCount);        
        //xmlhttp.onreadystatechange=handleImageResponse;
        querystring = "siteLanguage="+siteLanguage+"&pageName="+pageName+"&formName="+formName+"&customerInfo="+customerInfo+"&stage="+stage;
        querystring = querystring + "&name="+name+"&telephone1="+telephone1+"&telephone2="+telephone2+"&email="+email;
        querystring = querystring + "&captchaText="+captchaText;
        
        //alert(querystring);
        xmlhttp.open("POST", url, false);
        xmlhttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
        xmlhttp.send(querystring);
        //alert(trim(xmlhttp.responseText));
        handleImageResponsecontactUs();
    }
}


/* PLAN AND LEARN FORMS (BOTH SPA AND ENG) ENDS */




/* CAPTCHA VALIDATION STARTS*/
trim = function (str){
    return str.replace(/^\s+|\s+$/g,"");
}
getXMLObject=function()  
{
    var xmlhttp = false;
    try {
        xmlhttp = new ActiveXObject("Msxml2.XMLHTTP")  // For Old Microsoft Browsers
    }
    catch (e) {
        try {
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP")  // For Microsoft IE 6.0+
        }
        catch (e2) {
            xmlhttp = false   // No Browser accepts the XMLHTTP Object then false
        }
    }
    if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
        xmlhttp = new XMLHttpRequest();        //For Mozilla, Opera Browsers
    }
    return xmlhttp ;  // Mandatory Statement returning the ajax object created
}


handleImageResponsecontactUs=function(){
    //alert("inside response ->"+xmlhttp.readyState+ "--" +xmlhttp.status);
    if (xmlhttp.readyState==4) {
        if(xmlhttp.status==200) {
            error=trim(xmlhttp.responseText);       
            //alert("Inside Captcha Response -> "+trim(xmlhttp.responseText));                
                if(error=="false"){
                    //document.getElementById("captchaErr").style.display="none";
                    document.location.href=document.getElementById("success_URL").value;
                    //return false;
                } else{                    
                    var rand_no = Math.random();
                    alert(document.getElementById("captchaErr").innerHTML);
                    document.getElementById("captchaImage").src="/oriental/validateCaptcha?rdmNo="+rand_no;
                    document.getElementById("captchaText").value="";
                    document.getElementById("captchaText").focus();
                    //document.getElementById("captchaErr").style.display="block";
                    //return false;
                }
        }
    }
}
 
function OpenWireless() {
    popupWin = window.open("https://my.mshift.com/c2ht?msestks=orientalbts.xml&stk=homebase&appno=orientalbt&mode=txtmsg", "tg1window", "status,scrollbars,height=400,width=450,resizable");
    popupWin.focus();
}
