/*Function for the general validation For Admin*/

//=======================================//
// activation,deactivation
//========================================//


 function delvarify(del_id,del_page)
   {
   	  if(confirm("Are you sure you want to delete this Record"))
	  {
	     window.location.href=del_page+"&checkGroup="+del_id;
	  }
   }
   function check_delete(frmEmp,page)
	{
		
	var active="";
	for(var i = 0; i <frmEmp.checkGroup.length ; i++)
		{
			if(frmEmp.checkGroup[i].checked==true)
				{
					if(active !="")
					{
						active = active + ', ' + frmEmp.checkGroup[i].value;
					}
					else
					{
						active = frmEmp.checkGroup[i].value;
					}
			
				}
		}
	if(active=="")
		{
			if(frmEmp.checkGroup.checked==true)
				{
					active= frmEmp.checkGroup.value;
				}
		}
	if(active=="")
		{
		  alert("Please select at least one check box.") ;
		  return false;
		}
	else
		{
		d=confirm("Do you want to delete these record(s)");
		if(d)
		{
			frmEmp.mode.value="del_all";
			frmEmp.id.value= active;
			frmEmp.action=page;
			frmEmp.submit();
		}
	  }
	} 
	
	function activate_all(frmEmp,page)
	{
	
	var active="";
	for(var i = 0; i < frmEmp.checkGroup.length ; i++)
		{
			if(frmEmp.checkGroup[i].checked==true)
				{
					if(active !="")
					{
						active = active + ', ' +frmEmp.checkGroup[i].value;
					}
					else
					{
						active =frmEmp.checkGroup[i].value;
					}
			
				}
		}
	if(active=="")
		{
			if(frmEmp.checkGroup.checked==true)
				{
					active= frmEmp.checkGroup.value;
				}
		}
	if(active=="")
		{
		  alert("Please select at least one check box") ;
		  return false;
		}
	else
		{
		
		d=confirm("Do you want to deactivate these record(s)");
		if(d)
		{
			frmEmp.mode.value="activate_all";
		    frmEmp.id.value= active;
			frmEmp.action=page;
			frmEmp.submit();
		}
	  }
	}
	
	
	
	function deactivate_all(frmEmp,page)
	{
	var active="";
	for(var i = 0; i < frmEmp.checkGroup.length ; i++)
		{
			if(frmEmp.checkGroup[i].checked==true)
				{
					if(active !="")
					{
						active = active + ', ' + frmEmp.checkGroup[i].value;
					}
					else
					{
						active = frmEmp.checkGroup[i].value;
					}
			
				}
		}
	if(active=="")
		{
			if(frmEmp.checkGroup.checked==true)
				{
					active= frmEmp.checkGroup.value;
				}
		}
	if(active=="")
		{
		  alert("Please select at least one check box") ;
		  return false;
		}
	else
		{
			d=confirm("Do u want to activate these record(s)");
			if(d)
			{  
			frmEmp.mode.value="dectivate_all";
			frmEmp.id.value= active;
			frmEmp.action=page;
			frmEmp.submit();
			}
	
		}
	}
		
		
	function deactivate_all_c(frmEmp,page,cc)
	{
	//alert(cc);
	if(cc == 512){
		alert('More than 512 pages cannot be activated.');
		return;
	}
	
	var active="";
	
	//alert(frmEmp.checkGroup.length);
//	if(frmEmp.checkGroup.length > 5){
//		alert('More than 5 pages cannot be activated.');
//		return;
//	}
	
	for(var i = 0; i < frmEmp.checkGroup.length ; i++)
		{
			if(frmEmp.checkGroup[i].checked==true)
				{
					if(active !="")
					{
						active = active + ', ' + frmEmp.checkGroup[i].value;
					}
					else
					{
						active = frmEmp.checkGroup[i].value;
					}
			
				}
		}
		
	if(active=="")
		{
			if(frmEmp.checkGroup.checked==true)
				{
					active= frmEmp.checkGroup.value;
				}
		}
	if(active=="")
		{
		  alert("Please select at least one check box") ;
		  return false;
		}
		
	else
		{
			d=confirm("Do u want to activate these record(s)");
			if(d)
			{  
			frmEmp.mode.value="dectivate_all";
			frmEmp.id.value= active;
			frmEmp.action=page;
			frmEmp.submit();
			}
	
		}
	}



//=======================================//











//==========================================
// Check All boxes
//==========================================
function CheckAll(fmobj) {
  for (var i=0;i<fmobj.elements.length;i++) {
    var e = fmobj.elements[i];
    if ( (e.name != 'allbox') && (e.type=='checkbox') && (!e.disabled) ) {
      e.checked = fmobj.allbox.checked;
    }
  }
}

//==========================================
// Check all or uncheck all?
//==========================================
function CheckCheckAll(fmobj) {
  var TotalBoxes = 0;
  var TotalOn = 0;
  for (var i=0;i<fmobj.elements.length;i++) {
    var e = fmobj.elements[i];
    if ((e.name != 'allbox') && (e.type=='checkbox')) {
      TotalBoxes++;
      if (e.checked) {
       TotalOn++;
      }
    }
  }
  if (TotalBoxes==TotalOn) {
    fmobj.allbox.checked=true;
  }
  else {
   fmobj.allbox.checked=false;
  }
}



function admin_val()
{
	if(window.document.frm_admin.first_name.value == "") {
		alert("Please enter first name");
		window.document.frm_admin.first_name.focus();
		return false;
	}
	if(window.document.frm_admin.last_name.value == "") {
		alert("Please enter last name");
		window.document.frm_admin.last_name.focus();
		return false;
	}
	
	if(!validateEmail(window.document.frm_admin.email.value))
		{
			//alert("Please,Give Valid Email Address");
			window.document.frm_admin.email.focus();
			return false;
		}
	
	
	if(window.document.frm_admin.password.value == "") {
		alert("Please enter password");
		window.document.frm_admin.password.focus();
		return false;
	}
}

/*Function for the general validation Forget Password*/
function forget_password_val()
{
	if(window.document.frm_forget_password.email.value == "") {
		alert("Please enter email address");
		window.document.frm_forget_password.email.focus();
		return false;
	}
	else{
		if(!isValidEmail(window.document.frm_forget_password.email.value))
		{
			alert("Please give valid email address");
			window.document.frm_forget_password.email.focus();
			return false;
		}
	}
}

/*Function for the general validation  Index*/
function index_val()
{
	  
	if(window.document.frm_index1.email.value == "") {
		alert("Please enter the username");
		window.document.frm_index1.email.focus();
		return false;
	}
	if(window.document.frm_index1.password.value == "") {
		alert("Please enter the password");
		window.document.frm_index1.password.focus();
		return false;
	}
	
}

/*Function to open forget password page*/
function forgotPwd()
{
	window.open("forget_password.php","Help","toolbar=no,resizable=yes,scrollbars=yes,width=420,height=200");

}

/*Function for the general validation Menu*/
function menu_val()
{
	if(window.document.frm_menu.name.value == "") {
		alert("Please enter menu name");
		window.document.frm_menu.name.focus();
		return false;
	}
	if(window.document.frm_menu.order.value == "") {
		alert("Please enter order");
		window.document.frm_menu.order.focus();
		return false;
	}
}
function news_val()
{
	if(window.document.frm_news.title.value.search(/\S/) == -1) {
		alert("Please enter title");
		window.document.frm_news.title.focus();
		return false;
	}
	if(window.document.frm_news.date.value.search(/\S/) == -1) {
		alert("Please enter date");
		window.document.frm_news.date.focus();
		return false;
	}
}

function creatSpace(str,Field)
{     
		 var Field =Field;
         var length=Field.value.length;
		 var val=Field.value;
		 var wordLength = 0;
		 for( var i=0; i<=length; i++)
		 {
		    if(val.charCodeAt(i)==32 && val.charCodeAt(i+1)==32)
			{
				val = val.substring(0, i)+val.substr(i+1);
				i = i-1;
			}
		}
		 for( var i=0; i<=length; i++)
		 {

			if(val.charCodeAt(i)==32)
				wordLength = 0;
			else
				wordLength++;
			
			
			if(str=='txtPunch')	
			var strval=17;
			
			if(str=='frmBasic')	
			var strval=24;
			
			//alert(strval);
			if(wordLength > strval)
			{
				val = val.substring(0, i)+" "+val.substr(i);
				wordLength = 0;
			}
			
			
		 }
		 Field.value =trim(val);
		//ssalert(val);return false;
}
