/* ---------------------------- */
/* XMLHTTPRequest Enable */
/* ---------------------------- */
function createObject() {
	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 = createObject();

/* -------------------------- */
/* validate login name */
/* -------------------------- */
/* Required: var nocache is a random number to add to request. This value solve an Internet Explorer cache issue */
var nocache = 0;
function to_cart(id) {
	// Optional: Show a waiting message in the layer with ID login_response
	//document.getElementById('login_response').innerHTML = '<img src="images/loading.gif" alt="loading" />';
	
	// Required: verify that all fileds is not empty. Use encodeURI() to solve some issues about character encoding.
	//var message= encodeURI(document.getElementById('qsend').value);
	var amount = encodeURI(document.getElementById('item_'+id).value);
	// Set te random number to add to URL request
	nocache = Math.random();
	// Pass the login variables like URL variable
	http.open('get', 'js/cart.php?item_id='+id+'&amount='+amount+'&nocache = '+nocache);
	http.onreadystatechange = cartReply;
	http.send(null);
	
}
function cartReply() {
	if(http.readyState == 4){ 
		var response = http.responseText;
		// else if login is ok show a message: "Site added+ site URL".
		
		document.getElementById('cart_info').innerHTML = response;
		
	}
}
function send_msg(id) {
	// Optional: Show a waiting message in the layer with ID login_response
	//document.getElementById('msg_resp').innerHTML = '<img src="images/loading.gif" alt="loading" />';
	
	// Required: verify that all fileds is not empty. Use encodeURI() to solve some issues about character encoding.
	//var message= encodeURI(document.getElementById('qsend').value);
	var name = encodeURI(document.getElementById('name').value);
	var email = encodeURI(document.getElementById('email').value);
	var msg = encodeURI(document.getElementById('msg').value);
	// Set te random number to add to URL request
	nocache = Math.random();
	// Pass the login variables like URL variable
	http.open('get', 'js/send_msg.php?name='+name+'&email='+email+'&msg='+msg+'&nocache = '+nocache);
	http.onreadystatechange = msgReply;
	http.send(null);
	document.getElementById('req_table').style.visibility='hidden';

	
}
function msgReply() {
	if(http.readyState == 4){ 
		var response = http.responseText;
		// else if login is ok show a message: "Site added+ site URL".
		
		document.getElementById('msg_resp').innerHTML = response;
		
	}
}
function disable_enable(){
	if (document.all || document.getElementById){
		if (document.f1.dname.disabled==false){
			document.f1.dname.disabled=true;
			document.f1.daddress.disabled=true;
			document.f1.dcity.disabled=true;
			document.f1.dpost.disabled=true;
			document.f1.dphone.disabled=true;
			document.f1.demail.disabled=true;
		}
		else{
			document.f1.dname.disabled=false;
			document.f1.daddress.disabled=false;
			document.f1.dcity.disabled=false;
			document.f1.dpost.disabled=false;
			document.f1.dphone.disabled=false;
			document.f1.demail.disabled=false;
		}
	}
}
function request(){
	var item_id = encodeURI(document.getElementById('item').value);
	var name = encodeURI(document.getElementById('name').value);
	var city = encodeURI(document.getElementById('city').value);
	var phone = encodeURI(document.getElementById('phone').value);
	var email = encodeURI(document.getElementById('email').value);
	// Set te random number to add to URL request
	nocache = Math.random();
	// Pass the login variables like URL variable
	http.open('get', 'js/request.php?item_id='+item_id+'&name='+name+'&city='+city+'&phone='+phone+'&email='+email+'&nocache = '+nocache);
	http.onreadystatechange = requestReply;
	http.send(null);
}
function requestReply() {
	if(http.readyState == 4){ 
		var response = http.responseText;
		// else if login is ok show a message: "Site added+ site URL".
		document.getElementById('table').innerHTML = response;
	}
}

function get_news(){
	var email = encodeURI(document.getElementById('email').value);
	// Set te random number to add to URL request
	nocache = Math.random();
	// Pass the login variables like URL variable
	http.open('get', 'js/send.php?email='+email+'&nocache = '+nocache);
	http.onreadystatechange = get_newsReply;
	//document.getElementById('email').style.display ='none';
	//document.getElementById('b').style.display ='none';
	http.send(null);
}
function get_newsReply() {
	if(http.readyState == 4){ 
		var response = http.responseText;
		// else if login is ok show a message: "Site added+ site URL".
		document.getElementById('news_response').innerHTML = response;
	}
}