function createRequestObject() {
  var ro;
  var browser = navigator.appName;
  if(browser == "Microsoft Internet Explorer"){
     ro = new ActiveXObject("Microsoft.XMLHTTP");
  }else{
     ro = new XMLHttpRequest();
  }
  return ro;
}

var http = createRequestObject();

var pos; // variable for posting information
function loadXMLPosDoc(url,posData) {
    // branch for native XMLHttpRequest object
    if (window.XMLHttpRequest) {
        pos = new XMLHttpRequest();
        pos.onreadystatechange = processPosChange;
        pos.open("POST", url, false);
		pos.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
        pos.send(posData);
    // branch for IE/Windows ActiveX version
    } else if (window.ActiveXObject) {
        pos = new ActiveXObject("Microsoft.XMLHTTP");
        if (pos) {
            pos.onreadystatechange = processPosChange;
            pos.open("POST", url, false);
			pos.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
            pos.send(posData);
        }
    }
}


function processPosChange() {
  // page loaded "complete"
  if (pos.readyState == 4) {
    var response = pos.responseText;
    var update = new Array();

    if(response.indexOf('|' != -1)) {
      update = response.split('|');
      document.getElementById(update[0]).innerHTML = update[1];
    }
  }
}


function replaceChars(str){
  str = str.replace(/&/g,"**am**");
  str = str.replace(/=/g,"**eq**");
  str = str.replace(/\+/g,"**pl**");
 
  return str;
}


function submitform(){
  var page = "newsletter_process.php?action=send";

  var email = document.newsletterform.email.value;
  var msg = (document.newsletterform.unsubscribe.checked)?'YES':'NO';


  if(ValidateForm()){
    document.newsletterform.send.disabled=true; 
    document.newsletterform.send.value='Sending....';

    email = replaceChars(email);

    var stuff = "email="+email+"&unsubscribe="+msg;
    loadXMLPosDoc(page,stuff)
  }
}


function submitPropContactForm(){
  var page = "propcontact_process.php?action=send";

  var PropName = document.propcontactfrm.PropName.value;
  var PropEmail = document.propcontactfrm.PropEmail.value;
  var PropPhone = document.propcontactfrm.PropPhone.value;
  var PropID = document.propcontactfrm.PropID.value;  

  if(ValidatePropContactForm()){
    document.propcontactfrm.send.disabled=true; 
    document.propcontactfrm.send.value='Sending....';

    PropName = replaceChars(PropName);
    PropEmail = replaceChars(PropEmail);
    PropPhone = replaceChars(PropPhone);
    PropID = replaceChars(PropID);
  
    var stuff = "PropName="+PropName+"&PropEmail="+PropEmail+"&PropPhone="+PropPhone+"&PropID="+PropID;
    loadXMLPosDoc(page,stuff)
  }
}



function echeck(str) {

var at="@";
var dot=".";
var lat=str.indexOf(at);
var lstr=str.length;
var ldot=str.indexOf(dot);
if (str.indexOf(at)==-1){
   alert("Invalid E-mail address");
   return false;
}

if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
   alert("Invalid E-mail address");
   return false;
}

if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
    alert("Invalid E-mail address");
    return false;
}

 if (str.indexOf(at,(lat+1))!=-1){
    alert("Invalid E-mail address");
    return false;
 }

 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
    alert("Invalid E-mail address");
    return false;
 }

 if (str.indexOf(dot,(lat+2))==-1){
    alert("Invalid E-mail address");
    return false;
 }

 if (str.indexOf(" ")!=-1){
    alert("Invalid E-mail address");
    return false;
 }

 return true;
}

function ValidateForm(){
var emailID = document.newsletterform.email;

if ((emailID.value==null)||(emailID.value=="")){
	alert("Please Enter your Email address");
	emailID.focus();
	return false;
}
if (echeck(emailID.value)==false){
	emailID.value="";
	emailID.focus();
	return false;
}
return true;
}


function ValidatePropContactForm(){
var NameDtl=document.propcontactfrm.PropName
var emailID=document.propcontactfrm.PropEmail

if ((NameDtl.value==null)||(NameDtl.value=="")){
	alert("Please Enter your Name")
	NameDtl.focus()
	return false
}
if ((emailID.value==null)||(emailID.value=="")){
	alert("Please Enter your Email address")
	emailID.focus()
	return false
}
if (echeck(emailID.value)==false){
	emailID.value=""
	emailID.focus()
	return false
}
return true
}



