var regmails = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9-]+\.[a-zA-Z.]{2,6}$/;
var regNum = /^[0-9]+$/;
var regAlias = /^[a-zA-Z0-9_]+$/;
// JavaScript Document

var timeout=100;
var closetimer=0;
var ddmenuitem=0;
function mopen(id) {	
	mcancelclosetime();
	if(ddmenuitem) {
		ddmenuitem.style.visibility = 'hidden';
	}
	ddmenuitem = document.getElementById(id);
	ddmenuitem.style.visibility = 'visible';
}
function mclose() {
	if(ddmenuitem) {
		ddmenuitem.style.visibility = 'hidden';
	}
}
function mclosetime() {
	closetimer = window.setTimeout(mclose, timeout);
}
function mcancelclosetime() {
	if(closetimer) {
		window.clearTimeout(closetimer);
		closetimer = null;
	}
}
document.onclick = mclose;


function read_family_news(id, res_id) {
	for(var i=0; i<=5; i++) {
		if(window.document.getElementById("fnews_read"+i)) {
			window.document.getElementById("fnews_read"+i).innerHTML="";
		}
	}
	var url="common/get_processes_admin.php?fnewsid="+id;
	openConnection(url, "fnews_read"+res_id)
}

function check_common_feedback() {
	with(window.document.frm_nehmeh_enquery) {
		if(isEmpty(name, "Please enter you Name.")) {
			return false;
		} else if(isEmpty(company, "Please enter your Company Name.")) {
			return false;
		} else if(isEmpty(email, "Please enter your Email.")) {
			return false;
		} else if(isEmail(email, "Please enter you valid Email.")) {
			return false;
		}
	}
}

function remove_autocom() {
	if(window.document.getElementById("res_autocomplete")) {
		if(document.getElementById("res_autocomplete").className=='resauto_complete') {
			document.getElementById("res_autocomplete").className='resautocomplete';
		}
	}
}

function input_autocomplete(val) {
	window.document.getElementById("quicksearch").value=val;
	document.getElementById("res_autocomplete").className='resautocomplete';
	window.document.getElementById("quicksearch").focus();
}

function open_autocomplete(val, evnt) {
	if(evnt==13) {
		if(val=="") {
			alert("Please enter the Itemcode and press enter.");
			window.document.getElementById("quicksearch").focus();
		} else {
			self.location="index.php?rout=build%2Fall_products&do=search&category=&brand=&item_code="+val+"&product=&country=&manufacturer=&scope=&criteria=OR&btn_search_prod=Search";
		}
	}
	if(val!="") {
		document.getElementById("res_autocomplete").className='resauto_complete';
		var url="common/get_processes_admin.php?itemcode_complete="+val;
		openConnection(url, "res_autocomplete")
	} else {
		document.getElementById("res_autocomplete").className='resautocomplete';
	}
}

function check_cart_form() {
	with(window.document.frm_product_cart) {
		if(isEmpty(name, "Please enter your full name.")) {
			return false;
		} else if(isEmpty(company, "Please enter your company name.")) {
			return false;
		} else if(isEmpty(contact, "Please enter your contact number.")) {
			return false;
		} else if(isEmpty(email, "Please enter your email id.")) {
			return false;
		} else if(isEmail(email, "Please enter your valid email id.")) {
			return false;
		}
	}
}
function isNumberKey(evt) {
	var charCode = (evt.which) ? evt.which : event.keyCode
	if (charCode > 31 && (charCode < 48 || charCode > 57)) {
		return false;
	} else {
		return true;
	}
}

function place_cart_enquiry_form() {
	window.document.getElementById("cart_enquiry_box").innerHTML='<table align="center" width="690" border="0" cellpadding="2" cellspacing="1" bgcolor="#f1f1f1" class="text"><tr bgcolor="#ffffff"><td width="200" height="25" bgcolor="#ffffff">Full Name *</td><td width="490" bgcolor="#ffffff"><input name="name" type="text" class="feedback_txt" id="name" size="35" /></td></tr><tr bgcolor="#ffffff"><td height="25" bgcolor="#ffffff">Company Name *</td><td><input name="company" type="text" class="feedback_txt" id="company" size="35" /></td></tr><tr bgcolor="#ffffff"><td height="25" bgcolor="#ffffff">Designation</td><td><input name="designation" type="text" class="feedback_txt" id="designation" size="25" /></td></tr><tr bgcolor="#ffffff"><td height="25" bgcolor="#ffffff">Contact Number *</td><td><input name="contact" type="text" class="feedback_txt" id="contact" size="20" /></td></tr><tr bgcolor="#ffffff"><td height="25" bgcolor="#ffffff">Email *</td><td><input name="email" type="text" class="feedback_txt" id="email" size="35" /></td></tr><tr bgcolor="#ffffff"><td height="25" bgcolor="#ffffff">Fax</td><td><input name="fax" type="text" class="feedback_txt" id="fax" size="20" /></td></tr><tr bgcolor="#ffffff"><td height="25" valign="top" bgcolor="#ffffff">Comments</td><td><textarea name="enquiry" cols="45" rows="5" class="feedback_txt" id="enquiry"></textarea></td></tr><tr bgcolor="#ffffff"><td height="25" bgcolor="#ffffff">&nbsp;</td><td><input type="submit" name="btn_send_cart_enquiry" id="btn_send_cart_enquiry" value="Send" onclick="return check_cart_form()"> <input type="submit" name="btn_cancel" onclick="clear_cart_enquiry_form()" id="btn_cancel" value="Cancel"></td></tr></table>';
}
function clear_cart_enquiry_form() {
	window.document.getElementById("cart_enquiry_box").innerHTML="";
}
function remove_cart_basket() {
	var ans=confirm("Are you sure to remove the product enquiry window?");
	if(ans) {
		return true;
	} else {
		return false;
	}
	return false;
}
function remove_2_cart(url, id, name, qty) {
	var ans=confirm("Are you sure to remove the item '"+name+"'?");
	if(ans) {
		self.location=url+"&remove_2_cart="+id+":"+qty;
	} else {
		return false;
	}
	return false;
}
function update_2_cart(url, id) {
	var qty=window.document.getElementById("cartQuantity"+id).value;
	self.location=url+"&update_2_cart="+id+":"+qty;
}
function show_archive_tenders(tenid, id, total) {
	for(var i=1; i<=total; i++) {
		window.document.getElementById("my_archive_tenders_"+i).innerHTML="";
	}
	var url="common/get_processes_admin.php?show_tenders_details="+tenid;
	openConnection(url, "my_archive_tenders_"+id);
}
function archive_tender_title(yr, count, total_yr) {
	for(var i=1; i<=total_yr; i++) {
		window.document.getElementById("display_tenders_title_"+i).innerHTML="";
	}
	var url="common/get_processes_admin.php?archive_tenders_title="+yr;
	openConnection(url, "display_tenders_title_"+count);
}
function show_tender_detail(tenid, id, total) {
	for(var i=1; i<=total; i++) {
		window.document.getElementById("show_tender_detail_"+i).innerHTML="";
	}
	var url="common/get_processes_admin.php?show_tenders_details="+tenid;
	openConnection(url, "show_tender_detail_"+id);
}
function show_proj_detail(projid, id, total) {
	for(var i=1; i<=total; i++) {
		window.document.getElementById("show_proj_detail_"+i).innerHTML="";
	}
	var url="common/get_processes_admin.php?show_proj_details="+projid;
	openConnection(url, "show_proj_detail_"+id);
}
function submit_job_application() {
	with(window.document.frm_job_application) {
		if(isEmpty(name, "Please enter your full name.")) {
			return false;
		} else if(isEmpty(address, "Please enter your address.")) {
			return false;
		} else if(isEmpty(contact, "Please enter your contact number.")) {
			return false;
		} else if(isEmpty(email, "Please enter your email id.")) {
			return false;
		} else if(isEmail(email, "Please enter your valid email id.")) {
			return false;
		} else if(isEmpty(nationality, "Please enter your nationality.")) {
			return false;
		} else if(isEmpty(passportno, "Please enter your passport number.")) {
			return false;
		} else if(isEmpty(age, "Please enter your age.")) {
			return false;
		} else if(isEmpty(maritalstatus, "Please enter your marital status.")) {
			return false;
		}
	}
}
function job_details_read(jobid, id, total, ref) {
	//alert(jobid+", "+id+", "+total);
	for(var i=1; i<=total; i++) {
		window.document.getElementById("job_details_read_"+i).innerHTML="";
	}
	//window.document.getElementById("job_details_read_"+id).innerHTML=jobid;
	var url="common/get_processes_admin.php?read_jobs_detial="+jobid+"&myref="+ref;
	openConnection(url, "job_details_read_"+id);
}
function show_archive_news(newsid, id, total) {
	for(var i=1; i<=total; i++) {
		window.document.getElementById("my_archive_news_"+i).innerHTML="";
	}
	//window.document.getElementById("my_archive_news_"+id).innerHTML=newsid;
	var url="common/get_processes_admin.php?archive_news_detials="+newsid;
	openConnection(url, "my_archive_news_"+id);
}
function archive_news_title(yr, count, total_yr) {
	for(var i=1; i<=total_yr; i++) {
		//alert("display_news_title_"+i);
		window.document.getElementById("display_news_title_"+i).innerHTML="";
	}
	var url="common/get_processes_admin.php?archive_news_title="+yr;
	openConnection(url, "display_news_title_"+count);
}
function check_feedback_form() {
	with(window.document.frm_nehmeh_feedback) {
		if(isEmpty(name, "Please enter your full name.")) {
			return false;
		} else if(isEmpty(email, "Please enter your email id.")) {
			return false;
		} else if(isEmail(email, "Please enter your valid email id.")) {
			return false;
		}
	}
}
function check_reg_seminars() {
	with(window.document.frm_reg_seminars) {
		if(isEmpty(txt_person, "Please enter your name.")) {
			return false;
		} else if(isEmpty(txt_company, "Please enter your company name.")) {
			return false;
		} else if(isEmpty(txt_nos, "Please enter the number of person attending in seminar.")) {
			return false;
		} else if(isEmpty(txt_contact, "Please enter your contact number.")) {
			return false;
		} else if(isEmpty(txt_email, "Please enter your email id.")) {
			return false;
		} else if(isEmail(txt_email, "Please enter your valid email id.")) {
			return false;
		}
	}
}
function vote_my_poll() {
	with(window.document.frm_my_poll_home) {
		var data_id="";
		for(i = 0; i < rdo_poll.length; i++ ) {
			if(window.document.frm_my_poll_home.rdo_poll[i].checked==true) {
				data_id=window.document.frm_my_poll_home.rdo_poll[i].value;
				break;
			}
		}
		if(data_id=="") {
			alert("Please select a option for vote.");
			return false;
		} else {
			xmlhttpPost('common/post_qs_values.php', 'frm_my_poll_home', 'poll_box_result_id');
		}
	}
}
/*************************************************************************************/
function confirmDelete() {	
	var answer=confirm("Are you sure to delete?");
	if(answer)	{ 
		return true;
	} else {
		return false;
	}		
	return false;
}
function isEmpty(formElement, message) {
	formElement.value = trim(formElement.value);
	var _isEmpty = false;
	if (formElement.value == '') {
		_isEmpty = true;
		alert(message);
		formElement.focus();
	}
	return _isEmpty;
}
function trim(str) {
	return str.replace(/^\s+|\s+$/g,'');
}
function isEmail(formElement, message) {
	var _isEmail=false;
	if(!regmails.test(formElement.value)) {
		_isEmail=true;
		alert(message);
		formElement.select();
	}
	return _isEmail;
}
function remove_message(id) {
	var remRem=window.document.getElementById(id);
	remRem.parentNode.removeChild(remRem);
}
function openConnection(urls,ids) {
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null) {
		alert ("Browser does not support HTTP Request")
		return
	}
	xmlHttp.onreadystatechange=function() { stateChngtoOpenConnection(ids); };
	xmlHttp.open("GET",urls,true)
	xmlHttp.send(null)
}
function stateChngtoOpenConnection(ids) {
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
		document.getElementById(ids).innerHTML=xmlHttp.responseText;
	} else {
		document.getElementById(ids).innerHTML="<span class='text'>Processing...</span>";
	}
}
function GetXmlHttpObject()	{
	var xmlHttp=null;
	try {
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	}
	catch (e) {
		//Internet Explorer
		try	{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e) {
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	return xmlHttp;
}
