// Login Form Validation
function Clicking(){
var frmlogin=document.logFrm;
	if(frmlogin.txtName.value==""){
		alert("User name should not be blank");
		frmlogin.txtName.focus();
		return false;
	}
	if(frmlogin.txtPwd.value==""){
		alert("Password should not be blank");
		frmlogin.txtPwd.focus();
		return false;
	}
document.logFrm.action="index.php";
document.logFrm.submit();
}


// Admin Module Validation
function validateAdmin(){ 
	var formobj=document.Admin;
	if(formobj.a_name.value==""){
		alert("Admin name should not be blank.");
		formobj.a_name.focus();
		return false;
	}
	if(!IsEmail(formobj.a_email,'Email Address should not be blank.'))
		return false;
	if(formobj.pwd1.value==""){
		alert("Password should not be blank");
		formobj.pwd1.focus();
		return false;
	}
	if(formobj.pwd1.value!=""){
		if(formobj.pwd1.value.length<4){
			alert("Enter minimum 4-digit:");
			formobj.pwd1.focus();
			return false;
		}
	}
	if(formobj.pwd2.value==""){
		alert("Retype password should not be blank");
		formobj.pwd2.focus();
		return false;
	}
	if(formobj.pwd2.value.length<4){
			alert("Enter minimum 4-digit:");
			formobj.pwd2.focus();
			return false;
		}
	if(formobj.pwd1.value!=formobj.pwd2.value){
		alert("Retype password does not match with original password");
		formobj.pwd2.focus();
		return false;
	}
	else{
		return true;
	}
	return true;
}


// Main Category Module Validation
function validCategory()
{
	if(!IsBlank(document.Category.m_name,'Category name should not be blank'))
		return false;
	if(!IsNumber(document.Category.m_order,'Page Rank should not be blank'))
		return false;	
return true;
}
function IsNumber(obj, msgstr)
{
	if(Trim(obj.value) == ""){
		alert(msgstr);
		obj.focus();
		return false;
	}	
	else
	{
	    if(obj.value.search(/^\d+$/) != -1)
    	    return true;
	    else
		{
			alert("Invalid Value! Enter Only Numeric Value");
			obj.focus();
    	    return false;
		}
	}
}

//Sub Category Module Validation
function validsubcategory(){
	var frmobj=document.frmSubCategory;
		if(!IsBlank(frmobj.cid,'Select Main Category'))
			return false;	
		if(!IsBlank(frmobj.stitle,'Sub category should not be blank'))
			return false;		
		/*if(!IsNumber(document.frmSubCategory.s_order,'Page Rank should not be blank'))
			return false;*/
		return true;
}

//Poll Module Validation
function validatePoll(){
var objPoll = document.frmPoll;
if(!IsBlank(objPoll.p_que,'Poll Question should not be blank'))
	return false;	
if(objPoll.p_option.value=="all"){
	alert("Poll option should not be blank");
	objPoll.p_option.focus();
	return false;
}
if(!IsNumber(objPoll.p_order,'Page Rank should not be blank'))
			return false;	
return true;
}

function validate_contact()
{

var msg=true;

var con=document.contact;
	if(con.name.value=="")
	{
       alert("The name should not be left blank");
	   con.name.focus();
	   msg=false;
	}
	if(msg=='true')
	{
	if(con.name.value=="")
	{
       alert("The name should not be left blank");
	   con.name.focus();
	   msg=false;
	}
	
	}
	if(msg=='true')
	{
	if(con.phoneno.value=="")
	{
       alert("The phoneno should not be left blank");
	   con.name.focus();
	   msg=false;
	}
	}

	if(msg)
	{

	document.contact.submit();
	}
	
	

	
}
function validate_app()
{

var msg=true;

var con=document.app_form;
	if(con.name.value=="")
	{
       alert("The name should not be left blank");
	   con.name.focus();
	   msg=false;
	}
	if(msg)
	{
	if(con.day_phone.value=="")
	{
       alert("The day phone should not be left blank");
	   con.day_phone.focus();
	   msg=false;
	}
	
	}
	if(msg)
	{
	if(con.email.value=="")
	{
       alert("The email should not be left blank");
	   con.email.focus();
	   msg=false;
	}
	}

	if(msg)
	{

	document.app_form.submit();
	}
	else
	{
	return false;
	}
	

	
}
function validate_contact_gen()
{

var msg=true;
//alert("SDFSD");
var con=document.contact_gen;
	if(con.name.value=="")
	{
       alert("The name should not be left blank");
	   con.name.focus();
	   msg=false;
	}
	
	if(msg)
	{
	if(con.phoneno.value=="")
	{
       alert("The phoneno should not be left blank");
	   con.name.focus();
	   msg=false;
	}
	}
	if(msg)
	{
	if(con.email.value=="")
	{
       alert("The email should not be left blank");
	   con.email.focus();
	   msg=false;
	}
	else
	{
		 if(!IsEmail(con.email))
		 {
		  msg=false;
		 }
	}
	}
	
  if(msg)
	{
	if(con.n_loc.value=="")
	{
       alert("Please select atleast one location");
	   con.n_loc.focus();
	   msg=false;
	}
	
	}
	if(msg)
	{

	document.contact_gen.submit();
	}
	
	

	
}




// Article Module Validation 
function ArticleValidation(){
var objArticle = document.frmArticle;
var art_desc=FCKeditorAPI.GetInstance('lgdesc');
	if(!IsBlank(objArticle.art_name,'Article name should not be blank'))
		return false;	
	if(!IsBlank(objArticle.p_name,'Publisher name should not be blank'))
		return false;
	if(!IsNumber(objArticle.art_order,'Page Rank should not be blank'))
		return false;	
	if(art_desc.GetXHTML() == ""){
		alert("Article description should not be blank.");
		return false;
	}
return true;
}


// News Module Validation Function
function NewsValidation(){
	var objnews = document.frmnews;
	var desc=FCKeditorAPI.GetInstance('lgdesc');
	if(objnews.n_name.value==""){
		alert("News/Event name should not be blank.");
		objnews.n_name.focus();
		return false;
	}
	if(objnews.n_date.value==""){
		alert("News/Event Date should not be blank.");
		objnews.n_date.focus();
		return false;
	}
	if(!IsNumber(objnews.n_order,'Page Rank should not be blank'))
			return false;	

	if(desc.GetXHTML() == ""){
		alert("News/Event description should not be blank.");
		return false;
	}
	return true;
}


//Content Module Validation Function
function ContentValidation(){
var objcontent = document.frmcontent;
var cont_desc=FCKeditorAPI.GetInstance('lgdesc');
	if(objcontent.c_name.value==""){
		alert("Content name should not be blank.");
		objcontent.c_name.focus();
		return false;
	}if(!IsNumber(objcontent.c_order,'Page Rank should not be blank'))
			return false;	
	if(cont_desc.GetXHTML() == ""){
		alert("Content Description should not be blank.");
		return false;
	}
return true;
}

// Banner Module Validation Function
function bannerValid(val){
	var objBanner = document.frmBanner;
	if(document.getElementById("ban_source").checked==true){
		if(!IsBlank(objBanner.bs_source,'Advertise should not be blank'))
			return false;	
		if(!IsNumber(objBanner.bs_order,'Page Rank should not be blank'))
			return false;	
	}
	if(document.getElementById("bi_source").checked==true){
		if(!IsBlank(objBanner.b_name,'Name should not be blank'))
			return false;
		if(!IsBlank(objBanner.b_url,'Url should not be blank'))
			return false;	
		if(!IsNumber(objBanner.b_price,'Price should not be blank'))
			return false;	
		if(!IsBlank(objBanner.b_image,'Image should not be blank'))
			return false;	
		if(!IsNumber(objBanner.b_order,'Page Rank should not be blank'))
			return false;		
	}
return true;
}

// Validation For Blank Field
function IsBlank(obj,msg)
{
		if(Trim(obj.value) == "")
		{
			alert(msg);
			obj.focus();
			return false;
		}
		return true;
}
// Trim Function
function Trim(TRIM_VALUE)
{
	if(TRIM_VALUE.length < 1)
	{
		return"";
	}
	TRIM_VALUE = RTrim(TRIM_VALUE);
	TRIM_VALUE = LTrim(TRIM_VALUE);
	if(TRIM_VALUE=="")
	{
		return "";
	}
	else
	{
		return TRIM_VALUE;
	}
}

// Right Trim Function
function RTrim(VALUE)
{
	var w_space = String.fromCharCode(32);
	var v_length = VALUE.length;
	var strTemp = "";
	if(v_length < 0)
	{
		return"";
	}
	var iTemp = v_length -1;

	while(iTemp > -1)
	{
		if(VALUE.charAt(iTemp) == w_space)
		{
		}
		else
		{
			strTemp = VALUE.substring(0,iTemp +1);
			break;
		}
		iTemp = iTemp-1;

	}
	return strTemp;
}

//Left Trim Function
function LTrim(VALUE)
{
	var w_space = String.fromCharCode(32);
	if(v_length < 1)
	{
		return"";
	}
	var v_length = VALUE.length;
	var strTemp = "";
	var iTemp = 0;

	while(iTemp < v_length)
	{
		if(VALUE.charAt(iTemp) == w_space)
		{
		}
		else
		{
			strTemp = VALUE.substring(iTemp,v_length);
			break;
		}
		iTemp = iTemp + 1;
	}
	return strTemp;
}

function del()
{
	var aa;
	aa = confirm("Are you sure you want to delete this record");
	if(aa)
	{
		return true;
	}
	else
	{
		return false;
	}
}

// Email Validation Function
function IsEmail(obj, msgstr){
	if(Trim(obj.value) == ""){
		alert("Email Address should not be blank.");
		obj.focus();
		return false;
	}
	else{
	    if(obj.value.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1)
    	    return true;
	    else{
			alert("Invalid Email Address");
			obj.focus();
    	    return false;
		}
	}
}
// End of function



function validate_form(thisform)
{
	if(document.f1.ps1.value=="")
	{
		alert("Please Enter Position applied for");
		document.f1.ps1.focus();
		return false;
	}
	
	if(document.f1.empname.value!="")
	{	
		if(document.f1.refer_10.checked==false)
		{
			alert("Please Select Employee Referral");
			document.f1.refer_10.focus();
			return false;
		}
	}
	
	if(document.f1.refer_10.checked==true)
	{	
		if(document.f1.empname.value=="")
		{
			alert("Please Enter Employee Referral Name");
			document.f1.empname.focus();
			return false;
		}
	}
	
	if(document.f1.lastname.value=="")
	{
		alert("Please Enter Last Name");
		document.f1.lastname.focus();
		return false;
	}
	if(document.f1.firstname.value=="")
	{
		alert("Please Enter First Name");
		document.f1.firstname.focus();
		return false;
	}
	if(document.f1.emailid.value=="")
	{
		alert("Please Enter Email");
		document.f1.emailid.focus();
		return false;
	}
	if(document.f1.emailid.value!="")
	{
		if(document.f1.emailid.value.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) == -1)
		{
				alert("Invalid Email Address");
				document.f1.emailid.focus();
				return false;
		}
	}
	
	  if(document.f1.sall.value!="")
	  {
			if (isNaN(document.f1.sall.value))
			{
			alert("Please Enter numeric only.");
			document.f1.sall.focus();
			return false;
			}
	  }
	  if(document.f1.ssnum.value!="")
	  {
			if (isNaN(document.f1.ssnum.value))
			{
			alert("Please Enter numeric only.");
			document.f1.ssnum.focus();
			return false;
			}
	  }
	  if(document.f1.homeph.value!="")
	  {
			if (isNaN(document.f1.homeph.value))
			{
			alert("Please Enter numeric only.");
			document.f1.homeph.focus();
			return false;
			}
	  }
	  if(document.f1.workph.value!="")
	  {
			if (isNaN(document.f1.workph.value))
			{
			alert("Please Enter numeric only.");
			document.f1.workph.focus();
			return false;
			}
	  }
	  if(document.f1.emrphone.value!="")
	  {
			if (isNaN(document.f1.emrphone.value))
			{
			alert("Please Enter numeric only.");
			document.f1.emrphone.focus();
			return false;
			}
	  }
	  if(document.f1.grade1.value!="")
	  {
			if (isNaN(document.f1.grade1.value))
			{
			alert("Please Enter numeric only.");
			document.f1.grade1.focus();
			return false;
			}
	  }
	  if(document.f1.grade2.value!="")
	  {
			if (isNaN(document.f1.grade2.value))
			{
			alert("Please Enter numeric only.");
			document.f1.grade2.focus();
			return false;
			}
	  }
	  if(document.f1.grade3.value!="")
	  {
			if (isNaN(document.f1.grade3.value))
			{
			alert("Please Enter numeric only.");
			document.f1.grade3.focus();
			return false;
			}
	  }
	  if(document.f1.grade4.value!="")
	  {
			if (isNaN(document.f1.grade4.value))
			{
			alert("Please Enter numeric only.");
			document.f1.grade4.focus();
			return false;
			}
	  }
	  if(document.f1.grade5.value!="")
	  {
			if (isNaN(document.f1.grade5.value))
			{
			alert("Please Enter numeric only.");
			document.f1.grade5.focus();
			return false;
			}
	  }
}

