﻿    
     var SIGNUP_INPUTTEXT_FIELD_IDs = Array("Q10005|A10005","Q10007|A10007","Q10017|A10017","Q10018|A10018","Q10019|A10019","Q10020|A10020","Q10021|A10021","Q10012|A10012","Q10015|A10015",'arecodeInput','3digitInput','4digitInput');    

    
    /* adding Search features in array */
    
    Array.prototype.exists = function(o) {
        for(var i = 0; i < this.length; i++)
            if(this[i] === o)
            return true;
        return false;
    }
    /* List of valid source code */

    var SOURCE_CODE = new Array ("123","124","125");

    
    /*
    DESCRIPTION:
        - This method is called from signup.aspx
    ASSUMPTION:
        - 
    NOTE:
    Author : Nitin Garg 11/20/2008
    */
    function setSelectedOption(objControl,objHiddenControl)
    {
        setRadioValue(document.getElementById(objControl),document.getElementById(objHiddenControl));
    }
    /*
    DESCRIPTION:
        - This method is called from getSelectedOption method
        - Sets selected radio button value in hidden input control
    ASSUMPTION:
        - 
    NOTE:
    Author : Nitin Garg 11/20/2008
    */
    function setRadioValue(objCntrl,objhdn)
    {
        objhdn.value = objCntrl.value;
    }
    function SetUnsubContent()
    {
        // All pages from where SetUnsubContent being called should have "pagename".js file
        // and implement onValidationChangeErrMessage method
        try{
            onValidationChangeErrMessage();
        }catch(err)
        {
        }
    }
    
 
    
    /*
    DESCRIPTION:
       -  This method is called from ChangeFontColorOnValidation_Unbranded_EmailPage() function
       -  Checks if errCtrlId exist + display style is block
       -  If display style errCtrlId is block then change color and text of targetCtrlId
    ASSUMPTION:
        - 
    NOTE:
    Author : Nitin Garg 12/18/2008
    */
    
    function changeTextAndColor(errCtrlId, targetCtrlId, targetText)
    {
        if( document.getElementById(errCtrlId))
        {
           if( document.getElementById(errCtrlId).style.display == "block"	)
           {
                document.getElementById(targetCtrlId).style.color = "red";
                document.getElementById(targetCtrlId).innerHTML = targetText ;;
           }
        }
    }
    
    
    /*
    DESCRIPTION:
        - This method is called from signup.aspx
       -  Sets selected check box value in hidden input control
    ASSUMPTION:
        - 
    NOTE:
    Author : Nitin Garg 11/20/2008
    */
    function setChkBI()
    {
        if(document.getElementById('Q10526|A11354').checked==true)
        {
           document.getElementById('Q10526|A11354').value="BI";
        }
        else
        {
            document.getElementById('Q10526|A11354').value="";
        }
    }
    
    
    function getQueryVariable(variable) 
    { 
        var query = window.location.search.substring(1); 
        var vars = query.split("&"); 
        for (var i=0;i<vars.length;i++) 
        { 
            var pair = vars[i].split("="); 
            if (pair[0] == variable) 
            { 
                return pair[1]; 
            } 
        } 
    } 
    
        /*
    DESCRIPTION:
        - This method is called from request-more-information.aspx
       -  It combines 3 input value [phone #] and set in hidden input box for orchestration
    ASSUMPTION:
        - 
    NOTE:
    Author : Nitin Garg 12/19/2008
    */
    function setPhoneNumber(areaCodeCtrl, threeDigitCtrl, fourDigitCtrl, targetCtrl)
    {
       
       document.getElementById(targetCtrl).value = document.getElementById(areaCodeCtrl).value +"-"+
                                                     document.getElementById(threeDigitCtrl).value +"-"+
                                                     document.getElementById(fourDigitCtrl).value;
       if ( document.getElementById(targetCtrl).value == "--")
       {
            document.getElementById(targetCtrl).value = "";
       }                                                     
                                                             
    }
    /*
    DESCRIPTION:
        - This method is called from request-more-information.aspx
       -  It combines 2 input drop down value [Month and Year DOB] and set in hidden input box for orchestration
    ASSUMPTION: Default date is 1st of the month
                Date as MMDDYYYY format as per orchestration validator DateValidationMMDDYYYY
        - 
    NOTE:
    Author : Nitin Garg 12/19/2008
    */
    function setDOB(monthCtrl,yearCtrl,targetCtrl)
    { 
       if ( document.getElementById(monthCtrl).value == "" ||
            document.getElementById(yearCtrl).value == "" )
        
       {
            document.getElementById(targetCtrl).value = "";
            return;
       }             
       document.getElementById(targetCtrl).value =  document.getElementById(monthCtrl).value + "/"+
                                                    '01'+ "/"+
                                                    document.getElementById(yearCtrl).value ;
    }
    
    /*
    DESCRIPTION:
        - This method is called from request-more-information.aspx
       -  Phone fields get automatically advance as user inputs characters
    ASSUMPTION: 
        - 
    NOTE:
    Author : Nitin Garg 12/22/2008
    */
    
    function PhoneAutoAdvance(curCtrlid, nextCtrlid)
    {
        if(document.getElementById(curCtrlid).value.length == 3)
        {
            document.getElementById(nextCtrlid).focus();
        }
    }
    
    
        /*
    DESCRIPTION:
        - This method is called from 
       -  It reads cookies value
    ASSUMPTION: 
        - 
    NOTE:
    Author : Nitin Garg 02/11/2009
    */
    
    function readCookie(name) {
	    var nameEQ = name + "=";
	    var ca = document.cookie.split(';');
	    for(var i=0;i < ca.length;i++) {
		    var c = ca[i];
		    while (c.charAt(0)==' ') c = c.substring(1,c.length);
		    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	    }
	    return null;
    }
    /*
    DESCRIPTION:
        - This method is called from email-to-friend.aspx
       -  Its sets the cookies value
    ASSUMPTION: 
        - 
    NOTE:
    Author : Nitin Garg 12/22/2008
    */
        
    function createCookie(name,value,days) {
	    if (days) {
		    var date = new Date();
		    date.setTime(date.getTime()+(days*24*60*60*1000));
		    var expires = "; expires="+date.toGMTString();
	    }
	    else var expires = "";
	    document.cookie = name+"="+value+expires+"; path=/";
    }
    /*
    DESCRIPTION:
       -  this deletes the cookie when called
    ASSUMPTION: 
        - 
    NOTE:
    Author : Nitin Garg 02/11/2009
    */
    
        function deleteCookies( name, path) 
        {
            if ( readCookie( name ) ) document.cookie = name + "=" +
                    ( ( path ) ? ";path=" + path : "") +
                    ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
        }
    
    /*
    DESCRIPTION:
        - This method is called from email-to-friend-confirmation.aspx
       -  It reads cookies value
    ASSUMPTION: 
        - 
    NOTE:
    Author : Nitin Garg 12/22/2008
    */
    
    function readCookie(name) {
	    var nameEQ = name + "=";
	    var ca = document.cookie.split(';');
	    for(var i=0;i < ca.length;i++) {
		    var c = ca[i];
		    while (c.charAt(0)==' ') c = c.substring(1,c.length);
		    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	    }
	    return null;
    }
    
    function Set18YearRequirement()
    {
        if ( document.getElementById('Q13704|A20058') != null)
        {
            if (document.getElementById('Q13704|A20058').checked )
            {
                document.getElementById('hdnQ13704|A20058').value="Yes";
            }
            else
            {
                document.getElementById('hdnQ13704|A20058').value="";
            }
        }
    }


function validateSendEmailForm(form){
    $('#email_overlay .errors').html('')
    $('#email_overlay .errors_container').css('display', 'none');


    var emails=$(form).find('input[name=txtsenderemail], input[name=txtrecipientemail]');

    var email_1=validateEmail(emails[0].value);
    var email_2=validateEmail(emails[1].value);
    var name_1=$(form).find('input[name=txtsendername]')[0].value.match('([^ ]{1,})')!=null;
    var name_2=$(form).find('input[name=txtrecipientname]')[0].value.match('([^ ]{1,})')!=null;
    
    //console.info(email_1+' '+email_2+' '+name_1+' '+name_2);
    
    if(!name_1){
        $('#email_overlay #formSenderName').addClass('error');
    //$('#email_overlay .errors').append("<div>Please provide a Sender's Name.</div>");
    
    }
    if(!email_1){
        $('#email_overlay #formSenderEmail').addClass('error');
        //$('#email_overlay .errors').append("<div>Please provide a valid Sender's Email Address.</div>");
    }
    if(!name_2){
        $('#email_overlay #formRecipName').addClass('error');
        //$('#email_overlay .errors').append("<div>Please provide a Recipient's Name.</div>");
     }
    if(!email_2){
        $('#email_overlay #formRecipEmail').addClass('error');
        $('#email_overlay .errors').append("<div>Please provide a valid Recipient's Email Address.</div>"); }

    if(!email_1||!email_2||!name_1||!name_2){
        /*
        $('#email_overlay .errors_container').css('display', 'block');

        $('#email_overlay input').keypress(function(){
        $('#email_overlay .errors').html('')
        $('#email_overlay .errors_container').css('display', 'none');
        });
        */
        
        $('#emailPageError').css('display', 'block');
        
        $('#email_overlay input').keypress(function(){
            $('#email_overlay div').removeClass('error');
            $('#emailPageError').css('display', 'none');
        
        });
        

    }
    return (email_1&&email_2&&name_1&&name_2);

}

function validateEmail(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 PopupEmailLayer()
	{
	   document.getElementById('sendEmailDiv').style.display = "block";
       document.getElementById('emailConformDiv').style.display = "none";
       overlay_email.show();
	}
    
    
    /*
    DESCRIPTION:
        - This method is called from master page
       -  It reads for special query string userInteractionNode value for Source Code
       -  if Query String contain value then it sets in cookie named "UIN"
    ASSUMPTION: 
        - 
    NOTE:
    Author : Nitin Garg 02/11/2009
    */
    
    function CheckUINinQS(url)
    {
        keys = new Array(); 
        values = new Array(); 

        var query = url.substring(url.indexOf("?")+1);
        var pairs = query.split("&"); 
        for (var i=0;i<pairs.length;i++) 
        { 
            var pos = pairs[i].indexOf('='); 
            if (pos >= 0) 
            { 
                var argname = pairs[i].substring(0,pos); 
                var value = pairs[i].substring(pos+1); 
                
                if ( argname == 'tovsrc')
                {
                    if( isValidSourceCode(value))
                        createCookie('UIN',value,1);
                    else
                        deleteCookies('UIN','/');                                                
                }
            }    
        } 
        
      }
      
    /*
    DESCRIPTION:
        - This method is called from request-more-information.aspx
       -  It reads special cookies value for Source Code
    ASSUMPTION: 
        - 
    NOTE:
    Author : Nitin Garg 02/11/2009
    */

    
    function updateSourceCodeFromCookies()
    {
        if ( readCookie('UIN') != null)
        {
           document.getElementsByName('source_code')[0].value = readCookie('UIN');
        }
    }
    
    
    /*
    DESCRIPTION:
        - This method is called from CheckUINinQS()
       -  It checks whether source code is valid
       - Valid return true otherwise false
    ASSUMPTION: 
        - 
    NOTE:
    Author : Nitin Garg 02/11/2009
    */
    
    function isValidSourceCode(sourceCode)
    {
        // Return always true as Ken/Adnan asked so on 2/25
        return true;
        //return SOURCE_CODE.exists(sourceCode);
    }
    
    
		function getElementCSSVar(element, varname){
		      var is_true=YAHOO.util.Dom.get(element).className.match(varname);
		      var vals=YAHOO.util.Dom.get(element).className.match(new RegExp(varname+"_([a-zA-Z0-9_-|]{1,})"));
		      return vals&&vals.length?vals[1]:(is_true?true:false);
	      }

	      function setElementCSSVar(element, varname, newval){
		      var is_true=YAHOO.util.Dom.get(element).className.match(varname);
		      var vals=YAHOO.util.Dom.get(element).className.match(new RegExp("(^| )"+varname+"_([a-zA-Z0-9_-]{1,})"));
				//console.dir(vals);
		      if(vals&&vals[2]){
		            YAHOO.util.Dom.replaceClass(element, varname+'_'+vals[2], varname+'_'+newval);
		      }else{
				YAHOO.util.Dom.addClass(element, varname+'_'+newval);
			}
	      }
	      
	      
	function switchStylestyle(styleName)
	{
		$('link[@rel*=style][title]').each(function(i) 
		{
			this.disabled = true;
			if (this.getAttribute('title') == styleName) this.disabled = false;
		});
		//createCookie('style', styleName, 365);
	}
	
	// Function 1 : to decode values
	
    function unEscapeFormFields(arrInputFormFields){
        for(i=0; i < arrInputFormFields.length; i++ )
            document.getElementById(arrInputFormFields[i]).value = unEscapeSpecialChars(document.getElementById(arrInputFormFields[i]).value);
        return true;
    }
    // Function 2 : to decode values

    function unEscapeSpecialChars(textneu) {
        
        textneu = textneu.replace(/&lt;/g,"<");
        textneu = textneu.replace(/&gt;/g,">");
        textneu = textneu.replace(/&#39;/g,"'");
        textneu = textneu.replace(/&quot;/g,'"');
        textneu = textneu.replace(/&amp;/g,'&');
        return(textneu);
    }