/* ---------------------------- */
/* XMLHTTPRequest Enable */
/* ---------------------------- */
function createObjectf() {
var request_type;
var browser = navigator.appName;
if(browser == "Microsoft Internet Explorer"){
request_type = new ActiveXObject("Microsoft.XMLHTTP");
}else{
request_type = new XMLHttpRequest();
}
return request_type;
}

var http = createObjectf();


/* -------------------------- */
/* INSERT */
/* -------------------------- */
/* Required: var nocache is a random number to add to request. This value solve an Internet Explorer cache issue */
var nocache = 0;
function hideProcessingImg() {
	document.getElementById('usernameProcessingImg').style.display = "none";
}
function chkavail(pagename) {
	
// Optional: Show a waiting message in the layer with ID login_response
document.getElementById('chk_errorloc').innerHTML = ""

// Required: verify that all fileds is not empty. Use encodeURI() to solve some issues about character encoding.
nocache = Math.random();
if(pagename=='register'){
	//alert(document.register.username.value);
	var username= encodeURI(document.register.Username.value);
	http.open('post','http://www.ekriti.com/utilities/php/insert.php?ptype='+pagename+'&username='+username+'&nocache = '+nocache);
	hideProcessingImg();
}
if(pagename=='contact'){
	
var contact_name= encodeURI(document.getElementById('contact_name').value);
var contact_email= encodeURI(document.getElementById('contact_email').value);
var contact_no= encodeURI(document.getElementById('contact_no').value);
var contact_subject= encodeURI(document.getElementById('contact_subject').value);
var contact_massage= encodeURI(document.getElementById('contact_massage').value);

// Set te random number to add to URL request
// Pass the login variables like URL variable
http.open('get','contactus_form.php?ptype='+pagename+'&contact_name='+contact_name+'&contact_no='+contact_no+'&contact_subject='+contact_subject+'&contact_email='+contact_email+'&contact_massage='+contact_massage+'&nocache = '+nocache);
}

if(pagename=='query'){
	
var contact_name= encodeURI(document.getElementById('contact_name').value);
var contact_email= encodeURI(document.getElementById('contact_email').value);
var contact_query= encodeURI(document.getElementById('contact_query').value);
var contact_massage= encodeURI(document.getElementById('contact_massage').value);

// Set te random number to add to URL request
// Pass the login variables like URL variable
http.open('get','contactus_form.php?ptype='+pagename+'&contact_name='+contact_name+'&contact_query='+contact_query+'&contact_email='+contact_email+'&contact_massage='+contact_massage+'&nocache = '+nocache);
}
http.onreadystatechange = insertReplyc;
http.send(null);
}


function insertReplyc() {
if(http.readyState == 4){ 
var response = http.responseText;
var postion_error_word=(response.search(/error/));
document.getElementById('chk_errorloc').innerHTML =''+response;
// else if login is ok show a message: "Site added+ site URL".
}
}

function setUserNameVal($usernameVal) {
	if($usernameVal) {
		document.getElementById('Username').value = $usernameVal;
		document.getElementById('suggestionsBox').style.display = "none";
	}
}

function resetUsernameDivs() {
	document.getElementById('suggestionsBox').style.display = "none";
}