var errmsg='';

function resetall(){errmsg='';} // to reset the errmsg so that it can work better for next turn.

function required(obj,title)// checks that the field is not empty
{

	if(errmsg=='')// checks if one message is being displayed before it then this will not be displayed.
	{
		if(obj.value=='')
		{

			errmsg += title+" is required. \n";

			alert(errmsg);

			obj.focus();

		}
	}

}

function minstrlen(obj,len,title)
{

	if(errmsg=='')
	{
		if(obj.value.length < len)//checks if length of the entered string is lesser than the required length
		{
			errmsg += title+" should be at least "+len+" characters long. \n";

			alert(errmsg);

			obj.focus();

			return false;
		}
	}
}

function matchfields(obj1,title1,obj2,title2)
{
	if(errmsg=='')
	{
		if(obj1.value != obj2.value)//checks if obj1 and obj2 values are same
		{
			errmsg += title1+" and "+title2+" should be the same. \n";
			alert(errmsg);
			obj1.focus();

		}
	}
}

function isEmail(obj,title)
{

	if(errmsg=='')
	{
		p=obj.value.split('@');
		if(p[1]){q = p[1].split('.');}
		if(!(p[1] && q[1]))//checks if string is having a '@' and '.' characters
		{
			errmsg += title+" should be a valid E-mail Address. eg. john168@gtrecycling.com \n";
			alert(errmsg);
			obj.focus();
		}
	}
}

function checksubmit(frm)
{
	if(errmsg=='')
	{
		frm.submit();
	}
	else
	{
		errmsg='';
		return false;
	}
}

var http = createRequestObject();  
var response;
var the_srch_div_id;
var obj1;

function callFile(url) 
{
	http.open('get', url);
	http.onreadystatechange = getResponseCallFile;
	http.send(null);
}

function getResponseCallFile() 
{  
   if(http.readyState == 4 && http.status == 200)
   {  
	  response = http.responseText;  
   }  
}

function showTextinObj(obj, url) 
{
	obj1 = obj;
	document.getElementById(obj).style.visibility = 'visible';
	http.open('get', url);
	http.onreadystatechange = getResponse;
	http.send(null);
}

function getResponse()
{
   if(http.readyState == 4 && http.status == 200)
   {  
	  response = http.responseText;  
	  document.getElementById(obj1).innerHTML = response;
   }
}

function get_location(theForm, obj, index) 
{
	theLeft=0;
	theTop=0;
	div_search = eval("prdcode"+index);
	if(navigator.appName == 'Microsoft Internet Explorer')
	{
		theLeft = obj.getBoundingClientRect().left - 1;
		theTop = obj.getBoundingClientRect().top + 20;
	}
	else
	{
		if (navigator.appName == 'Netscape') 
		{
			theLeft = document.getBoxObjectFor(document.getElementById(div_search.id)).x ;
			theTop = document.getBoxObjectFor(document.getElementById(div_search.id)).y ;
		}
		else 
		{
			alert("Unknow browser! Please contact with website administrator.");
		}
	}
	
	document.getElementById(div_search.id).style.left = theLeft;
	document.getElementById(div_search.id).style.top = theTop;
	document.getElementById(div_search.id).style.position = 'fixed';
	document.getElementById(div_search.id).style.height = '150px';
	document.getElementById(div_search.id).style.visibility = "visible";

	the_srch_div_id = div_search.id;
	http.open('get', 'search_products.php?q='+obj.value+"&obj="+obj.id);
	http.onreadystatechange = handleResponse;
	http.send(null);  
}

	
function createRequestObject() 
{  
	var req;  
	
	if(window.XMLHttpRequest)
	{  
	  // Firefox, Safari, Opera...  
	  req = new XMLHttpRequest();  
	} 
	else if(window.ActiveXObject) 
	{  
		// Internet Explorer 5+  
	  	req = new ActiveXObject("Microsoft.XMLHTTP");  
	} 
	else 
	{  
		// There is an error creating the object,  
		// just as an old browser is being used.  
		alert('Problem creating the XMLHttpRequest object');  
	}  
	
	if (req.overrideMimeType) 
	{
		req.overrideMimeType('text/xml');
	}
	
	if (!req) 
	{
		alert('Cannot create XMLHTTP instance');
	}

	return req;  
}  

/* this function controls layer's visibility */     
function handleResponse() 
{	 
	if(http.readyState == 4 && http.status == 200)
	{  
		response = http.responseText;  
	  	if(response.length > 1) 
		{  
			document.getElementById(the_srch_div_id).style.visibility = "visible";
			document.getElementById(the_srch_div_id).innerHTML = response;  
	  	} 
		else 
		{
			document.getElementById(the_srch_div_id).style.visibility = "hidden";
	  	}
  	}  
}  

/* this function controls the layer's visibitlity */
function div_state() 
{
	document.getElementById(the_srch_div_id).style.height = '1px';
	document.getElementById(the_srch_div_id).style.visibility = "hidden";
}

/* This function sets the form action */
function the_frm_process_quotation(theForm, obj) 
{
	if (obj.name == 'btn_reset') 
	{
		theForm.reset();

	} 
	else 
	{
		if (obj.name == 'btn_add') 
		{
			theForm.action = "quotation_detail.php";
			theForm.submit();
		} 
		else 
		{
			if (obj.name == 'btn_complete') 
			{
				theForm.action = "search_products.php";
				theForm.submit();
			} 
			else 
			{
				return false;
			}
		}
	}

	return true;
}

function pop_fields(fld, data) 
{
	document.getElementById(fld).value = data;
}

document.onclick = checkMouse;

function checkMouse() 
{

	try
	{
		if ((event.x > 250 && event.x < 855) && (event.y > 160 && event.y < 471)) 
		{ 
	}  
	else 
	{
		document.getElementById("srch").style.visibility = "hidden";
	
	}
	}
	catch(e){}
}

function searchboxempty()
{
	if(document.srchprdfrm.searchproducts.value=="" || document.srchprdfrm.searchproducts.value=="Please enter your search here" || document.srchprdfrm.searchproducts.value=="Search this site"  )
	{
		document.srchprdfrm.searchproducts.value="Please enter your search here";	
		return false;
	}
}

function onclickfunction()
{
	
	if(document.srchprdfrm.searchproducts.value!='')
	{  
   		if(document.srchprdfrm.searchproducts.value=='Search this site')
   		{
   			document.srchprdfrm.searchproducts.style.color = "#000";
   			document.srchprdfrm.searchproducts.value='';
   		}
	}
	else
	{
		document.srchprdfrm.searchproducts.style.color = "#898989";
		document.srchprdfrm.searchproducts.value='Search this site';
	}
}
/*
function checkSearchString(e)
{
	var oEvent = window.event ? window.event : e;
	if ( (oEvent.keyCode == 32) && (!otherChr) )
	{
		document.getElementById('searchproducts').value = '';
		document.getElementById('srch').style.visibility='hidden';
		return false;
	}
	else
	{
		otherChr = true;
		if (document.getElementById('searchproducts').value.length >= 2)
		{
			showTextinObj('srch',genUrl());
			return true;
		}
		else
			return false;
	}

}*/
	
function Menu()
{ 
	if(navigator.appVersion.indexOf("MSIE")==-1){return;}
	var i,k,g,lg,r=/\s*p7hvr/,nn='',c,cs='p7hvr',bv='p7menubar';
	for(i=0;i<10;i++){g=document.getElementById(bv+nn);if(g)
	{
		lg=g.getElementsByTagName("li");
		if(lg)
		{
			for(k=0;k<lg.length;k++)
			{
				lg[k].onmouseover=function(){c=this.className;cl=(c)?c+' '+cs:cs;
				this.className=cl;};lg[k].onmouseout=function(){c=this.className;
				this.className=(c)?c.replace(r,''):'';
			};}
		}
	}nn=i+1;}
}




<!---------------------Inline code------------------>






	var otherChr = false;
	/*function checkSearchString(e)
	{
		
		var oEvent = window.event ? window.event : e;
		
		if ( (oEvent.keyCode == 32) && (!otherChr) )
		{
			
			document.getElementById('searchproducts').value = '';
			document.getElementById('srch').style.visibility='hidden';
			return false;
		}
		else
		{
			
			otherChr = true;
			if (document.getElementById('searchproducts').value.length >= 2)
			{
				
				showTextinObj('srch',genUrl());
				return true;
			}
			else
				return false;
		}
	}*/
	
	function checkSearchStringHomeSearchBar(e)
	{
		var val = document.getElementById('searchproducts').value;
		var oEvent = window.event ? window.event : e;
		if ( (oEvent.keyCode == 32) && (!otherChr) )
		{
			document.getElementById('searchproducts').value = '';
			document.getElementById('srch').style.visibility='hidden';
			return false;
		}
		else
		{
			
			otherChr = true;
			if (document.getElementById('searchproducts').value.length >= 2)
			{
				// alert("AVC");
				/* showTextinObj('srch',genUrl());
*/			
			//alert("adasd");
			document.getElementById('srch').style.visibility='visible';
			$('#srch').load('user_predictive_search.php?tbl=products&default_field=ProductName&frm=srchprdfrm&obj=searchproducts&fld=ProductName',{val:val},function(){});
	
				return true;
			}
			else
				return false;
		}
	}
	
	function genUrl()
	{
		url="user_predictive_search.php?tbl=products&default_field=ProductName&frm=srchprdfrm&obj=searchproducts&fld=ProductName";
		url += "&val=";
		url += document.getElementById('searchproducts').value;
		url += "&catid=";
		//url += document.getElementById('ddCatSearch').value;
		//alert(url);
		//alert('Done');
		return url;
	}
	function KeyPress(e, field)
	{
		var oEvent = window.event ? window.event : e;
		if (oEvent.keyCode == 32)
		field.value = '';
	}
	
	/*function searchboxempty()
	{
		if(document.srchprdfrm.searchproducts.value=="")
		{
			document.srchprdfrm.searchproducts.value="Please enter your search here";
			return false;
		}
	}*/

