// JavaScript Document
var r={
	  'special':/[\W]/g,
	  'quotes':/['\''&'\"']/g,
	  'notnumbers':/[^\d]/g
	}

var httpxml = browserCheck(httpxml);
var nocache = 0;



function alertstateChanged() 
{ 
	 if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	 { 
		alert(xmlHttp.responseText);
	 } 
}

function getstateChanged() 
{ 
	 if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	 { 
		document.getElementById('btm_content').innerHTML=xmlHttp.responseText;
	 } 
}


function browserCheck() {
	try	{
		// Firefox, Opera 8.0+, Safari
		httpxml=new XMLHttpRequest();
	}
	catch (e) {
		// Internet Explorer
		try	{
			httpxml=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e) {
			try {
				httpxml=new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e) {
				alert("Your browser does not support AJAX!");
				return false;
			}
		}
	}
	return httpxml;
}

function ShowHideHintSearch(ID, val) {
	//alert(ID);
	var InputID = document.getElementById(ID);
	if(InputID.value == 'Search product...' || InputID.value == 'Your email address') {
		InputID.value = '';
		InputID.style.color = '#333333';
	}
}

function ShowHideHint(ID, val) {
	//alert(ID);
	var InputID = document.getElementById(ID);
	if(InputID.value == 'Search product...' || InputID.value == 'Enter mobile number' || InputID.value == 'Re-enter mobile number') {
		InputID.value = '';
		InputID.style.color = '#4C4C4C';
	}
}

function OnBlurHintSearch(ID, val) {
	var InputID = document.getElementById(ID);
	if(InputID.value == '') {
		switch(ID) {
			case 'search':
				InputID.value = 'Search product...';
				break;
			case 'newsletter':
				InputID.value = 'Your email address';
				break;
		}
		InputID.style.color = '#333333';
	}
}

function OnBlurHint(ID, val) {
	var InputID = document.getElementById(ID);
	if(InputID.value == '') {
		switch(ID) {
			case 'keyword':
				InputID.value = 'Search keyword...';
				break;
			case 'mobile_number':
				InputID.value = 'Enter mobile number';
				break;
			case 'cnf_mobile_number':
				InputID.value = 'Re-enter mobile number';
				break;
		}
		InputID.style.color = '#4C4C4C';
	}
}

function getById(ID) {
	var pt = document.getElementById(ID);
	return pt;
}

function SendContactEmail() { //alert("in");
	getById('EmailResponse').innerHTML = "Sending...";
	
	var name = getById('name').value;
	var address = getById('address').value;
	var email = getById('email').value;
	var query = getById('query').value;
	address.replace('&', 'and');
	query.replace('&', 'and');
	
	qstring = 'n='+name+'&ad='+address+'&em='+email+'&q='+query;
	nocache = Math.random(); //alert('send_email.php?action=send&'+qstring+'&nocache='+nocache);
	httpxml.open('get', 'send_email.php?action=send&'+qstring+'&nocache = '+nocache);
	httpxml.onreadystatechange = ContactEmailReply;
	httpxml.send(null);
}

function ContactEmailReply() { //alert('assas');
	if(httpxml.readyState == 4){
		var response = httpxml.responseText; //alert(response);
		if(response == '1')
			getById('EmailResponse').innerHTML = '<span style="color: #009933;">Your query has been sent to Businessland team</span>';
		else if(response == '-1')
			getById("EmailResponse").innerHTML = '<span style="color: #ff0000;">Could not send email</span>';
		else
			getById("EmailResponse").innerHTML = '<span style="color: #ff0000;">Please enter all required fields</span>';
	}
}
