

//  
//  Description : Handles the Country selection for dialing codes and State
//  Form : Application.Aspx
function GetDialingCodeForEnquiry(country, parentPrefix) 
{ 
// the prefix thing is a bit crappy, it is the parent codes used in the rendered HTML, eg. ctl00_mainContent_Wizard1_

    var state_Selection = document.getElementById('ctl00$MainContent$Wizard1$Country_Selection');
    if (state_Selection == null)
        state_Selection = document.forms[0]['ctl00$MainContent$Wizard1$State_Selection'];
    if (state_Selection == null)
        state_Selection = document.forms[0]['ctl00$MainContent$State_Selection'];//enquiry form
    var country = document.getElementById('ctl00$MainContent$Wizard1$State_Selection');
    if (country == null)
        country = document.forms[0]['ctl00$MainContent$Wizard1$Country_Selection'];
    if (country == null)
        country = document.forms[0]['ctl00$MainContent$Country_Selection']; //enquiry form
    var codes=country.value.split("$$");
	//var phone = document.getElementById(parentPrefix + 'Phone');
	//var	state_Selection = document.getElementById(parentPrefix + 'State_Selection');
	
		
	// phone & fax international dialing code
    //	if ( phone != null )
    //	{
    //	    // we should only update if the phone box is empty
    //        if ( phone.value.length == 0 )
    //        {
    //        
    //        //    13/11/2005 - Giles doesn't want this anymore  
    //        //    phone.value = codes[1];
    //        }
    //		
    //	}
	
	// now check to see if we need to enable the state / province
	if ( codes[0] == 'USA' | codes[0] == 'CAN' )
	{
		state_Selection.disabled = false;
		state_Selection.selectedIndex = 1;

	}
	else
	{
		state_Selection.disabled = true;
		state_Selection.selectedIndex = 0;
	}
}


//  
//  Description : Checks to see if the data is in the Pivotal format or not
//  
function validateYYYYDDMMDate(oSrc, args)
{
    var dateIn = args.Value;
	var bValid = true;
		
     
    try {  	
	    if (dateIn.length != 10 || dateIn.indexOf('-') == -1)
	    {
		    bValid = false;
	    }
	    else
	    {
		    var dateArr = dateIn.split('-');
		    if (dateArr.length == 3)
		    {
		    
		       
		        // SJG 20/01/2006 - Some weird JScript error where ParseInt seems to fail with "08" and "09"
		        // got it from http://groups.google.co.uk/group/comp.lang.javascript/browse_thread/thread/892cb564bbe2cec2/79022bf395c79dd5?lnk=st&q=%22parseInt+doesn't+work%22+javascript&rnum=1&hl=en#79022bf395c79dd5
			    
			    var year = parseInt(dateArr[0],10);
			    var day = parseInt(dateArr[1],10);
			    var month = parseInt(dateArr[2],10);
    			
			    if (isNaN(year) || isNaN(month) || isNaN(day))
			    {
			      
				    bValid = false;
			    }
			    else
			    {
				    if (month < 1 || month > 12 || day < 1 || day > 31)
				    {
			
					   bValid = false;
				    }
				    else
				    {
					    switch (month) {
						    case 2:
							    if (day > 28) {
							    
								    bValid = false;
							    }
							    break;
						    case 4:
						    case 6:
						    case 9:
						    case 11:
							    if (day > 30) {
							       
								    bValid = false;
							    }
							    break;
						    default:
							    break;
					    }
				    }
			    }
		    }
		    else
		    {
		   
			    bValid = false;
		    }
    	 
	
	    }
	 }
	 catch (e) {
	   
	    // error, so it must be wrong!
	    bValid = false;   
	 }   
	    
	 args.IsValid = bValid;
		
}

//  
//  Description : Validates special interest groups for the contact.
//  Form : Update Contact.Aspx
function validateContactUpdateSpecialInterestGroups(oSrc, args){

	var bValid = false;
		
	if (
		document.getElementById('ctl00$MainContent$Wizard1$chkInterest_Business_Process').checked || 
		document.getElementById('ctl00$MainContent$Wizard1$chkInterest_').checked || 
		document.getElementById('ctl00$MainContent$Wizard1$chkInterest_Business_Succession_Planning').checked ||
		document.getElementById('ctl00$MainContent$Wizard1$chkInteres_Business_Technology').checked ||
		document.getElementById('ctl00$MainContent$Wizard1$chkInterest_Business_Valuation').checked ||
		document.getElementById('ctl00$MainContent$Wizard1$chkInteres_Estate_Administration').checked 
		
		)
    {
		
		bValid = true
    }
		
	
	args.IsValid = bValid;
}

//  
//  Description : Validates the Role selection on contact.
//  Form : Update Contact2.Aspx
function validateContactUpdateRole2(oSrc, args){
    
	var bValid = false;
		
	if (
		document.getElementById('ctl00_ZoneTwoParts_Settings_chkRole_Marketing_Contact').checked || 
		document.getElementById('ctl00_ZoneTwoParts_Settings_chkRole_Financial_Contact').checked || 
		document.getElementById('ctl00_ZoneTwoParts_Settings_chkRole_Firm_Administrator_Contact').checked ||
		document.getElementById('ctl00_ZoneTwoParts_Settings_chkRole_Human_Resources_Contact').checked ||
		document.getElementById('ctl00_ZoneTwoParts_Settings_chkRole_IT_Contact').checked ||
		document.getElementById('ctl00_ZoneTwoParts_Settings_chkRole_Other_Contact').checked 
		
		)
    {
		
		bValid = true
    }
		
	
	args.IsValid = bValid;
}

//  
//  Description : Validates the Role selection on contact.
//  Form : Update Contact.Aspx
function validateContactUpdateRole(oSrc, args){
    
	var bValid = false;
		
	if (
		document.getElementById('ctl00$MainContent$Wizard1$chkRole_Marketing_Contact').checked || 
		document.getElementById('ctl00$MainContent$Wizard1$chkRole_Financial_Contact').checked || 
		document.getElementById('ctl00$MainContent$Wizard1$chkRole_Firm_Administrator_Contact').checked ||
		document.getElementById('ctl00$MainContent$Wizard1$chkRole_Human_Resources_Contact').checked ||
		document.getElementById('ctl00$MainContent$Wizard1$chkRole_IT_Contact').checked ||
		document.getElementById('ctl00$MainContent$Wizard1$chkRole_Other_Contact').checked 
		
		)
    {
		
		bValid = true
    }
		
	
	args.IsValid = bValid;
}
	
//  
//  Description : Validates the Region selection on contact.
//  Form : Update Contact.Aspx
function validateContactUpdateRegion(oSrc, args){

	var bValid = false;
		
	if (
		document.getElementById('ctl00$MainContent$Wizard1$R_Australia_NewZealand').checked || 
		document.getElementById('ctl00$MainContent$Wizard1$R_Eastern_Europe').checked || 
		document.getElementById('ctl00$MainContent$Wizard1$R_India').checked ||
		document.getElementById('ctl00$MainContent$Wizard1$R_Latin_America').checked ||
		document.getElementById('ctl00$MainContent$Wizard1$R_Mexico').checked ||
		document.getElementById('ctl00$MainContent$Wizard1$R_Middle_East').checked ||
		document.getElementById('ctl00$MainContent$Wizard1$R_North_America').checked||
		document.getElementById('ctl00$MainContent$Wizard1$R_SE_Asia').checked ||
		document.getElementById('ctl00$MainContent$Wizard1$R_Southern_Africat').checked
		
		)
    {
		
		bValid = true
    }
		
	
	args.IsValid = bValid;
}




//  
//  Description : Checks to see that at least on for the firms services or other is entered.
//  Form : Enquiry.Aspx
function validateEnquiryFirmServices(oSrc, args){

	var bValid = false;
		
	if (
		document.getElementById('ctl00$mainContent$chkFirm_Service_Accounting').checked || 
		document.getElementById('ctl00$mainContent$chkFirm_Service_Audit').checked || 
		document.getElementById('ctl00$mainContent$chkFirm_Service_Legal').checked ||
		document.getElementById('ctl00$mainContent$chkFirm_Service_Tax').checked ||
		document.getElementById('ctl00$mainContent$chkFirm_Service_Offshore').checked ||
		document.getElementById('ctl00$mainContent$Firm_Service_Other').value.length > 0
		
		)
    {
		
		bValid = true
    }
		
	
	args.IsValid = bValid;
}
	
	
//  
//  Description : Checks to see that at least on for the firms services or other is entered.
//  Form : Application.Aspx
function validateApplicationFirmServices(oSrc, args){

	var bValid = false;
		
	if (
		document.getElementById('ctl00$mainContent$Wizard1$chkFirm_Service_Accounting').checked || 
		document.getElementById('ctl00$mainContent$Wizard1$chkFirm_Service_Audit').checked || 
		document.getElementById('ctl00$mainContent$Wizard1$chkFirm_Service_Legal').checked ||
		document.getElementById('ctl00$mainContent$Wizard1$chkFirm_Service_Tax').checked ||
		document.getElementById('ctl00$mainContent$Wizard1$chkFirm_Service_Offshore').checked ||
		document.getElementById('ctl00$mainContent$Wizard1$Firm_Service_Other').value.length > 0
		
		)
    {
		
		bValid = true
    }
		
	
	args.IsValid = bValid;
}
	
	
//  
//  Description : Checks to see if the State has been selected or not if USA or Canada have
//  Form : CompanyUpdate.Aspx
function validateCompanyUpdateStateSelection(oSrc, args){

	var bValid = true;
	
	var	state_Selection = document.getElementById('ctl00$MainContent$Wizard1$Country_Selection');
	if (state_Selection == null)
	    state_Selection = document.forms[0]['ctl00$MainContent$Wizard1$State_Selection'];
	var country = document.getElementById('ctl00$MainContent$Wizard1$State_Selection');
	if (country == null)
	    country = document.forms[0]['ctl00$MainContent$Wizard1$Country_Selection'];
    var codes=country.value.split("$$");

	if ( codes[0] == 'USA' | codes[0] == 'CAN' )
	    {
		    if ( state_Selection[state_Selection.selectedIndex].text == 'N/A' ) 
		    {
			    bValid = false;
		    }

	    }    
	
	//alert(codes[0]);
	args.IsValid = bValid;
}
	
	
//  
//  Description : Checks to see if the State has been selected or not if USA or Canada have
//  Form : Enquiry.Aspx
function validateEnquiryStateSelection(oSrc, args){

	var bValid = true;

	var state_Selection = document.getElementById('ctl00$MainContent$Wizard1$Country_Selection');
	if (state_Selection == null)
	    state_Selection = document.forms[0]['ctl00$MainContent$Wizard1$State_Selection'];
	if (state_Selection == null)
	    state_Selection = document.forms[0]['ctl00$MainContent$State_Selection']; //enquiry form
	var country = document.getElementById('ctl00$MainContent$Wizard1$State_Selection');
	if (country == null)
	    country = document.forms[0]['ctl00$MainContent$Wizard1$Country_Selection'];
	if (country == null)
	    country = document.forms[0]['ctl00$MainContent$Country_Selection']; //enquiry form
	    
    var codes=country.value.split("$$");

	if ( codes[0] == 'USA' | codes[0] == 'CAN' )
	    {
		    if ( state_Selection[state_Selection.selectedIndex].text == 'N/A' ) 
		    {
			    bValid = false;
		    }

	    }    
	
	args.IsValid = bValid;
}

//  
//  Description : Checks to see if the State has been selected or not if USA or Canada have
//  Form : Application.Aspx
function validateApplicationStateSelection(oSrc, args){

    
	var bValid = true;

	var state_Selection = document.getElementById('ctl00$MainContent$Wizard1$Country_Selection');
	if (state_Selection == null)
	    state_Selection = document.forms[0]['ctl00$MainContent$Wizard1$State_Selection'];
	if (state_Selection == null)
	    state_Selection = document.forms[0]['ctl00$MainContent$State_Selection']; //enquiry form
	var country = document.getElementById('ctl00$MainContent$Wizard1$State_Selection');
	if (country == null)
	    country = document.forms[0]['ctl00$MainContent$Wizard1$Country_Selection'];
	if (country == null)
	    country = document.forms[0]['ctl00$MainContent$Country_Selection']; //enquiry form
	    
    var codes=country.value.split("$$");

	if ( codes[0] == 'USA' | codes[0] == 'CAN' )
	    {
		    if ( state_Selection[state_Selection.selectedIndex].text == 'N/A' ) 
		    {
			    bValid = false;
		    }
	    }    
	
	args.IsValid = bValid;
	
    return true;
}
	
		
		
function validateContactUpdateForm_Page1()
{


    var bmainFieldsCheck = true;
	var validEmail = false;
    var svalidationMsg = '';
    
    var Password = document.getElementById('ctl00$MainContent$Wizard1$Password');
		
	var First_Name_Contact1  = document.getElementById('ctl00$MainContent$Wizard1$First_Name');
	var Last_Name_Contact1 = document.getElementById('ctl00$MainContent$Wizard1$Last_Name');
	var Email_Contac1 = document.getElementById('ctl00$MainContent$Wizard1$Email');
	
	var Fax_Int_Code = document.getElementById('ctl00_MainContent_Wizard1_Fax_Int_Code');
	var Fax_Area_Code = document.getElementById('ctl00_MainContent_Wizard1_Fax_Area_Code');
	var Fax_Main_Number  = document.getElementById('ctl00_MainContent_Wizard1_Fax_Main_Number');
	var Fax  = document.getElementById('Fax');

	var Phone_Int_Code = document.getElementById('ctl00_MainContent_Wizard1_Phone_Int_Code');
	var Phone_Area_Code = document.getElementById('ctl00_MainContent_Wizard1_Phone_Area_Code');
	var Phone_Main_Number  = document.getElementById('ctl00_MainContent_Wizard1_Phone_Main_Number');
	var Phone  = document.getElementById('Phone');

	var Cell_Int_Code = document.getElementById('ctl00_MainContent_Wizard1_Cell_Int_Code');
	var Cell_Area_Code = document.getElementById('ctl00_MainContent_Wizard1_Cell_Area_Code');
	var Cell_Main_Number  = document.getElementById('ctl00_MainContent_Wizard1_Cell_Main_Number');
	var Cell  = document.getElementById('Cell');
	
	Phone.value = formatPhoneNumber(Phone_Int_Code,Phone_Area_Code,Phone_Main_Number);

	var FaxNumber;
	FaxNumber = '';
	if ( Fax_Area_Code.value != '')
	{
		FaxNumber =  '+' + Fax_Int_Code.value;
	}
	if ( Fax_Int_Code.value != '' )
	{
	 	FaxNumber = FaxNumber + ' (' + Fax_Area_Code.value + ')';
	}
	Fax.value =  FaxNumber + ' ' + Fax_Main_Number.value;
	
	
	var CellNumber;
	CellNumber = '';
	if ( Cell_Area_Code.value != '')
	{
		CellNumber =  '+' + Cell_Int_Code.value;
	}
	if ( Cell_Int_Code.value != '' )
	{
	 	CellNumber = CellNumber + ' (' + Cell_Area_Code.value + ')';
	}
	Cell.value =  CellNumber + ' ' + Cell_Main_Number.value;
	
	

    if (Password.value.length <=0) { 
			svalidationMsg = svalidationMsg + 'Password \t\t\t: Missing\n'; 
			bmainFieldsCheck = false;
		}
		
      if (First_Name_Contact1.value.length <=0) { 
			svalidationMsg = svalidationMsg + 'First Name \t\t\t: Missing\n'; 
			bmainFieldsCheck = false;
		}
		
	
	 if (Last_Name_Contact1.value.length <=0) { 
			svalidationMsg = svalidationMsg + 'Last Name \t\t\t: Missing\n'; 
			bmainFieldsCheck = false;
		}
		
		
	 if (Email_Contac1.value.length <=0) { 
			svalidationMsg = svalidationMsg + '1st Contact Email \t\t\t: Missing\n'; 
			bmainFieldsCheck = false;
		}
		else
		{
		    validEmail = validateEmail( Email_Contac1.value );
		    if ( validEmail == false )
		    {
		        svalidationMsg = svalidationMsg + '1st Contact Email \t\t\t: Invalid\n';
		        bmainFieldsCheck = false; 
		    }	   
	    }
		
		
	   
	 if ( ( Phone_Area_Code.value.length <=0 ) || ( Phone_Main_Number.value.length <=0)) { 
			svalidationMsg = svalidationMsg + 'Phone Number \t\t\t: Missing\n'; 
			bmainFieldsCheck = false;
		}
	    else
	    {
	        if ( validateInternationNumber(Phone.value) == false )
	        {
	            svalidationMsg = svalidationMsg + 'Phone Number \t\t\t: Invalid\n'; 
			    bmainFieldsCheck = false;
	        }
	    
	    }
	        
	    if ( ( Fax_Area_Code.value.length >0 ) || ( Fax_Main_Number.value.length >0))  
	    {
	        if ( validateInternationNumber(Fax.value) == false )
	        {
	            svalidationMsg = svalidationMsg + 'Fax Number \t\t\t: Invalid\n'; 
			    bmainFieldsCheck = false;
	        }
	    }
	    
	     if ( ( Cell_Area_Code.value.length >0 ) || ( Cell_Main_Number.value.length >0))  
	    {
	        if ( validateInternationNumber(Cell.value) == false )
	        {
	            svalidationMsg = svalidationMsg + 'Cell Number \t\t\t: Invalid\n'; 
			    bmainFieldsCheck = false;
	        }
	    }
    
		
  if (document.getElementById('ctl00_MainContent_Wizard1_chkRole_Marketing_Contact').checked || 
            document.getElementById('ctl00_MainContent_Wizard1_chkRole_Financial_Contact').checked ||
            document.getElementById('ctl00_MainContent_Wizard1_chkRole_Firm_Administrator_Contact').checked || 
            document.getElementById('ctl00_MainContent_Wizard1_chkRole_Human_Resources_Contact').checked ||
            document.getElementById('ctl00_MainContent_Wizard1_chkRole_Other_Contact').checked ||
            document.getElementById('ctl00_MainContent_Wizard1_chkRole_IT_Contact').checked) {
                //at least one of the boxes is checked - all ok

        }
        else {
        
               bmainFieldsCheck =false;
              svalidationMsg = svalidationMsg + 'Your firms services \t\t\t: Missing\n'; 
                
               /*
                //none of the boxes are checked, let's check the 'Other' option
               
                 if (document.getElementById('ctl00_MainContent_Wizard1_Other_Contact').value.length <=0) { 
                    bmainFieldsCheck =false;
                    svalidationMsg = svalidationMsg + 'Your Role \t\t\t: Missing\n'; 
                 }
               */
        }
        
	if (bmainFieldsCheck==true) {
		return true;
	}
	else {
		alert(svalidationMsg);
		return false;
	}
		
		
		return false;
}



/////////////////////////////////  APPLICATION FORM


function validateApplicationForm_Page1()
{

// Validation for Page 1 of the Wizard 
    var bmainFieldsCheck = true;
	var validEmail = false;
    var svalidationMsg = '';
    
    var Firm_Name = document.getElementById('ctl00$mainContent$Wizard1$Firm_Name');
	var Managing_Partner = document.getElementById('ctl00$mainContent$Wizard1$Managing_Partner');
	
	var First_Name_Contact1  = document.getElementById('ctl00$mainContent$Wizard1$First_Name_Contact1');
	var Last_Name_Contact1 = document.getElementById('ctl00$mainContent$Wizard1$Last_Name_Contact1');
	var Email_Contac1 = document.getElementById('ctl00$mainContent$Wizard1$Email_Contac1');
	
    var First_Name_Contact2  = document.getElementById('ctl00$mainContent$Wizard1$First_Name_Contact2');
	var Last_Name_Contact2 = document.getElementById('ctl00$mainContent$Wizard1$Last_Name_Contact2');
	var Email_Contac2 = document.getElementById('ctl00$mainContent$Wizard1$Email_Contac2');
    
    var First_Name_Contact3  = document.getElementById('ctl00$mainContent$Wizard1$First_Name_Contact3');
	var Last_Name_Contact3 = document.getElementById('ctl00$mainContent$Wizard1$Last_Name_Contact3');
	var Email_Contac3 = document.getElementById('ctl00$mainContent$Wizard1$Email_Contac3');
    
    

    if (Firm_Name.value.length <=0) { 
			svalidationMsg = svalidationMsg + 'Firm Name \t\t\t: Missing\n'; 
			bmainFieldsCheck = false;
		}
	
	 if (Managing_Partner.value.length <=0) { 
			svalidationMsg = svalidationMsg + 'Managing Partner\t\t\t: Missing\n'; 
			bmainFieldsCheck = false;
		}
// 1st Contact 		
     if (First_Name_Contact1.value.length <=0) { 
			svalidationMsg = svalidationMsg + '1st Contact First Name \t\t: Missing\n'; 
			bmainFieldsCheck = false;
		}
		
     if (Last_Name_Contact1.value.length <=0) { 
			svalidationMsg = svalidationMsg + '1st Contact Last Name \t\t: Missing\n'; 
			bmainFieldsCheck = false;
		}
     
     if (Email_Contac1.value.length <=0) { 
			svalidationMsg = svalidationMsg + '1st Contact Email \t\t\t: Missing\n'; 
			bmainFieldsCheck = false;
		}
		else
		{
		    validEmail = validateEmail( Email_Contac1.value );
		    if ( validEmail == false )
		    {
		        svalidationMsg = svalidationMsg + '1st Contact Email \t\t\t: Invalid\n';
		        bmainFieldsCheck = false; 
		    }	   
	    }
		
// 2nd Contact		
 if (First_Name_Contact2.value.length <=0) { 
			svalidationMsg = svalidationMsg + '2nd Contact First Name \t\t: Missing\n'; 
			bmainFieldsCheck = false;
		}
		
     if (Last_Name_Contact2.value.length <=0) { 
			svalidationMsg = svalidationMsg + '2nd Contact Last Name \t\t: Missing\n'; 
			bmainFieldsCheck = false;
		}
     
     if (Email_Contac2.value.length <=0) { 
			svalidationMsg = svalidationMsg + '2nd Contact Email \t\t\t: Missing\n'; 
			bmainFieldsCheck = false;
		}
		else
		{
		    validEmail = validateEmail( Email_Contac2.value );
		    if ( validEmail == false )
		    {
		        svalidationMsg = svalidationMsg + '2nd Contact Email \t\t\t: Invalid\n';
		        bmainFieldsCheck = false; 
		    }	   
	    }
	    
// 3d Contact
 if (First_Name_Contact3.value.length <=0) { 
			svalidationMsg = svalidationMsg + '3rd Contact First Name \t\t: Missing\n'; 
			bmainFieldsCheck = false;
		}
		
     if (Last_Name_Contact3.value.length <=0) { 
			svalidationMsg = svalidationMsg + '3rd Contact Last Name \t\t: Missing\n'; 
			bmainFieldsCheck = false;
		}
     
     if (Email_Contac3.value.length <=0) { 
			svalidationMsg = svalidationMsg + '3rd Contact Email \t\t\t: Missing\n'; 
			bmainFieldsCheck = false;
		}
		else
		{
		    validEmail = validateEmail( Email_Contac3.value );
		    if ( validEmail == false )
		    {
		        svalidationMsg = svalidationMsg + '3rd Contact Email \t\t\t: Invalid\n';
		        bmainFieldsCheck = false; 
		    }	   
	    }
	
		if (bmainFieldsCheck==true) {
			return true;
		}
		else {
			alert(svalidationMsg);
			return false;
		}
		

}



function validateApplicationForm_Page2()
{
 //   var bmainFieldsCheck = true;
 //   var svalidationMsg = '';
    
    // MAKE GENERIC START	
  //  var Fax_Int_Code = document.getElementById('ctl00_mainContent_Wizard1_Fax_Int_Code');
//	var Fax_Area_Code = document.getElementById('ctl00_mainContent_Wizard1_Fax_Area_Code');
//	var Fax_Main_Number  = document.getElementById('ctl00_mainContent_Wizard1_Fax_Main_Number');
//	var Fax  = document.getElementById('Fax');

//	var Phone_Int_Code = document.getElementById('ctl00_mainContent_Wizard1_Phone_Int_Code');
//	var Phone_Area_Code = document.getElementById('ctl00_mainContent_Wizard1_Phone_Area_Code');
//	var Phone_Main_Number  = document.getElementById('ctl00_mainContent_Wizard1_Phone_Main_Number');
//	var Phone  = document.getElementById('Phone');
//	var country  = document.getElementById('ctl00_mainContent_Wizard1_Country_Selection');
	
//	var codes=country.value.split("$$");
/*
	Phone.value = formatPhoneNumber(Phone_Int_Code,Phone_Area_Code,Phone_Main_Number);
	
	// the fax number isn't mandatory, so we shouldn't perform the formatting if it's not being used
	var FaxNumber;
	FaxNumber = '';
	if ( Fax_Area_Code.value != '')
	{
		FaxNumber =  '+' + Fax_Int_Code.value;
	}
	if ( Fax_Int_Code.value != '' )
	{
	 	FaxNumber = FaxNumber + ' (' + Fax_Area_Code.value + ')';
	}
	Fax.value =  FaxNumber + ' ' + Fax_Main_Number.value;
*/
    
	// state needs to show N/A if not selected.
//	var	state_Selection = document.getElementById('ctl00_mainContent_Wizard1_State_Selection');
//	var	state = document.getElementById('State_');
//	
//	state.value = state_Selection[state_Selection.selectedIndex].text;
	
	/*
	// MAKE GENERIC END
    var	address = document.getElementById('ctl00_mainContent_Wizard1_Full_Address');
     if (address.value.length <=0) { 
			svalidationMsg = svalidationMsg + 'Address \t\t\t\t: Missing\n'; 
			bmainFieldsCheck = false;
		}



        if (country.value.length <=0) { 
			svalidationMsg = svalidationMsg + 'Country \t\t\t\t: Missing\n'; 
			bmainFieldsCheck = false;
		}
		
		// if USA or Canada then the state needs to be selected
		if ( codes[0] == 'USA' | codes[0] == 'CAN' )
	    {
		    if ( state.value == 'N/A' ) 
		    {
		        svalidationMsg = svalidationMsg + 'State for ' + country.value + '\t\t\t: Missing\n'; 
			    bmainFieldsCheck = false;
		    }

	    }
		
	   
	    if ( ( Phone_Area_Code.value.length <=0 ) || ( Phone_Main_Number.value.length <=0)) { 
			svalidationMsg = svalidationMsg + 'Phone Number \t\t\t: Missing\n'; 
			bmainFieldsCheck = false;
		}
	    else
	    {
	        if ( validateInternationNumber(Phone.value) == false )
	        {
	            svalidationMsg = svalidationMsg + 'Phone Number \t\t\t: Invalid\n'; 
			    bmainFieldsCheck = false;
	        }
	    
	    }
	        
	    if ( ( Fax_Area_Code.value.length >0 ) || ( Fax_Main_Number.value.length >0))  
	    {
	        if ( validateInternationNumber(Fax.value) == false )
	        {
	            svalidationMsg = svalidationMsg + 'Fax Number \t\t\t: Invalid\n'; 
			    bmainFieldsCheck = false;
	        }
	    }
	    var WWW = document.getElementById('ctl00$mainContent$Wizard1$Web_Site').value;
	  
	    if (WWW.length <=0) { 
			svalidationMsg = svalidationMsg + 'Web Site \t\t\t\t: Missing\n'; 
			bmainFieldsCheck = false;
		}
	    
		else {
			if ((WWW.indexOf('.')<0) || (WWW.length < 5)) {
				svalidationMsg = svalidationMsg + 'Web Site \t\t\t\t: Invalid\n'; 
				bmainFieldsCheck =false;
			}
		}
		
		

  
    if (bmainFieldsCheck==true) {
			return true;
		}
		else {
			alert(svalidationMsg);
			return false;
		}
		
 */
    return true;
}



function validateApplicationForm_Page3()
{

// Validation for Page 1 of the Wizard 
    var bmainFieldsCheck = true;
	var validEmail = false;
    var svalidationMsg = '';
    
    // checkbox handlers
	convertCheckBox ( 'ctl00_mainContent_Wizard1_chkFirm_Service_Accounting', 'Firm_Service_Accounting' );
	convertCheckBox ( 'ctl00_mainContent_Wizard1_chkFirm_Service_Audit', 'Firm_Service_Audit' );
	convertCheckBox ( 'ctl00_mainContent_Wizard1_chkFirm_Service_Legal', 'Firm_Service_Legal' );
	convertCheckBox ( 'ctl00_mainContent_Wizard1_chkFirm_Service_Tax', 'Firm_Service_Tax_Consulting' );
	convertCheckBox ( 'ctl00_mainContent_Wizard1_chkFirm_Service_Offshore', 'Firm_Service_Offshore' );

    convertYesNo( 'ctl00_mainContent_Wizard1_Firm_Licensed_to_Practice_Yes','ctl00_mainContent_Wizard1_Firm_Licensed_to_Practice_No','Firm_Licensed_to_Practice_Regu');

    return true;
}

function validateApplicationForm_Page4()
{

// Validation for Page 1 of the Wizard 
    var bmainFieldsCheck = true;
	var validEmail = false;
    var svalidationMsg = '';
       
    
//    convertDropdown('ctl00_mainContent_Wizard1_Practice_Area_1_Selection', 'Practice_Area_1');
//    convertDropdown('ctl00_mainContent_Wizard1_Practice_Area_2_Selection', 'Practice_Area_2');
//    convertDropdown('ctl00_mainContent_Wizard1_Practice_Area_3_Selection', 'Practice_Area_3');
//    convertDropdown('ctl00_mainContent_Wizard1_Practice_Area_4_Selection', 'Practice_Area_4');
//    convertDropdown('ctl00_mainContent_Wizard1_Practice_Area_5_Selection', 'Practice_Area_5');
//    
//    convertDropdown('ctl00_mainContent_Wizard1_Industry_Sector_1_Selection', 'Industry_Sector_1');
//    convertDropdown('ctl00_mainContent_Wizard1_Industry_Sector_2_Selection', 'Industry_Sector_2');
//    convertDropdown('ctl00_mainContent_Wizard1_Industry_Sector_3_Selection', 'Industry_Sector_3');
//    convertDropdown('ctl00_mainContent_Wizard1_Industry_Sector_4_Selection', 'Industry_Sector_4');
//    convertDropdown('ctl00_mainContent_Wizard1_Industry_Sector_5_Selection', 'Industry_Sector_5');
    
    convertYesNo( 'ctl00_mainContent_Wizard1_Any_Litigation_Yes','ctl00_mainContent_Wizard1_Any_Litigation_No','Any_Litigation');

    return true;
}


function validateApplicationForm_Page5()
{
     //   convertYesNo( 'ctl00_mainContent_Wizard1_Any_Litigation_Yes','ctl00_mainContent_Wizard1_Any_Litigation_No','Any_Litigation');

    return true;
}

function validateApplicationForm_Page6()
{
    convertYesNo( 'ctl00_mainContent_Wizard1_Pro_Indemnity_Insurance_Yes','ctl00_mainContent_Wizard1_Pro_Indemnity_Insurance_No','Pro_Indemnity_Insurance');

    return true;
}

function validateApplicationForm_Page7()
{
  
    convertYesNo( 'ctl00_mainContent_Wizard1_Staff_Speak_English_Yes','ctl00_mainContent_Wizard1_Staff_Speak_English_No','Staff_Speak_English');

    return true;
}


// MIH	16-12-2002		SRC #2	CS validation
// SJG  10-08-2004      Pivotal Integration.  Hidden fields to send off the interface values
//                      Also added new email and validateInternationNumber functions
function validateEnquiryForm() {
	// we need to validate the form and build the phone and fax numbers
	var bmainFieldsCheck = true;
	var validEmail = false;
    var svalidationMsg = '';
	var Fax_Int_Code = document.getElementById('ctl00_mainContent_Fax_Int_Code');
	var Fax_Area_Code = document.getElementById('ctl00_mainContent_Fax_Area_Code');
	var Fax_Main_Number  = document.getElementById('ctl00_mainContent_Fax_Main_Number');
	var Fax  = document.getElementById('Fax');

	var Phone_Int_Code = document.getElementById('ctl00_mainContent_Phone_Int_Code');
	var Phone_Area_Code = document.getElementById('ctl00_mainContent_Phone_Area_Code');
	var Phone_Main_Number  = document.getElementById('ctl00_mainContent_Phone_Main_Number');
	var Phone  = document.getElementById('Phone');
	
	var country  = document.getElementById('ctl00_mainContent_Country_Selection');
	
	var codes=country.value.split("$$");

	Phone.value = formatPhoneNumber(Phone_Int_Code,Phone_Area_Code,Phone_Main_Number);

//	Phone.value = '+' + Phone_Int_Code.value + ' (' + Phone_Area_Code.value + ') ' + Phone_Main_Number.value
	
	// the fax number isn't mandatory, so we shouldn't perform the formatting if it's not being used
	var FaxNumber;
	FaxNumber = '';
	if ( Fax_Area_Code.value != '')
	{
		FaxNumber =  '+' + Fax_Int_Code.value;
	}
	if ( Fax_Int_Code.value != '' )
	{
	 	FaxNumber = FaxNumber + ' (' + Fax_Area_Code.value + ')';
	}
	Fax.value =  FaxNumber + ' ' + Fax_Main_Number.value;

	// checkbox handlers
	convertCheckBox ( 'ctl00_mainContent_chkFirm_Service_Accounting', 'Firm_Service_Accounting' );
	convertCheckBox ( 'ctl00_mainContent_chkFirm_Service_Audit', 'Firm_Service_Audit' );
	convertCheckBox ( 'ctl00_mainContent_chkFirm_Service_Legal', 'Firm_Service_Legal' );
	convertCheckBox ( 'ctl00_mainContent_chkFirm_Service_Tax', 'Firm_Service_Tax_Consulting' );
	convertCheckBox ( 'ctl00_mainContent_chkFirm_Service_Offshore', 'Firm_Service_Offshore' );

	// state needs to show N/A if not selected.
	var	state_Selection = document.getElementById('ctl00_mainContent_State_Selection');
	var	state = document.getElementById('State_');
	
	state.value = state_Selection[state_Selection.selectedIndex].text;
	
	// Control Validation.  This isn't a rewrite so we need to keep the look and feel consistent
	// so not using any of .NET stuff here  
	
	//		Validate the main fields at the top of the page
  
		if (document.getElementById('ctl00_mainContent_Company_Name').value.length <=0) { 
			svalidationMsg = svalidationMsg + 'Firm Name \t\t\t: Missing\n'; 
			bmainFieldsCheck = false;
		}

		if (document.getElementById('ctl00_mainContent_First_Name').value.length <=0) { 
			svalidationMsg = svalidationMsg + 'First Name \t\t\t: Missing\n'; 
			bmainFieldsCheck = false;
		}

		if (document.getElementById('ctl00_mainContent_Last_Name').value.length <=0) { 
			svalidationMsg = svalidationMsg + 'Last Name \t\t\t: Missing\n'; 
			bmainFieldsCheck = false;
		}
		
		if (document.getElementById('ctl00_mainContent_Address_1').value.length <=0) { 
			svalidationMsg = svalidationMsg + 'Address \t\t\t\t: Missing\n'; 
			bmainFieldsCheck = false;
		}
		
		var	Email = document.getElementById('ctl00_mainContent_Email');
        
        if (Email.value.length <=0) { 
			svalidationMsg = svalidationMsg + 'Email Address \t\t\t: Missing\n'; 
			bmainFieldsCheck = false;
		}
		
		else
		{
		    validEmail = validateEmail( Email.value );
		    if ( validEmail == false )
		    {
		        svalidationMsg = svalidationMsg + 'Email Address \t\t\t: Invalid\n';
		        bmainFieldsCheck = false; 
		    }	   
	    }
	    
        if (document.getElementById('Country').value.length <=0) { 
			svalidationMsg = svalidationMsg + 'Country \t\t\t\t: Missing\n'; 
			bmainFieldsCheck = false;
		}
		
		// if USA or Canada then the state needs to be selected
		if ( codes[0] == 'USA' | codes[0] == 'CAN' )
	    {
		    if ( state.value == 'N/A' ) 
		    {
		        svalidationMsg = svalidationMsg + 'State for ' + document.getElementById('Country').value + '\t\t\t: Missing\n'; 
			    bmainFieldsCheck = false;
		    }

	    }
		
	   
	    if ( ( Phone_Area_Code.value.length <=0 ) || ( Phone_Main_Number.value.length <=0)) { 
			svalidationMsg = svalidationMsg + 'Phone Number \t\t\t: Missing\n'; 
			bmainFieldsCheck = false;
		}
	    else
	    {
	        if ( validateInternationNumber(Phone.value) == false )
	        {
	            svalidationMsg = svalidationMsg + 'Phone Number \t\t\t: Invalid\n'; 
			    bmainFieldsCheck = false;
	        }
	    
	    }
	        
	    if ( ( Fax_Area_Code.value.length >0 ) || ( Fax_Main_Number.value.length >0))  
	    {
	        if ( validateInternationNumber(Fax.value) == false )
	        {
	            svalidationMsg = svalidationMsg + 'Fax Number \t\t\t: Invalid\n'; 
			    bmainFieldsCheck = false;
	        }
	    }
	    var WWW = document.getElementById('ctl00_mainContent_WWW').value;
	  
	    if (WWW.length <=0) { 
			svalidationMsg = svalidationMsg + 'Web Site \t\t\t\t: Missing\n'; 
			bmainFieldsCheck = false;
		}
	    
		else {
			if ((WWW.indexOf('.')<0) || (WWW.length < 5)) {
				svalidationMsg = svalidationMsg + 'Web Site \t\t\t\t: Invalid\n'; 
				bmainFieldsCheck =false;
			}
		}
		
			
        if (document.getElementById('ctl00_mainContent_chkFirm_Service_Accounting').checked || 
            document.getElementById('ctl00_mainContent_chkFirm_Service_Audit').checked ||
            document.getElementById('ctl00_mainContent_chkFirm_Service_Legal').checked || 
            document.getElementById('ctl00_mainContent_chkFirm_Service_Tax').checked ||
            document.getElementById('ctl00_mainContent_chkFirm_Service_Offshore').checked) {
                //at least one of the boxes is checked - all ok

        }
        else {
        
                bmainFieldsCheck =false;
                svalidationMsg = svalidationMsg + 'Your firms services \t\t\t: Missing\n'; 
                
                /* 23/08/2005 - Removed as apparently it's now not needed.
             
                //none of the boxes are checked, let's check the 'Other' option
                 if (document.getElementById('ctl00_mainContent_Firm_Service_Other').value.length <=0) { 
                    bmainFieldsCheck =false;
                    svalidationMsg = svalidationMsg + 'Your firms services \t\t\t: Missing\n'; 
                 }
               */
        }
	  
//		Return validation result and message to the user
		if (bmainFieldsCheck==true) {
			return true;
		}
		else {
			alert(svalidationMsg);
			return false;
		}
	
	
}

// General Functions

function formatPhoneNumber(Phone_Int_Code, Phone_Area_Code, Phone_Main_Number)
{
    return ('+' + Phone_Int_Code.value + ' (' + Phone_Area_Code.value + ') ' + Phone_Main_Number.value);
}



function convertDropdown( dropdownFieldName, resultFieldName)
{
    
    var dropdown = document.getElementById(dropdownFieldName);
	var hidden = document.getElementById(resultFieldName);
 
    hidden.value = dropdown[dropdown.selectedIndex].text;

}

function convertYesNo( radioBoxYesName, radioBoxNoName, resultFieldName)

{

      // converts to either 1 or 0 into hidden field

      var radioBoxYes  = document.getElementById(radioBoxYesName);

      var radioBoxNo  = document.getElementById(radioBoxNoName);

      var resultField  = document.getElementById(resultFieldName);

      

      if ( radioBoxYes.checked == true )

      {

            resultField.value = 1;

      }

      else

      {

          if ( radioBoxNo.checked == true )

          {

                resultField.value = 0;

          }

          else

          {

              resultField.value = '';

          }

      }

      

}

 

// Pivotal can't handle checked on etc .. so we have to replace it with either 1 or 0
function convertCheckBox( checkBoxName, sourceFieldName)
{

	// converts to either 1 or 0 into hidden field
	var checkBox  = document.getElementById(checkBoxName);
	var sourceField  = document.getElementById(sourceFieldName);
	
	if ( checkBox.checked == true )
	{
		sourceField.value = 1;
	}
	else
	{
		sourceField.value = 0;
	}
	
}

// Declaring required variables
var digits = "0123456789";
// non-digit characters which are allowed in phone numbers
var phoneNumberDelimiters = "()- ";
// characters which are allowed in international phone numbers
// (a leading + is OK)
var validWorldPhoneChars = phoneNumberDelimiters + "+";
// Minimum no of digits in an international phone no.
var minDigitsInIPhoneNumber = 10;

function isInteger(s)
{   var i;
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag)
{   var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function validateInternationNumber(strPhone)
{
    s=stripCharsInBag(strPhone,validWorldPhoneChars);
    return (isInteger(s) && s.length >= minDigitsInIPhoneNumber);
}

function validateEmail(strEmail) 
{ 

    var at="@";
    var dot=".";
    var lat=strEmail.indexOf(at) ;

    var lstr=strEmail.length  

    var ldot=strEmail.indexOf(dot) 

    if (strEmail.indexOf(at)==-1)

    {
        return false 
    }

    if (strEmail.indexOf(at)==-1 || strEmail.indexOf(at)==0 || strEmail.indexOf(at)==lstr)
    {
        return false 
    } 


    if (strEmail.indexOf(dot)==-1 || strEmail.indexOf(dot)==0 || strEmail.indexOf(dot)==lstr)
    {
         return false
    } 

    if (strEmail.indexOf(at,(lat+1))!=-1)
    {
        return false
    } 

    if (strEmail.substring(lat-1,lat)==dot || strEmail.substring(lat+1,lat+2)==dot)

    { 
        return false 
    } 

    if (strEmail.indexOf(dot,(lat+2))==-1)

    { 
        return false 
    }

    if (strEmail.indexOf(" ")!=-1)

    { 
        return false
    }

    return true

 } 
