function popUp(fileName) {
    myFloater = window.open('','myWindow','directories=yes,toolbar=yes,menubar=yes,location=yes,resizable=yes,scrollbars=yes,status=yes')
    myFloater.location.href = fileName;
    return false
}

function encodeHtml(htmlVar) {
     encodedHtml = escape(htmlVar);
     encodedHtml = encodedHtml.replace(/\//g,"%2F");
     encodedHtml = encodedHtml.replace(/\?/g,"%3F");
     encodedHtml = encodedHtml.replace(/=/g,"%3D");
     encodedHtml = encodedHtml.replace(/&/g,"%26");
     encodedHtml = encodedHtml.replace(/@/g,"%40");
     return encodedHtml;
}

function verifyEmail(emailID) { 
    if ((emailID.value==null)||(emailID.value=="")){
        return true
    }
	if (echeck(emailID.value)==false){
	    emailID.value=""
	    emailID.focus()
		return false
	}
	return true
}

function submitDateRequest(dateForm) {
    if (verifyEmail(dateForm.senderEmail)) {
        var contactType = dateForm.contactMethod[1].value;
        if (dateForm.contactMethod[0].checked) {
            contactType = dateForm.contactMethod[0].value;
        }
        
        var a = 'datesAction.php?senderName=' + encodeHtml(dateForm.senderName.value) + 
                                '&senderEmail=' + encodeHtml(dateForm.senderEmail.value) +
                                '&senderPhone=' + encodeHtml(dateForm.senderPhone.value) + 
                                '&contactMethod=' + encodeHtml(contactType) + 
                                '&eventDescription=' + encodeHtml(dateForm.eventDescription.value) + 
                                '&theDate=' + encodeHtml(dateForm.theDate.value);
        
        doAjaxAction(a);
    }
}

function submitContactForm(contactForm) {
  if (verifyEmail(contactForm.senderEmail)) {
  
    var a = 'contactAction.php?senderName=' + encodeHtml(contactForm.senderName.value) + 
                              '&senderEmail=' + encodeHtml(contactForm.senderEmail.value) +
                              '&emailMessage=' + encodeHtml(contactForm.emailMessage.value);
                              
    doAjaxAction(a);                
  }    
}

/**
  * DHTML email validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
  */

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 ID")
		return false
	}

	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
	    alert("Invalid E-mail ID")
		return false
	}

	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
	    alert("Invalid E-mail ID")
		return false
	}

	if (str.indexOf(at,(lat+1))!=-1){
	    alert("Invalid E-mail ID")
		return false
    }

	if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
	    alert("Invalid E-mail ID")
		return false
    }

	if (str.indexOf(dot,(lat+2))==-1){
	    alert("Invalid E-mail ID")
		return false
    }
		
	if (str.indexOf(" ")!=-1){
	    alert("Invalid E-mail ID")
		return false
    }

 	return true					
}

function doAjaxAction(phpFile) {
    xmlHttp=GetXmlHttpObject()

    if (xmlHttp==null) {
        document.getElementById("infoBar").innerHTML="Browser does not support HTTP Request"
        return
    }

    var url=phpFile
    xmlHttp.onreadystatechange=stateChanged 
    xmlHttp.open("GET",url,true)
    xmlHttp.send(null)
}

function doImageAjaxAction(phpFile) {
	xmlHttp=GetXmlHttpObject()

    if (xmlHttp==null) {
        document.getElementById("infoBar").innerHTML="Browser does not support HTTP Request"
        return
    }

    var url=phpFile
    xmlHttp.onreadystatechange=imageStateChanged 
    xmlHttp.open("GET",url,true)
    xmlHttp.send(null)
}

function stateChanged() { 
    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") { 
        var temp1 = document.getElementById("imageData");
        temp1.innerHTML="" 
        
        var temp = document.getElementById("pageData");
        temp.innerHTML=xmlHttp.responseText 
    } 
}

function imageStateChanged() { 
    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") { 
        var temp = document.getElementById("pageData");
        temp.innerHTML=xmlHttp.responseText 
        
        var x = temp.getElementsByTagName("script");   
        for(var i=0;i<x.length;i++)  
        {
            alert(x[i].text);
            eval(x[i].text);  
        }
    } 
}

function GetXmlHttpObject() {
    var xmlHttp=null;
    try {
        // Firefox, Opera 8.0+, Safari
        xmlHttp=new XMLHttpRequest();
    }
    catch (e) {
        try {
            // Internet Explorer 6 and later 
            xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch (e) {
            // Internet Explorer 5.5 
            xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
    }
    return xmlHttp;
}

 
