var emptyInitialMsg="", emptySurnameMsg ="",emptyAddressLine1Msg="", emptyAddressLine2Msg ="";
var emptyTownCityMsg="", emptyCountyStateMsg="", emptyEmailAddressMsg="", emptyZipCodeMsg="";
var NotQASCountry="", invalidCharacterMsg="", InvalidEmail="",emptyUserIdMsg=""
var emptyPwdMsg="";
function ValidateQASCountryList(strControl)
{
	var ControlID;
	var strArr=new Array ();
	if (strControl.length ==0)
		ControlID =  "cmbcountry";
	else
	{
		strControl= parseInt(strControl);
		strArr.push( "dlNonLeadMembersAddress__ctl" );
		strArr.push( strControl );
		strArr.push( "_cmbCountryOnList" );		
	}	
	var strSelectedValue=document.getElementById(ControlID).value;	
	var QASSupportedCountry=document.getElementById("hdnQASCountry").value;
	var arrQASSupportedCountry = new Array();
	arrQASSupportedCountry = QASSupportedCountry.toString().split("^");
	for (var nIndex = 0; nIndex<arrQASSupportedCountry.length ; nIndex++)
	{
		if (arrQASSupportedCountry[nIndex]==strSelectedValue)
			return true;
	}
	alert(NotQASCountry);
	return false;
}
function ResetTextControl(ctrlId, defVal)
{
    var ctrl=document.getElementById(ctrlId);
    if(ctrl !=null) ctrl.value='';    
}
function ResetComboControl(ctrlId)
{
    var ctrl=document.getElementById(ctrlId);
    if(ctrl !=null) ctrl.value=ctrl.options[0].value;    
}
function Reset()
{
    ResetTextControl('txtInitial','');
    ResetTextControl('txtSurname','');
    ResetTextControl('txtAddressLine1','');
    ResetTextControl('txtAddressLine2','');
    ResetTextControl('txtTownCity','');
    ResetTextControl('txtCountyState','');
    ResetTextControl('txtPostalCode','');    
    ResetTextControl('txtEmailAddress','');
    ResetComboControl('cmbTitle','');
    ResetComboControl('cmbCountry','');
    return false;
}
function FetchCountryList(strControl)
{
    SavingDropDownListValue();   
}
function ValidateSubmit()
{
    var valid =(document.getElementById("txtEmailAddress")==null || ValidateEmail("txtEmailAddress",'')==true)&&
   (document.getElementById("txtInitial")==null||( FilterWildCharactersName('txtInitial',invalidCharNameMsg)==true && FilterNumeric('txtInitial','',invalidCharNameMsg)==true)) &&
   (document.getElementById("txtSurname") ==null||( FilterWildCharactersName('txtSurname',invalidCharSurnameMsg)==true  && FilterNumeric('txtSurname','',invalidCharSurnameMsg)==true)) &&
   (document.getElementById("txtAddressLine1")==null|| FilterWildCharacters('txtAddressLine1','/,-,','',invalidCharAdd1Msg)==true) &&
   (document.getElementById("txtAddressLine2") ==null|| FilterWildCharacters('txtAddressLine2','/,-,','',invalidCharAdd2Msg)==true) &&
   (document.getElementById("txtTownCity") ==null|| FilterWildCharacters('txtTownCity','','',invalidCharTownCityMsg)==true) &&
   (document.getElementById("txtCountyState") ==null ||FilterWildCharacters('txtCountyState','','',invalidCharCountyStateMsg)==true) &&
   (document.getElementById("txtPostalCode") ==null|| FilterWildCharacters('txtPostalCode','','',invalidCharZipMsg)==true) &&
   checkMandatoryAttr("txtInitial",emptyInitialMsg) && checkMandatoryAttr("txtSurname",emptySurnameMsg) &&
   checkMandatoryAttr("txtAddressLine1",emptyAddressLine1Msg) &&  checkMandatoryAttr("txtAddressLine2",emptyAddressLine2Msg) &&
   checkMandatoryAttr("txtTownCity",emptyTownCityMsg) && checkMandatoryAttr("txtCountyState",emptyCountyStateMsg) &&
   checkMandatoryAttr("txtEmailAddress",emptyEmailAddressMsg) && checkMandatoryAttr("txtPostalCode",emptyZipCodeMsg);
   
   SavingDropDownListValue();                   

   return valid; 
}
function ShowHideFindAddress()
{	
	var countryName = "";
	var ddCtrl=document.getElementById("cmbCountry");
	if (ddCtrl!=null)
	{
		var countryName = ddCtrl.options[ddCtrl.selectedIndex].value ;
	    if ( countryName.length>0 )
	    {		    
		    var qasCounty=document.getElementById("hdnQASCountry");
		    if (qasCounty!=null)
		    {
			    var countryColl = qasCounty.value;
			    var imgBtn=document.getElementById("imgBtnFindAddress");	
		        if ( countryColl.length >0 && imgBtn !=null )
		           imgBtn.style.display=(countryColl.indexOf(countryName) != -1)? "block":"none";
		    }				
	    }
	}
}	
function SaveDDList(ddList, hdnFld)
{
    var list = document.getElementById(ddList);   
    if(list!=null)
    {	var selectIndex = list.selectedIndex;
        var hdn = document.getElementById(hdnFld);
        if( hdn != null )hdn.value = list.value + "^" + list.options[selectIndex].text;
    }
}
function SavingDropDownListValue()
{
    SaveDDList("cmbCountry","hdnCountry");
    SaveDDList("cmbTitle","hdnTitle");	
}
function FilterWildCharactersName(Control,invalidCharacterMsg)
	{
		var strValue;
		strValue = document.getElementById(Control).value;
		
		var wildCharacters = new Array( "<",">","/");
		
		if(strValue!="")
		  {
			 for(iCount=0;iCount<wildCharacters.length;iCount++)
			 {
				if(strValue.indexOf(wildCharacters[iCount])!=-1)
				{
					alert(invalidCharacterMsg + " " + wildCharacters[iCount]);
					document.getElementById(Control).select();
					document.getElementById(Control).focus();
					return false;
					
				}
			 }
	       }  
        return true;
    }
