function ShowEntryForm(iFileNo, sType) {
	document.getElementById("divBG").style.width = document.body.offsetWidth + "px";
	document.getElementById("divBG").style.height = document.body.offsetHeight + "px";
	document.getElementById("divBG").style.display = "block";
	if (document.getElementById("select1") != null)	document.getElementById("select1").style.visibility = "hidden";
	if (document.getElementById("select2") != null)	document.getElementById("select2").style.visibility = "hidden";
	document.getElementById("hidFileNo").value = iFileNo;
	document.getElementById("hidType").value = sType;
	showDivCenter("divDetailsForm", true);
}
	
function CloseEntryForm() {
	document.getElementById("divBG").style.width = "0px";
	document.getElementById("divBG").style.height = "0px";
	document.getElementById("divBG").style.display = "none";
	if (document.getElementById("select1") != null)	document.getElementById("select1").style.visibility = "visible";
	if (document.getElementById("select2") != null)	document.getElementById("select2").style.visibility = "visible";	
	document.getElementById("hidFileNo").value = 0;	
	document.getElementById("hidType").value = "";
	showDivCenter("divDetailsForm", false);
}
	
function showDivCenter(divid, bFlag) { 
    var o = document.getElementById(divid); 
    var r = o.style;
    var Xwidth = r.width.replace("px", "");
    var Yheight = r.height.replace("px", "");
    if (bFlag) {
        var scrolledX, scrolledY; 
        if (self.pageYoffset) { 
            scrolledX = self.pageXoffset; 
            scrolledY = self.pageYoffset; 
        } else if (document.documentElement && document.documentElement.scrollTop) { 
            scrolledX = document.documentElement.scrollLeft; 
            scrolledY = document.documentElement.scrollTop; 
        } else if (document.body) { 
            scrolledX = document.body.scrollLeft; 
            scrolledY = document.body.scrollTop; 
        } 

        // Next, determine the coordinates of the center of browser's window 

        var centerX, centerY; 
        if (self.innerHeight) { 
            centerX = self.innerWidth; 
            centerY = self.innerHeight; 
        } else if (document.documentElement && document.documentElement.clientHeight) { 
            centerX = document.documentElement.clientWidth; 
            centerY = document.documentElement.clientHeight; 
        } else if (document.body) { 
            centerX = document.body.clientWidth; 
            centerY = document.body.clientHeight; 
        } 

        var leftoffset = scrolledX + (centerX - Xwidth) / 2; 
        var topoffset = scrolledY + (centerY - Yheight) / 2; 
	               
        r.position = 'absolute'; 
        r.top = topoffset + 'px'; 
        r.left = leftoffset + 'px'; 
        r.display = "block"; 
    } else {
        r.display = "none"; 
    }
} 
	
function sendDetails() {
	var txtFullName, txtCompName, txtTitle, txtEmail, txtPhone;
		
	txtFullName = document.getElementById("txtFullName");
	txtCompName = document.getElementById("txtCompName");
	txtTitle = document.getElementById("txtTitle");
	txtEmail = document.getElementById("txtEmail");
	txtPhone = document.getElementById("txtPhone");
		
	var sFullName, sCompName, sTitle, sEmail, sPhone;
		
	sFullName = trim(txtFullName.value);
	sCompName = trim(txtCompName.value);
	sTitle = trim(txtTitle.value);
	sEmail = trim(txtEmail.value);
	sPhone = trim(txtPhone.value);
		
	if (sFullName == "") {
		alert("Please enter your Full Name.");
		txtFullName.focus();
		return false;
	}
		
	if (sCompName == "") {
		alert("Please enter your Company Name.");
		txtCompName.focus();
		return false;
	}
		
	if (sEmail == "") {
		alert("Please enter your Email Address.");
		txtEmail.focus();
		return false;
	}
	else if (!checkEmail(sEmail)) {
		alert("Invalid Email Address.");
		txtEmail.focus();
		return false;
	}
		
	var xmlHttp;
	try	{xmlHttp = new XMLHttpRequest();}
	catch (e) {try {xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");}catch (e){try {xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");}catch (e) {alert("Your browser does not support AJAX!");return false;}}}
	xmlHttp.onreadystatechange = function() {
	    if(xmlHttp.readyState == 4) {
	        var sResponseText = xmlHttp.responseText;
	        if (sResponseText != "Failure") {
			alert("Thank you for providing the information.");
			clearFields();
			window.open(sResponseText);
	        }
	    }
	}
	var requestURL = "cs_mail.asp?FN=" + sFullName;
	requestURL += "&CN=" + sCompName;
	requestURL += "&TL=" + sTitle;
	requestURL += "&EM=" + sEmail;
	requestURL += "&PH=" + sPhone;
	requestURL += "&NO=" + document.getElementById("hidFileNo").value;
	requestURL += "&Type=" + document.getElementById("hidType").value;
	xmlHttp.open("GET", requestURL, true);
	xmlHttp.send(null); 
}
	
function clearFields() {
	document.getElementById("txtFullName").value = "";
	document.getElementById("txtCompName").value = "";
	document.getElementById("txtTitle").value = "";
	document.getElementById("txtEmail").value = "";
	document.getElementById("txtPhone").value = "";
	CloseEntryForm();
}
	
function trim(sString) {
	if (sString != null) {
        while (sString.substring(0,1) == ' ')
            sString = sString.substring(1, sString.length);
        while (sString.substring(sString.length-1, sString.length) == ' ')
            sString = sString.substring(0,sString.length-1);
        return sString;
    }
    else {
        return "";
    }
}
	
function OnlyEmail(obj, evt) {
    var charCode = evt.which;
    if (typeof(charCode) == "undefined") charCode = evt.keyCode;
    if ((charCode == 0) || (charCode >= 48 && charCode <= 57) || (charCode >= 65 && charCode <= 90) || (charCode >= 97 && charCode <= 122) || (charCode == 45) || (charCode == 95) || (charCode == 8)) {
        return true; 
    }
    else if (charCode == 46) {
        if (obj.value.lastIndexOf(".") != (obj.value.length - 1))
            return true;
    }
    else if (charCode == 64) {
        if (obj.value.indexOf("@") == -1)
            return true;
    }
    return false;
}

function onlyPhoneNumbers(evt) {
    var charCode = evt.which;
    if (typeof(charCode) == "undefined") charCode = evt.keyCode;
    if ((charCode > 47 && charCode < 58) || (charCode == 32) || (charCode == 43) || (charCode == 44) || (charCode == 45) || (charCode == 8) || (charCode == 0))
        return true;
    else
        return false;
}

function checkEmail(strEmail){
    var filter = /^.+@.+\..{2,3}$/;
    if (filter.test(strEmail))
        return true;
    else 
        return false
}