// Null value filter start //
function trim(str)
	{
	   return str.replace(/^\s*|\s*$/g,"");
	}

function emptychk()
	{
		if(document.getElementById('textbar').value == "")	{
			return false; 
		}
	}
function alert_delete()
	{
		if (confirm("Delete Record?") == false)	{
			return false;
		} else {
			return true;
		}
	}

function save_cancel(url, save)
	{
		if(save == 1) {
			if (confirm("Save Record?") == false)	{
				return false;
			} else {
				window.location = url;
			}
		} else {
			window.location = url;
		}
			
	}

function NumericOnly()
	{
	var key = window.event.keyCode;
	
	if (key <48 || key >57)
	window.event.returnValue = false;
	}


function numbersonly(e){
	var unicode=e.charCode? e.charCode : e.keyCode
	if (unicode!=8){ //if the key isn't the backspace key (which we should allow)
	if (unicode<48||unicode>57) //if not a number
	return false //disable key press
	}
}

//delete conformation
/* ------------------- hide and seek cookies -------------------- */
function readCookie(name) {
   var nameEQ = name + '=';
   var ca = document.cookie.split(';');
   for(var i=0;i < ca.length;i++) {
      var c = ca[i];
      while (c.charAt(0)==' ') c = c.substring(1,c.length);
      if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
   }
   return null;
}

function isCookieAllowed(){
   setCookie('cookie_allowed',1,10); 
   if(readCookie('cookie_allowed') != 1) {alert('This operation requires that your browser accepts cookies! Please turn on cookies accepting.'); return false; }; 
   return true; 
}

function setCookie(name,value,days) {
   if (days) {
      var date = new Date();
      date.setTime(date.getTime()+(days*24*60*60*1000));
      var expires = '; expires='+date.toGMTString();
   }
   else var expires = '';
   document.cookie = name+'='+value+expires+'; path=/';
}

function hideUnHideFiltering(btn,div,rdir){
	
	if(div=='divWeb'){
	document.getElementById('divWeb').style.display = 'block';
	} else {
	document.getElementById('divWeb').style.display = 'none';
	}
	
	if(div=='divEmail'){
    document.getElementById('divEmail').style.display = 'block';
	} else {
    document.getElementById('divEmail').style.display = 'none';
	}	
	
	if(div=='divCat'){
    document.getElementById('divCat').style.display = 'block';
	} else {
    document.getElementById('divCat').style.display = 'none';
	}	
	
	if(btn=='btnWeb'){
	document.getElementById('btnWeb').src = '/images/btnWebpages_over.gif'; 
	} else {
	document.getElementById('btnWeb').src = '/images/btnWebpages.gif'; 
	}
	
	if(btn=='btnEmail'){
    document.getElementById('btnEmail').src = '/images/btnEmail_over.gif';
	} else {
    document.getElementById('btnEmail').src = '/images/btnEmail.gif';
	}
	
	if(btn=='btnCat'){
    document.getElementById('btnCat').src = '/images/btnCategory_over.gif';
	}
	if(btn=='btnWeb'){
    document.getElementById('btnCat').src = '/images/btnCategoryL.gif';
	} 
	if(btn=='btnEmail'){
    document.getElementById('btnCat').src = '/images/btnCategoryR.gif';
	}
		
	setCookie('cDiv',div,10);
	setCookie('cBtn',btn,10);
	
	if(rdir==1) window.location='index.php';
	
}

function getCookies(pg){
	var c = parseInt(readCookie('hide_'+pg));
	//alert(c);
	if(!c){
		if(document.getElementById(pg))	document.getElementById(pg).style.display = ''; 
		if(document.getElementById(pg+'_hide'))	document.getElementById(pg+'_hide').style.display = ''; 
		if(document.getElementById(pg+'_unhide')) document.getElementById(pg+'_unhide').style.display = 'none'; 
	} else {		
		if(document.getElementById(pg))	document.getElementById(pg).style.display = 'none'; 
		if(document.getElementById(pg+'_hide'))	document.getElementById(pg+'_hide').style.display = 'none'; 
		if(document.getElementById(pg+'_unhide')) document.getElementById(pg+'_unhide').style.display = '';
	}
}
/* ------------------- hide and seek cookies -------------------- */

function Clear()
  {	
	 document.frmmail.fname.value="";
	 document.frmmail.phone.value="";
	 document.frmmail.email.value="";
	 document.frmmail.comments.value="";
	 document.frmmail.fname.focus();
	 return false;
  }
  
function valideval()
  {
	if (trim(document.frmmail.fname.value)=="")
	{	
	 alert("Please enter your name....");
	 document.frmmail.fname.value="";
	 document.frmmail.fname.focus();
	 return false;
	}
	else if (trim(document.frmmail.phone.value)=="")
	{
	 alert("Please enter your phone number....");
	 document.frmmail.phone.value="";
	 document.frmmail.phone.focus();
	 return false;
	}
	else if (trim(document.frmmail.email.value)=="")
	{
	 alert("Please enter an email address....");
	 document.frmmail.email.value="";
	 document.frmmail.email.focus();
	 return false;
	}
	else if (echecknew(document.frmmail.email.value)=="")
	{
	document.frmmail.email.value=""
	document.frmmail.email.focus()
	return false;
	}
	else if (trim(document.frmmail.comments.value)=="")
	{
	 alert("Please enter a message....");
	 document.frmmail.comments.value="";
	 document.frmmail.comments.focus();
	 return false;
	}
	else
	{
	 document.frmmail.submit();
	 return true;
	}
  }
  
 // *** Email validation display in textbox ***
	function echecknew(str,frm) {
        dml=document.forms[frm];
		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("Invalid email address")
		   //dml.txtdisplay.value="Invalid email address..";
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || 
str.indexOf(at)==lstr){
		   alert("Invalid email address")
		   //dml.txtdisplay.value="Invalid email address..";
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || 
str.indexOf(dot)==lstr){
		   alert("Invalid email address")
		    //dml.txtdisplay.value="Invalid email address..";
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid email address")
		   //dml.txtdisplay.value="Invalid email address..";
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || 
str.substring(lat+1,lat+2)==dot){
		  alert("Invalid email address")
		    //dml.txtdisplay.value="Invalid email address..";
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid email address")
		   //dml.txtdisplay.value="Invalid email address..";
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Invalid email address")
		   //dml.txtdisplay.value="Invalid email address..";
		    return false
		 }

 		 return true					
	}
//*****************email validation end


function pgNavProcess(pg,url)
	{		
		start = new Date(); 
		start = start.getTime();
	
		var exec = function(str)
		{		
			//alert(str);
			if(trim(str) != "") {
			     //alert(str);
			} else {
				//window.open(url);
				//alert(url);
				//window.location = url;
			}
		}
		var ajax = new doAjax();
		ajax.doGet('/ajax.webClick.php?pg='+pg+'&start='+start, exec);	
	}
