// JavaScript Document
// End date validation ------------------------------------->

function emailCheck(emailStr, skipMsgs) {
    if (!skipMsgs){
        skipMsgs = false;
    }
    /* 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. */
        if (skipMsgs!=true){
            alert("Email address seems incorrect (check @ and .'s)")
        }
        return false
    }
    var user=matchArray[1]
    var domain=matchArray[2]
    
    // See if "user" is valid
    if (user.match(userPat)==null) {
        // user is not valid
        if (skipMsgs!=true){
            alert("The username doesn't seem to be valid.")
        }
        return false
    }
    
    //check for characters that are not allowed in email address
     var iChars = "!$%^~&*()+=[]\\\';,/{}|\":<>`?";

      for (var i = 0; i < emailStr.length; i++)
        {
        if (iChars.indexOf(emailStr.charAt(i)) != -1)
        {
            if (skipMsgs!=true){
                alert("Email address doesn't seem to be valid.")
            }
            return false;
        }
      }
    
    /* 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) {
                if (skipMsgs!=true){
                    alert("Destination IP address is invalid!")
                }
                return false
            }
        }
        return true
    }
    
    // Domain is symbolic name
    var domainArray=domain.match(domainPat)
    if (domainArray==null) {
        if (skipMsgs!=true){
            alert("The Domain Name doesn't seem to be valid.")
        }
        return false
    }
    
    /* domain name seems valid, but now make sure that it ends in a
       three-letter word (like com, edu, gov) or a two-letter word,
       representing country (uk, nl), and that there's a hostname preceding
       the domain or country. */
    
    /* Now we need to break up the domain to get a count of how many atoms
       it consists of. */
    var atomPat=new RegExp(atom,"g")
    var domArr=domain.match(atomPat)
    var len=domArr.length
    if (domArr[domArr.length-1].length<2 ||
        domArr[domArr.length-1 ].length>3) {
       // the address must end in a two letter or three letter word.
        if (skipMsgs!=true){
           alert("The address must end in a three-letter domain, or two letter country.")
        }
       return false
    }
    
    // Make sure there's a host name preceding the domain.
    if (len<2) {
        if (skipMsgs!=true){
           var errStr="This E-mail address is missing a hostname!";
           alert(errStr);
        }
       return false
       }
       // If we've gotten this far, everything's valid!
    return true       
}
// end o

function GetXmlHttpObject()
{
var xmlHttp=null;
try
 {
 // Firefox, Opera 8.0+, Safari
 xmlHttp=new XMLHttpRequest();
 }
catch (e)
 {
 //Internet Explorer
 try
  {
  xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
  }
 catch (e)
  {
  xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
 }
return xmlHttp;
}

function AdvancedSearch() {
	//document.getElementById('areaP').style.display='block';
	document.getElementById('PriceP').style.display='none';
	
	document.getElementById('property-search').innerHTML='Advanced Search';
	document.getElementById('AdvancedSearch').innerHTML='- <a href="javascript:PropertySearch();">Close</a>';
	document.getElementById('advanced-search').style.display='block';
	}
function PropertySearch() {
	
	//	document.getElementById('areaP').style.display='none';
	document.getElementById('PriceP').style.display='block';

	document.getElementById('property-search').innerHTML='Property Search';
	document.getElementById('AdvancedSearch').innerHTML='+ <a href="javascript:AdvancedSearch();">Advanced Search</a>';
	document.getElementById('advanced-search').style.display='none';
	}

function SubmitBlue()
{
	var x = getElementsByClass('SubmitBlue',null,'input');
	for (var i=0;i<x.length;i++)
	{
		x[i].onmouseover = function () {this.style.backgroundPosition='0 -26px';}
		//x[i].onmousedown = function () {this.style.backgroundPosition='0 -52px';}
		x[i].onmouseout = function () {this.style.backgroundPosition='0 0';}

	}
}
function getElementsByClass(searchClass,node,tag) {
	var classElements = new Array();
	if ( node == null )
		node = document;
	if ( tag == null )
		tag = '*';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;

	var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
	for (i = 0, j = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].className) ) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}
function subMenu(){
	document.getElementById('Link-Lifestyle').onmouseover = function () {document.getElementById('subMenu').style.display='block';}
	document.getElementById('Link-Lifestyle').onmouseout = function () {document.getElementById('subMenu').style.display='none';}
	document.getElementById('subMenu').onmouseover = function () {this.style.display='block';}
	document.getElementById('subMenu').onmouseout = function () {this.style.display='none';}

}

function subMenu(){
	document.getElementById('Link-Lifestyle').onmouseover = function () {document.getElementById('subMenu').style.display='block';}
	document.getElementById('Link-Lifestyle').onmouseout = function () {document.getElementById('subMenu').style.display='none';}
	document.getElementById('subMenu').onmouseover = function () {this.style.display='block';}
	document.getElementById('subMenu').onmouseout = function () {this.style.display='none';}

}

function mail_f(box) {
	id_1 = 'mail_a_'+box;
	id_2 = "mail_f_"+box;
	document.getElementById(id_2).style.display='block';
	document.getElementById(id_1).style.display='none';
	//document.getElementById("rightSection").style.height = "600"
}

function mail_f_1(box) {
	id_1 = 'mail_a_'+box;
	id_2 = "mail_f_"+box;
	document.getElementById(id_1).style.display='block';
	document.getElementById(id_2).style.display='none';
	//document.getElementById("rightSection").style.height = "400"
}

function mail_f_2(box) {
	id_1 = 'mail_a_'+box;
	id_2 = "mail_f_"+box;
	id_3 = "mail_b_"+box;
	document.getElementById(id_3).style.width='220px';
	document.getElementById(id_2).style.display='block';
	document.getElementById(id_1).style.display='none';
}
function mail_f_2_1(box) {
	id_1 = 'mail_a_'+box;
	id_2 = "mail_f_"+box;
	id_3 = "mail_b_"+box;
	document.getElementById(id_3).style.width='150px';
	document.getElementById(id_1).style.display='block';
	document.getElementById(id_2).style.display='none';
}

function addTextEmail()
{
  document.getElementById("email_id").value = "Enter Your Email.";
}
function removeTextEmail(id)
{
  document.getElementById(id).value = "";
}

function addText(id,code)
{
	if(document.getElementById(id).value == '')
  document.getElementById(id).value = code;
}

function Toggle()
{
	document.getElementById("newsletter_id").value = "Sent"	   	
}


function addEmail(em){


document.getElementById("newsletter_id").value = "Please wait.."	
if(!emailCheck(em.value)){
	em.focus()
	return false
	}else{
	
	xmlhttp = GetXmlHttpObject()
	
			
	xmlhttp.onreadystatechange = function (){
	if(xmlhttp.readyState == 4)
	{	
		
		
		
		setTimeout('Toggle()',3000);
document.getElementById("newsletterform").onsubmit = returnfalse

		em.value = ''
		}
		
	}
	xmlhttp.open("GET","NewsletterAdd.php?em="+em.value,true);
	xmlhttp.send(null)
	

	}
return false
}

function returnfalse(){
	return false;
	}