function selectNav() {
	path = window.location.pathname;
	page = path.substring(path.lastIndexOf('/') + 1);
	id = page.substring(0, page.indexOf('.php'));
	if (id == "" || id == "thanks") {
		id = "index";
	}
	if (id == "order2" || id == "order3") {
		id = "order";
	}
	document.getElementById(id).className = "selected";
	//document.getElementById(id).style.backgroundImage = "url(" + imgPath + imgArray[w][1] + ")";
}
window.onload=selectNav;

var xmlhttp;
d = document;

function xmlHTTPReq() {
        frm = d.forms[0];
        try {
                // Firefox, Opera 8.0+, Safari
                xmlhttp=new XMLHttpRequest();
        }
        catch (e) {
                // Internet Explorer
                try {
                        xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
                }
                catch (e) {
                        try {
                                xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
                        }
                        catch (e) {
                                //alert("Your browser does not support AJAX!");
                        }
                }
        }

        xmlhttp.open('post','form/contactus.php','false');
        xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");

	name = d.getElementById('name').value;
        email = d.getElementById('email').value;
	subject = d.getElementById('subject').value;
	body = d.getElementById('body').value;
        formData = "name=" + name + "&email=" + email + "&subject=" + subject + "&body=" + body;

        xmlhttp.onreadystatechange = handleresponse;
        xmlhttp.send(formData);
}

function handleresponse() {
        if(xmlhttp.readyState == 4) {
                if (xmlhttp.status == 200){
                        resDiv=d.getElementById('content');
                        var response = xmlhttp.responseText;
                        if(response!=true) {
				document.getElementById("contactus").style.display = "none";
                                resDiv.innerHTML = ""; 
                                resDiv.innerHTML = response;
				//alert(response);
                                return;
                        } else {
				//alert("Whoops...There Was An Error!");
                                resDiv.innerHTML = "Whoops...There Was An Error!";
                        }
                }
        }
}

function validEmail(email,msg) {
	with (email) {
		apos=email.indexOf("@");
		dotpos=email.lastIndexOf(".");
		if (apos<1||dotpos-apos<2) {
			alert(msg);
			return false;
		} else {
			return true;
		}
	}
}

function contactUs() {
        frm = d.forms[0];
	name = frm.name.value;
        email = frm.email.value;
	subject = frm.subject.value;
	body = frm.body.value;
	if (name == "") {
		alert("Please Enter Your Name!");
		frm.name.focus();
		return;
	}
	if (validEmail(email,"Please Enter a Valid E-mail Address!")==false) {
		frm.email.focus();
		return;
	}
	if (subject == "") {
		alert("Please Enter a Subject!");
		frm.subject.focus();
		return;
	}
	if (body == "") {
		alert("Please enter a Message!");
		frm.body.focus();
		return;
	}
        xmlHTTPReq();
}

function _openWin(wdth,hght,tp,lft,url,wName,scrollbar,resize) {
	if(!resize) resize="no";
	if(!scrollbar) scrollbar="no";
	xWin = window.open(url,wName,"width=" + wdth + ",height=" + hght + ",top=" + tp + ",left=" + lft + ",resizable=" + resize +",scrollbars=" + scrollbar );
}

function clearDefault(field) {
        document.getElementbyId(field).value = "";
}

function addLoadEvent(func) {
var oldonload = window.onload;
        if (typeof window.onload != 'function') {
                window.onload = func;
        } else {
                window.onload = function() {
                        if (oldonload) {
                                oldonload();
                        }
                func();
                }
        }
}

function loadAddFile(filename) {
	var fileref=d.createElement('script');
	fileref.setAttribute("type","text/javascript");
	fileref.setAttribute("src", filename);
	if (typeof fileref!="undefined") {
		d.getElementsByTagName("head")[0].appendChild(fileref);
	}
}
