/* 
---Javascript 
---Date: 3/1/2008
---Created by: Sumudu Chulan Kodikara 
*/



//create the request
var xHRObject = false;
if (window.XMLHttpRequest) { xHRObject = new XMLHttpRequest(); }
else if (window.ActiveXObject)
{ xHRObject = new ActiveXObject("Microsoft.XMLHTTP"); }

/*New Destination function */
function chk_DestFrance_click()
{ 
if (document.getElementById('chk_DestFrance').checked==true)
return true;
else false;
}

function chk_DestFrance_click()
{ 
if (document.getElementById('chk_DestFrance').checked==true)
return true;
else false;
}
function chk_DestAustria_click()
{ 
if (document.getElementById('chk_DestAustria').checked==true)
return true;
else false;
}
function chk_DestGreece_click()
{ 
if (document.getElementById('chk_DestGreece').checked==true)
return true;
else false;
}
function chk_DestEgypt_click()
{ 
if (document.getElementById('chk_DestEgypt').checked==true)
return true;
else false;
}
function chk_DestTurkey_click()
{ 
if (document.getElementById('chk_DestTurkey').checked==true)
return true;
else false;
}
function chk_DestDubai_click()
{ 
if (document.getElementById('chk_DestDubai').checked==true)
return true;
else false;
}
function chk_DestOman_click()
{ 
if (document.getElementById('chk_DestOman').checked==true)
return true;
else false;
}
function chk_DestIndia_click()
{ 
if (document.getElementById('chk_DestIndia').checked==true)
return true;
else false;
}

function chk_France_click() {
        if (document.getElementById('chk_France').checked == true) {
            //enable radio buttons
            document.frm_BroRequest_new.rad_France[0].disabled = false;
            document.frm_BroRequest_new.rad_France[1].disabled = false;
            //the first radio button default checked
            document.frm_BroRequest_new.rad_France[0].checked = true;
        }
        else {
            //disable radio buttons
            document.frm_BroRequest_new.rad_France[0].disabled = true;
            document.frm_BroRequest_new.rad_France[1].disabled = true;
            //unchecked all the radio buttons
           document.frm_BroRequest_new.rad_France[0].checked = false;
           document.frm_BroRequest_new.rad_France[1].checked = false;
        }
    }

function chk_Egypt_click() {
        if (document.getElementById('chk_Egypt').checked == true) {
            //enable radio buttons
            document.frm_BroRequest_new.rad_Egypt[0].disabled = false;
            document.frm_BroRequest_new.rad_Egypt[1].disabled = false;
            //the first radio button default checked
            document.frm_BroRequest_new.rad_Egypt[0].checked = true;
        }
        else {
            //disable radio buttons
            document.frm_BroRequest_new.rad_Egypt[0].disabled = true;
            document.frm_BroRequest_new.rad_Egypt[1].disabled = true;
            //unchecked all the radio buttons
            document.frm_BroRequest_new.rad_Egypt[0].checked = false;
            document.frm_BroRequest_new.rad_Egypt[1].checked = false;
        }

    }
    function chk_India_click() {
        if (document.getElementById('chk_India').checked == true) {
            //enable radio buttons
            document.frm_BroRequest_new.rad_India[0].disabled = false;
            document.frm_BroRequest_new.rad_India[1].disabled = false;
            //the first radio button default checked
            document.frm_BroRequest_new.rad_India[0].checked = true;
        }
        else {
            //disable radio buttons
            document.frm_BroRequest_new.rad_India[0].disabled = true;
            document.frm_BroRequest_new.rad_India[1].disabled = true;
            //unchecked all the radio buttons
            document.frm_BroRequest_new.rad_India[0].checked = false;
            document.frm_BroRequest_new.rad_India[1].checked = false;
        }
    }
    
    
    function Button1_onclick() {
     
     var u_title='';
     var u_fname='';
     var u_surname='';
     var u_email='';
     //Newly added fields
     var u_street='';
     var u_suburb='';
     var u_city='';
     var u_state='';
     
     var u_postcode='';
     
     var u_addtomaillist='';
     var u_request='';
     var user_session=document.getElementById('txt_userdetails').value;
     var chk_France = document.getElementById('chk_France');
	 var chk_Egypt = document.getElementById('chk_Egypt');
	 var chk_India = document.getElementById('chk_India');
	 var bodyofrequest ='';
     
      var element=user_session.split('|');
     
     u_title=element[0];
     u_fname=element[1];
     u_surname=element[2];
     u_email=element[3];
     //Newly Added Address 
     u_street=element[4];
     u_suburb=element[5];
     u_city=element[6];
     u_state=element[7];
     u_postcode=element[8];
     
     
     
     //Modified here added addtomail list
     u_addtomaillist=element[9];
     u_request=element[10];
     
     var bodyofrequest = "title=" + encodeURIComponent(u_title) + "&fName=" + encodeURIComponent(u_fname);
		bodyofrequest += "&sName=" + encodeURIComponent(u_surname) + "&email=" + encodeURIComponent(u_email)+ "&street="+encodeURIComponent(u_street)+ "&suburb=" + encodeURIComponent(u_suburb)+"&city="+encodeURIComponent(u_city)+"&state="+encodeURIComponent(u_state)+"&postcode="+encodeURIComponent(u_postcode) +"&addtomaillist="+encodeURIComponent(u_addtomaillist);
		
		if(u_request == "None")
		bodyofrequest += "&u_request=None";
		else
		bodyofrequest += "&u_request="+ encodeURIComponent(u_request);
		
	if (chk_France.checked==false) bodyofrequest += "&brochureFrance=None";
		else 
		{
			if(document.getElementById('rad_france1').checked==true) bodyofrequest += "&brochureFrance=" + document.getElementById('rad_france1').value;
			else bodyofrequest += "&brochureFrance=" + document.getElementById('rad_france2').value;	
		}
			
			
    if(chk_Egypt.checked==false) bodyofrequest += "&brochureEgypt=None";
    else
    {
    if(document.getElementById('rad_egypt1').checked == true) bodyofrequest += "&brochureEgypt=" + document.getElementById('rad_egypt1').value;
    else
     bodyofrequest += "&brochureEgypt=" + document.getElementById('rad_egypt2').value;	
    } 
    
    		
	if(chk_India.checked ==false ) bodyofrequest += "&brochureIndia=None";
	else
	{
	if(document.getElementById('rad_india1').checked == true) bodyofrequest += "&brochureIndia=" + document.getElementById('rad_india1').value;	
	else bodyofrequest += "&brochureIndia=" + document.getElementById('rad_india2').value;
	}
		
	//alert(bodyofrequest);	
	
	
		xHRObject.open("POST", "response_brochureRequest_exuser.aspx", true);
       	//alert("Dyanamic Script was called");
		xHRObject.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		xHRObject.onreadystatechange = getData;
       	xHRObject.send(bodyofrequest); 
      
    document.getElementById('Button1').setAttribute('disabled','true');
    document.getElementById('Button1').setAttribute('value','Please Wait......');
     

    
    }










//function getData when receiving the response from the server
function getData()
{
    if (xHRObject.readyState == 4 && xHRObject.status == 200)
    {
        var serverText = xHRObject.responseText;
        //alert(serverText);
         
         
        if(serverText.indexOf('|') != -1)
        {
         var element=serverText.split('|');
         
         //Change Brochure Enquiry into Thank you
          document.getElementById('banner_brochureEnquiry_1').src="images/BannerImages/ThankYou/Header_01.jpg";
		  document.getElementById('banner_brochureEnquiry_2').src="images/BannerImages/ThankYou/Header_02.jpg";
	      document.getElementById('banner_brochureEnquiry_3').src="images/BannerImages/ThankYou/Header_03.jpg";
	      document.getElementById('banner_brochureEnquiry_5').src="images/BannerImages/ThankYou/Header_05.jpg";
	      
	      //Clear the Content of div_left
          document.getElementById('div_left').innerHTML = '';
          //Clear the Span Error
          //document.getElementById('error').innerHTML = '';
		  //document.getElementById('error').style.cssText = '';
		  
		  
		  document.getElementById('div_nested').innerHTML='';
		  document.getElementById('div_nested').style.cssText = ''
		  
		  document.getElementById('div_right').innerHTML='';
		  document.getElementById('div_right').style.cssText = ''
		  
		  
		 document.getElementById('div_right').style.cssText="color: #999999;font-family: Arial, Helvetica, sans-serif;overflow:auto;font-size:13px;";
		 document.getElementById('div_right').align="left";
		 
		 document.getElementById('div_right').innerHTML = '<strong>THANK YOU</strong><br/><br/>';

		 document.getElementById('div_right').innerHTML += 'Thank you for contacting Icon Holidays.<br/><br/>';

		 document.getElementById('div_right').innerHTML += '<strong>' + element[0] + '</strong><br/><br/>';
		 
		 //Request only
		if (element[1] == "Yes") document.getElementById('div_right').innerHTML += 'We appreciate your request for further information and will respond shortly.<br/><br/>';
		
		//Printed France and Egypt
		
		if ((element[2].indexOf('Printed') != -1)&&(element[3].indexOf('Printed') != -1)) document.getElementById('div_right').innerHTML += 'The printed brochures requested will shortly be forwarded to you.<br/>'; 
		
		//Printed France and India
		
		else if ((element[2].indexOf('Printed') != -1)&&(element[4].indexOf('Printed') != -1)) document.getElementById('div_right').innerHTML += 'The printed brochures requested will shortly be forwarded to you.<br/>';
    		
		//Printed Egypt and India 
		
		else if ((element[3].indexOf('Printed') != -1)&&(element[4].indexOf('Printed') != -1)) document.getElementById('div_right').innerHTML += 'The printed brochures requested will shortly be forwarded to you.<br/>';
        
        //Printed France only  
        
        else if (element[2].indexOf('Printed') != -1) document.getElementById('div_right').innerHTML += 'The printed brochure requested will shortly be forwarded to you.<br/>';
        
        //Printed India only
			
		else if (element[4].indexOf('Printed') != -1) document.getElementById('div_right').innerHTML += 'The printed brochure requested will shortly be forwarded to you.<br/>'; 
		
	    //All the printed brochures
			
		else if ((element[2].indexOf('Printed') != -1)&&(element[3].indexOf('Printed') != -1)&&(element[4].indexOf('Printed') != -1)) document.getElementById('div_right').innerHTML += 'The printed brochures requested will shortly be forwarded to you.<br/>';
       
        
        //All PDF Brochures
        
        //Only PDF France and Egypt 
        if ((element[2].indexOf('PDF') != -1)&&(element[3].indexOf('PDF') != -1)&& (element[4].indexOf('PDF') == -1)) 
			{
			   document.getElementById('div_right').innerHTML += 'The PDF brochures those you have requested can be downloaded by using the links below:<br/><br/>';
			   document.getElementById('div_right').innerHTML += '<a href="http://www.iconholidays.com/Brochures/Our_World_in_Style_Mediterranean.pdf" target="_blank">Our World in Style: <i>France &bull; Greece &bull; Turkey &bull; Austria</i></a><br/>';
			   document.getElementById('div_right').innerHTML += '<a href="http://www.iconholidays.com/Brochures/Our_World_in_Style_MiddleEast.pdf" target="_blank">Our World in Style: <i>Egypt &bull; Oman &bull; Dubai</i></a><br/>';
			}
			
		//Only PDF France and India
        else if ((element[2].indexOf('PDF') != -1)&&(element[4].indexOf('PDF') != -1)&& (element[3].indexOf('PDF') == -1)) 
			{
				document.getElementById('div_right').innerHTML += 'The PDF brochures those you have requested can be downloaded by using the links below:<br/><br/>';
				document.getElementById('div_right').innerHTML += '<a href="http://www.iconholidays.com/Brochures/Our_World_in_Style_Mediterranean.pdf" target="_blank">Our World in Style: <i>France &bull; Greece &bull; Turkey &bull; Austria</i></a><br/>';
				document.getElementById('div_right').innerHTML += '<a href="http://www.iconholidays.com/Brochures/India_in_Style.pdf" target="_blank">India in Style</a><br/>';
			}
			
		//Only PDF Egypt and India	
        else if ((element[3].indexOf('PDF') != -1)&&(element[4].indexOf('PDF') != -1) && (element[2].indexOf('PDF') == -1)) 
			{
				document.getElementById('div_right').innerHTML += 'The PDF brochures those you have requested can be downloaded by using the links below:<br/><br/>';
				document.getElementById('div_right').innerHTML += '<a href="http://www.iconholidays.com/Brochures/Our_World_in_Style_MiddleEast.pdf" target="_blank">Our World in Style: <i>Egypt &bull; Oman &bull; Dubai</i></a><br/>';
				document.getElementById('div_right').innerHTML += '<a href="http://www.iconholidays.com/Brochures/India_in_Style.pdf" target="_blank">India in Style</a><br/>';
			}
			
		//Only PDF France Only	
        else if (element[2].indexOf('PDF') != -1 && (element[3].indexOf('PDF') == -1) && (element[4].indexOf('PDF') == -1)) 
			{
				document.getElementById('div_right').innerHTML += 'The PDF brochure that you have requested can be downloaded by using the link below:<br/><br/>';
				document.getElementById('div_right').innerHTML += '<a href="http://www.iconholidays.com/Brochures/Our_World_in_Style_Mediterranean.pdf" target="_blank">Our World in Style: <i>France &bull; Greece &bull; Turkey &bull; Austria</i></a><br/>';
			}
         //Only PDF Egypt Only
         else if (element[3].indexOf('PDF') != -1 && (element[2].indexOf('PDF') == -1) && (element[4].indexOf('PDF') == -1)) 
			{
				document.getElementById('div_right').innerHTML += 'The PDF brochure that you have requested can be downloaded by using the link below:<br/><br/>';
				document.getElementById('div_right').innerHTML += '<a href="http://www.iconholidays.com/Brochures/Our_World_in_Style_MiddleEast.pdf" target="_blank">Our World in Style: <i>Egypt &bull; Oman &bull; Dubai</i></a><br/>';
			}
		//Only PDF India Only
         else if (element[4].indexOf('PDF') != -1 && (element[3].indexOf('PDF') == -1)&& (element[2].indexOf('PDF') == -1)) 
			{
				document.getElementById('div_right').innerHTML += 'The PDF brochure that you have requested can be downloaded by using the link below:<br/><br/>';
				document.getElementById('div_right').innerHTML += '<a href="http://www.iconholidays.com/Brochures/India_in_Style.pdf" target="_blank">India in Style</a><br/>';
			}
			//All the PDF brochures
         else if ((element[2].indexOf('PDF') != -1)&&(element[3].indexOf('PDF') != -1)&&(element[4].indexOf('PDF') != -1)) 
			{
				document.getElementById('div_right').innerHTML += 'The PDF brochures those you have requested can be downloaded by using the links below:<br/><br/>';
				document.getElementById('div_right').innerHTML += '<a href="http://www.iconholidays.com/Brochures/Our_World_in_Style_Mediterranean.pdf" target="_blank">Our World in Style: <i>France &bull; Greece &bull; Turkey &bull; Austria</i></a><br/>';
				document.getElementById('div_right').innerHTML += '<a href="http://www.iconholidays.com/Brochures/Our_World_in_Style_MiddleEast.pdf" target="_blank">Our World in Style: <i>Egypt &bull; Oman &bull; Dubai</i></a><br/>';
				
				document.getElementById('div_right').innerHTML += '<a href="http://www.iconholidays.com/Brochures/India_in_Style.pdf" target="_blank">India in Style</a><br/>';
			} 
          
          
          
          
          
          
        //document.getElementById('div_right').innerHTML += 'We appreciate your request for further information and the brochures requested will shortly be forwarded to you.<br/><br/>';

	   document.getElementById('div_right').innerHTML += '<br/>We look forward to assisting you with any travel arrangements you require.  Should you wish to discuss your ideas further with us, please do not hesitate to contact us.<br/><br/>';

		document.getElementById('div_right').innerHTML += '<strong>ICON HOLIDAYS</strong><br/><strong>Telephone: 03 9810 7666</strong>&nbsp;<span style="font-variant:small-caps">(melbourne and metropolitan area only)</span><br/><strong>Freecall: 1300 853 953</strong>&nbsp;<span style="font-variant:small-caps">(all other areas)</span>';  
          
          }
         
         
        
          
          
          
          
	
		
  
     
    }
}

//function to cut all spaces unneeded in a string
function trim(inputString) {
   // Removes leading and trailing spaces from the passed string. Also removes
   // consecutive spaces and replaces it with one space. If something besides
   // a string is passed in (null, custom object, etc.) then return the input.
   if (typeof inputString != "string") { return inputString; }
   var retValue = inputString;
   var ch = retValue.substring(0, 1);
   while (ch == " ") { // Check for spaces at the beginning of the string
      retValue = retValue.substring(1, retValue.length);
      ch = retValue.substring(0, 1);
   }
   ch = retValue.substring(retValue.length-1, retValue.length);
   while (ch == " ") { // Check for spaces at the end of the string
      retValue = retValue.substring(0, retValue.length-1);
      ch = retValue.substring(retValue.length-1, retValue.length);
   }
   while (retValue.indexOf("  ") != -1) { // Note that there are two spaces in the string - look for multiple spaces within the string
      retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length); // Again, there are two spaces in each of the strings
   }
   return retValue; // Return the trimmed string back to the user
} // Ends the "trim" function

//function emailCheck
function emailCheck (emailStr) {

/* The following variable tells the rest of the function whether or not
to verify that the address ends in a two-letter country or well-known
TLD. 1 means check it, 0 means don't. */

var checkTLD=1;

/* The following is the list of known TLDs that an e-mail address must end with. */

var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;

/* The following pattern is used to check if the entered e-mail address
fits the user@domain format. It also is used to separate the username
from the domain. */

var emailPat=/^(.+)@(.+)$/;

/* The following string represents the pattern for matching all special
characters. We don't want to allow special characters in the address.
These characters include ( ) < > @ , ; : \ " . [ ] */

var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";

/* The following string represents the range of characters allowed in a
username or domainname. It really states which chars aren't allowed.*/

var validChars="\[^\\s" + specialChars + "\]";

/* The following pattern applies if the "user" is a quoted string (in
which case, there are no rules about which characters are allowed
and which aren't; anything goes). E.g. "jiminy cricket"@disney.com
is a legal e-mail address. */

var quotedUser="(\"[^\"]*\")";

/* The following pattern applies for domains that are IP addresses,
rather than symbolic names. E.g. joe@[123.124.233.4] is a legal
e-mail address. NOTE: The square brackets are required. */

var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;

/* The following string represents an atom (basically a series of non-special characters.) */

var atom=validChars + '+';

/* The following string represents one word in the typical username.
For example, in john.doe@somewhere.com, john and doe are words.
Basically, a word is either an atom or quoted string. */

var word="(" + atom + "|" + quotedUser + ")";

// The following pattern describes the structure of the user

var userPat=new RegExp("^" + word + "(\\." + word + ")*$");

/* The following pattern describes the structure of a normal symbolic
domain, as opposed to ipDomainPat, shown above. */

var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");

/* Finally, let's start trying to figure out if the supplied address is valid. */

/* Begin with the coarse pattern to simply break up user@domain into
different pieces that are easy to analyze. */

var matchArray=emailStr.match(emailPat);

if (matchArray==null) {

/* Too many/few @'s or something; basically, this address doesn't
even fit the general mould of a valid e-mail address. */

	return "Email address seems incorrect (check @ and .'s)";
}
var user=matchArray[1];
var domain=matchArray[2];

// Start by checking that only basic ASCII characters are in the strings (0-127).

for (i=0; i<user.length; i++) {
if (user.charCodeAt(i)>127) {
	
	return "The username contains invalid characters.";
}
}
for (i=0; i<domain.length; i++) {
if (domain.charCodeAt(i)>127) {

	return "The domain name contains invalid characters.";
}
}

// See if "user" is valid

if (user.match(userPat)==null) {

// user is not valid

	return "The username doesn't seem to be valid.";
}

/* if the e-mail address is at an IP address (as opposed to a symbolic
host name) make sure the IP address is valid. */

var IPArray=domain.match(ipDomainPat);
if (IPArray!=null) {

// this is an IP address

for (var i=1;i<=4;i++) {
if (IPArray[i]>255) {
	
	return "Destination IP address is invalid!";
}
}
return "";
}

// Domain is symbolic name. Check if it's valid.

var atomPat=new RegExp("^" + atom + "$");
var domArr=domain.split(".");
var len=domArr.length;
for (i=0;i<len;i++) {
if (domArr[i].search(atomPat)==-1) {

	return "The domain name does not seem to be valid.";
}
}

/* domain name seems valid, but now make sure that it ends in a
known top-level domain (like com, edu, gov) or a two-letter word,
representing country (uk, nl), and that there's a hostname preceding
the domain or country. */

if (checkTLD && domArr[domArr.length-1].length!=2 &&
domArr[domArr.length-1].search(knownDomsPat)==-1) {
	
	return "The address must end in a well-known domain or two letter " + "country.";
}

// Make sure there's a host name preceding the domain.

if (len<2) {

	return "This address is missing a hostname!";
}

// If we've gotten this far, everything's valid!
return "";
}

// End -->