﻿function emailCheck (emailStr) {
var checkTLD=1;
var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;
var emailPat=/^(.+)@(.+)$/;
var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";
var validChars="\[^\\s" + specialChars + "\]";
var quotedUser="(\"[^\"]*\")";
var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
var atom=validChars + '+';
var word="(" + atom + "|" + quotedUser + ")";
var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
var matchArray=emailStr.match(emailPat);
if (matchArray==null) {
alert("Email address seems incorrect (check @ and .'s)");
return false;
}
var user=matchArray[1];
var domain=matchArray[2];
for (i=0; i<user.length; i++) {
if (user.charCodeAt(i)>127) {
alert("Ths username contains invalid characters.");
return false;
   }
}
for (i=0; i<domain.length; i++) {
if (domain.charCodeAt(i)>127) {
alert("Ths domain name contains invalid characters.");
return false;
   }
}
if (user.match(userPat)==null) {
alert("The username doesn't seem to be valid.");
return false;
}
var IPArray=domain.match(ipDomainPat);
if (IPArray!=null) {
for (var i=1;i<=4;i++) {
if (IPArray[i]>255) {
alert("Destination IP address is invalid!");
return false;
   }
}
return true;
}
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) {
alert("The domain name does not seem to be valid.");
return false;
   }
}
if (checkTLD && domArr[domArr.length-1].length!=2 && 
domArr[domArr.length-1].search(knownDomsPat)==-1) {
alert("The address must end in a well-known domain or two letter " + "country.");
return false;
}
if (len<2) {
alert("This address is missing a hostname!");
return false;
}
return true;
}
//----------------------------------------------------------------------------------------------------
function remove_XS_whitespace(item)
{
  var tmp = "";
  var item_length = item.value.length;
  var item_length_minus_1 = item.value.length - 1;
  for (index = 0; index < item_length; index++)
  {
    if (item.value.charAt(index) != ' ')
    {
      tmp += item.value.charAt(index);
    }
    else
    {
      if (tmp.length > 0)
      {
        if (item.value.charAt(index+1) != ' ' && index != item_length_minus_1)
        {
          tmp += item.value.charAt(index);
        }
      }
    }
  }
  item.value = tmp;
}
//----------------------------------------------------------------------------------------------------
function showSubscriptionBox()
{
	if(document.getElementById("SubscriptionBox").style.visibility=="visible")
	{
		document.getElementById("SubscriptionBox").style.visibility="hidden";
	}
	else
	{
		document.getElementById("SubscriptionBox").style.visibility="visible";
	}
//document.getElementById("SubscriptionBox").style.visibility="visible";
 document.getElementById("result").style.display="none";
}
function showSubscriptionBox2()
{
	if(document.getElementById("SubscriptionBox2").style.display=="block")
	{
		document.getElementById("SubscriptionBox2").style.display="none";
	}
	else
	{
		document.getElementById("SubscriptionBox2").style.display="block";
	}
 document.getElementById("result2").style.display="none";
}
//----------------------------------------------------------------------------------------------------
function sendSubScript(num)
{
	if(emailCheck(document.getElementById("reqMail").value)!=true)
	{
		document.getElementById("reqMail").focus();    
	}
   else
   {
	   sendMail(document.getElementById("reqMail").value,num,"header");
   }
}
function sendSubScript2(num)
{
	if(emailCheck(document.getElementById("reqMail2").value)!=true)
	{
		document.getElementById("reqMail2").focus();    
	}
   else
   {
	   sendMail(document.getElementById("reqMail2").value,num,"contact");
   }
}

//----------------------------------------------------------------------------------------------------
function sendMail(emailID,num,comefrom)
{
xHttp=GetXmlHttpObject();
if (xHttp==null) 
{alert("Your browser does not support Ajax");
return;
}


				var myvariable;				
				var pathArray;	
				var pathval;
				var pathcenter;
				
     			myvariable=window.location.pathname;
			    pathArray = myvariable.split( '/' );
				var address;
                try
                {
                pathcenter=pathArray[pathArray.length-2];
                }
                catch(er2){}
				if((pathcenter.toLowerCase()=="destinations") || (pathcenter.toLowerCase()=="sightseeing") || (pathcenter.toLowerCase()=="calsearch") || (pathcenter.toLowerCase()=="carparking")|| (pathcenter.toLowerCase()=="eurostar")|| (pathcenter.toLowerCase()=="flightandhotel")|| (pathcenter.toLowerCase()=="flights")|| (pathcenter.toLowerCase()=="fpowerTest")|| (pathcenter.toLowerCase()=="hotelonly")|| (pathcenter.toLowerCase()=="hotels") || (pathcenter.toLowerCase()=="insurance") || (pathcenter.toLowerCase()=="lounge"))
				{
					address="../subscript.aspx";
				}
				else
				{
					address="subscript.aspx";
				}

address=address+"?requiredMail="+emailID;
xHttp.onreadystatechange=function()
{
  if (xHttp.readyState==4)
    {
    	if (xHttp.status==200)
        {
			if(comefrom=="contact")
			{
				document.getElementById("result2").style.display="block";
              document.getElementById("SubscriptionBox2").style.display="none";
              document.getElementById("reqMail2").value="please enter your email"
			}
			else
			{
				document.getElementById("result").style.display="block";
              document.getElementById("SubscriptionBox").style.display="none";
              document.getElementById("reqMail").value="please enter your email"
			}
			
              
        }
    }
};
xHttp.open("GET",address,true);
xHttp.send(null); 
}
//----------------------------------------------------------------------------------------------------
function GetXmlHttpObject()
{
var xmlHttp=null;
try{xmlHttp=new XMLHttpRequest();}
catch (e){
try{xmlHttp=new  ActiveXObject("Msxml2.XMLHTTP");}
catch(e){xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");}
}return xmlHttp;}
//----------------------------------------------------------------------------------------------------
