function addquestion_vali(submit){
	error=0;
	if(checkEmailAddress(document.getElementById('email_q'),'Y')==false ){
		document.getElementById('email_q').style.border="1px solid #FF0000";
		error=1;
	}else{
		document.getElementById('email_q').style.border="1px solid #00FF00";
	}
	if(document.getElementById('name_q').value==''){
		document.getElementById('name_q').style.border="1px solid #FF0000";
		error=1;
	}else{
		document.getElementById('name_q').style.border="1px solid #00FF00";
	}
	if(document.getElementById('question').value==''){
		document.getElementById('question').style.border="1px solid #FF0000";
		error=1;
	}else{
		document.getElementById('question').style.border="1px solid #00FF00";
	}
	
	if(error==0){
		var name_q=document.getElementById('name_q').value;
		var email_q=document.getElementById('email_q').value;
		var question_q=document.getElementById('question').value;
		var productid;
		var cat=0;
		if(document.getElementById('productid'))
		productid=document.getElementById('productid').value;
		
		if(document.getElementById('cat'))
		cat=document.getElementById('cat').value;
		if(submit!='Y')	{	
		values="question="+question_q+"&related_tags=Y&target=HQ_products";
		search_questions("add_question_product.php","search_result",values);
		
		}
		if(submit=='Y'){// Submit form value to the database
			parameters="name_q="+name_q+"&email_q="+email_q+"&target=HQ_products&question="+question_q+"&productid="+productid+"&categoryid="+cat+"&mode=add&redirect_must=Y&close_popup=Y";
			addquestion_ajax("add_question_product.php",'question_form_response',parameters);
//		document.getElementById('question').value='';
		}
	
	}

} 

function search_questions(serverScript, insert, parameters) {
	var xmlHttp;

	try {
		// Firefox, Opera 8.0+, Safari
		xmlHttp = new XMLHttpRequest();
	} catch (e) {
		// Internet Explorer 6+
		try {
			xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			// Internet Eplorer 5
			try {
				xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {
				alert("Your browser does not support AJAX. Download a newer browser to view this page.");
				return false;
			}
		}
	}

	// insert server response into HTML element
	xmlHttp.onreadystatechange = function() {
		if (xmlHttp.readyState == 4) {
			if (xmlHttp.status == 200) {
				document.getElementById(insert).innerHTML=xmlHttp.responseText;
				document.getElementById('showthis').style.display='none';
				document.getElementById('search_again').style.display='inline';
				document.getElementById('hidethis').style.display='inline';
			} else {
				alert("There was a problem while using XMLHTTP:\n"
						+ xmlHttp.statusText);
			}

		}
	}

	xmlHttp.open("POST", serverScript, true);
	xmlHttp.setRequestHeader('Content-type','application/x-www-form-urlencoded');
	xmlHttp.setRequestHeader('Content-length', parameters.length);
	xmlHttp.setRequestHeader('Connection', 'close');
	xmlHttp.send(parameters);
}


function addquestion_ajax(serverScript, insert, parameters) {
	var xmlHttp;

	try {
		// Firefox, Opera 8.0+, Safari
		xmlHttp = new XMLHttpRequest();
	} catch (e) {
		// Internet Explorer 6+
		try {
			xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			// Internet Eplorer 5
			try {
				xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {
				alert("Your browser does not support AJAX. Download a newer browser to view this page.");
				return false;
			}
		}
	}

	// insert server response into HTML element
	xmlHttp.onreadystatechange = function() {
		if (xmlHttp.readyState == 4) {
			if (xmlHttp.status == 200) {
				//alert(xmlHttp.responseText);
				document.getElementById(insert).style.display='inline';
				document.getElementById(insert).innerHTML=xmlHttp.responseText;
				//
				//document.getElementById('questionform').style.display='none';
			} else {
				alert("There was a problem while using XMLHTTP:\n"
						+ xmlHttp.statusText);
			}

		}
	}

	xmlHttp.open("POST", serverScript, true);
	xmlHttp.setRequestHeader('Content-type','application/x-www-form-urlencoded');
	xmlHttp.setRequestHeader('Content-length', parameters.length);
	xmlHttp.setRequestHeader('Connection', 'close');
	xmlHttp.send(parameters);
}


function addquestion_main(){
	error=0;
	if(checkEmailAddress(document.getElementById('email_q'),'Y')==false ){
		document.getElementById('email_q').style.border="1px solid #FF0000";
		error=1;
	}else{
		document.getElementById('email_q').style.border="1px solid #00FF00";
	}
	if(document.getElementById('name_q').value==''){
		document.getElementById('name_q').style.border="1px solid #FF0000";
		error=1;
	}else{
		document.getElementById('name_q').style.border="1px solid #00FF00";
	}
	if(document.getElementById('question').value==''){
		document.getElementById('question').style.border="1px solid #FF0000";
		error=1;
	}else{
		document.getElementById('question').style.border="1px solid #00FF00";
	}
	
	if(error==0){
		document.askquestion.submit();
	}
}

function update_view(serverScript,parameters){

	var xmlHttp;

	try {
		// Firefox, Opera 8.0+, Safari
		xmlHttp = new XMLHttpRequest();
	} catch (e) {
		// Internet Explorer 6+
		try {
			xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			// Internet Eplorer 5
			try {
				xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {
				alert("Your browser does not support AJAX. Download a newer browser to view this page.");
				return false;
			}
		}
	}

	// insert server response into HTML element
	xmlHttp.onreadystatechange = function() {
		if (xmlHttp.readyState == 4) {
			if (xmlHttp.status == 200) {
//	alert(xmlHttp.responseText);
			} else {
				alert("There was a problem while using XMLHTTP:\n"
						+ xmlHttp.statusText);
			}

		}
	}

	xmlHttp.open("POST", serverScript, true);
	xmlHttp.setRequestHeader('Content-type','application/x-www-form-urlencoded');
	xmlHttp.setRequestHeader('Content-length', parameters.length);
	xmlHttp.setRequestHeader('Connection', 'close');
	xmlHttp.send(parameters);

} 
function showans(questionid,total,real_qid){

	for (var i=0;i<total;i++){
		document.getElementById('divid_'+i).style.display="none";
	}
	document.getElementById('divid_'+questionid).style.display="inline";
	var parameters="questionid="+real_qid+"&update_view=Y";
	update_view('health_answers.php',parameters);

	}

function select_subcat(catid,divid,page){

	var parameters="catid="+catid+"&page1="+page+"&hq_catselect=Y";
	category_selector('health_answers.php',parameters,divid);
//	document.getElementById(divid).style.display="inline";
	
}
function category_selector(serverScript,parameters,divid){

	var xmlHttp;

	try {
		// Firefox, Opera 8.0+, Safari
		xmlHttp = new XMLHttpRequest();
	} catch (e) {
		// Internet Explorer 6+
		try {
			xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			// Internet Eplorer 5
			try {
				xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {
				alert("Your browser does not support AJAX. Download a newer browser to view this page.");
				return false;
			}
		}
	}

	// insert server response into HTML element
	xmlHttp.onreadystatechange = function() {
		if (xmlHttp.readyState == 4) {
			if (xmlHttp.status == 200) {
				document.getElementById(divid).style.display="inline";
//				var k=document.getElementById(divid).innerHTML;
//			alert(document.getElementById(fillid).innerHTML);
				document.getElementById(divid).innerHTML=xmlHttp.responseText;
//				document.getElementById(divid).innerHTML=k;
				
			} else {
				alert("There was a problem while using XMLHTTP:\n"
						+ xmlHttp.statusText);
			}

		}
	}

	xmlHttp.open("POST", serverScript, true);
	xmlHttp.setRequestHeader('Content-type','application/x-www-form-urlencoded');
	xmlHttp.setRequestHeader('Content-length', parameters.length);
	xmlHttp.setRequestHeader('Connection', 'close');
	xmlHttp.send(parameters);

} 


