
var whitespace = " \t\n\r"
function isEmpty(s)
{
   return ((s == null) || (s.length == 0))
}
function isWhitespace (s)
{ 
	var i;
	if (isEmpty(s)) return true;

	 for (i = 0; i < s.length; i++)
	 {   
		var c = s.charAt(i);
 
		 if (whitespace.indexOf(c) == -1) return false;
	 }
 
	 return true;
}
function isCharsInBag (s, bag)
{  
  var i;
   for (i = 0; i < s.length; i++)
  {   
	  var c = s.charAt(i);
	  if (bag.indexOf(c) == -1) return false;
  }
  return true;
}

function ChkAuthenticationValidation(frm)
{

   if (isWhitespace(frm.username.value))
	{
		alert("Username cannot be left blank");
		frm.username.focus();
		return false;
	}
  
  /* if(isWhitespace(frm.password.value))
   {
	alert("Password cannot be left blank");
	frm.password.focus();
	return false;
   }*/
  
}

function mainmenu(frm)
{

   if (isWhitespace(frm.title.value))
	{
		alert("Username cannot be left blank");
		frm.username.focus();
		return false;
	}
  
    
}
function ChkGalarytype(frm)
{

   if (isWhitespace(frm.galary.value))
	{
		alert("Galary type cannot be left blank");
		frm.username.focus();
		return false;
	}
  
    
}

function validateSubMenu(frm)
{
	if(frm.menu.value=="")
	{
		alert("Please Select Menu");
		frm.menu.focus();
		return false;
	}

	if(frm.submenu.value=="")
	{
		alert("Please Enter Sub Menu");
		frm.submenu.focus();
		return false;
	}

	if(frm.title.value=="")
	{
		alert("Please Enter Title");
		frm.title.focus();
		return false;
	}

	return true;

}



function confirmDelete(delUrl) {
  if (confirm("Are you sure you want to delete")) {
    document.location = delUrl;
  }
}
function paging(page)
{
	form3.PageNo.value = page;
	form3.submit();
}



function Validatephoto(thePhoto)
{
	
	if(thePhoto.galarytype.value=="")
	{
		alert("Plese Select The Type");
		thePhoto.galarytype.focus();
		return false;
	}
	
	
	if(thePhoto.exist.value=="" && thePhoto.photo.value=="")
	{
	   alert("Please Upload the photo");
	   thePhoto.photo.focus();
	   return false;
	}
	else if(thePhoto.photo.value!="")
	{
		var str=thePhoto.photo.value;
		var fname = str.lastIndexOf(".");
		var fname = str.substr(fname+1);
		var fname = fname.toLowerCase();
		//alert(fname);
		if (fname == 'jpg' || fname == 'gif')
		{
			
		}
		else
		{
			alert("Only .jpg or .gif files will be accepted");
			thePhoto.photo.focus();
			return false;
		}
		
	
	}
	return true;
	
	}
		
function Validatephoto(thePhoto)
{
	
	
	if(thePhoto.galarytype.value=="")
	{
		alert("Plese Select The Type");
		thePhoto.galarytype.focus();
		return false;
	}
	
	
		
	if(thePhoto.website.value=="")
	{
		alert("Plese Enter Website");
		thePhoto.website.focus();
		return false;
	}
	else
	{
		var website=thePhoto.website.value;
		webRE=/^[wW]{3}\.[a-zA-Z0-9._-]+\.[a-zA-Z]{2,4}$/;
		if(!website.match(webRE))
		{
			alert("Please check the website address\nEx:www.indochinaalliance.org");
			thePhoto.website.focus();
			return false;
		}
	}
	if(thePhoto.photo.value=="")
	{
	   alert("Please Upload the photo");
	   thePhoto.photo.focus();
	   return false;
	}
	else
	{
		var str=thePhoto.photo.value;
		var fname = str.lastIndexOf(".");
		var fname = str.substr(fname+1);
		var fname = fname.toLowerCase();
		//alert(fname);
		if(thePhoto.galarytype.value=='photo')
		{
			if (fname == 'jpg' || fname == 'jpeg' || fname == 'gif')
			{
				
			}
			else
			{
				alert("Only .jpg or .gif files will be accepted");
				thePhoto.photo.focus();
				return false;
			}
		}
		else
		{
			if (fname == 'swf')
			{
				
			}
			else
			{
				alert("Only .swf files will be accepted");
				thePhoto.photo.focus();
				return false;
			}
		}
		
	
	}
	return true;
	
	}
function changepassword(pchange)
{
	if(pchange.oldpass.value=='')
	{
		alert("Enter Old Password");
		pchange.oldpass.focus();
		return false;
	}
	if(pchange.newpass.value=='')
	{
		alert("Enter New Password");
		pchange.newpass.focus();
		return false;
	}
	if(pchange.confirmpass.value=='')
	{
		alert("Please Confirm the Password");
		pchange.confirmpass.focus();
		return false;
	}
	if(pchange.confirmpass.value!=pchange.newpass.value)
	{
		alert("New Password amd Confirm password are not matched.");
		pchange.confirmpass.focus();
		return false;
	}
	return true;
	
	
}

function ChkjobsValidation(jobs)
{
	
	
		if(jobs.jobtitle.value == "")
    {
		alert("Enter Job Title");
		jobs.jobtitle.focus();
		return false;
	}
	if(jobs.qualification.value == "")
    {
		alert("Enter Qualification");
		jobs.qualification.focus();
		return false;
	}


	if(jobs.vacancies.value == "")
    {
		alert("Enter Number of Vacancies");
		jobs.vacancies.focus();
		return false;
	}
	else
	{
		if(jobs.vacancies.value == 0)
		{
			alert("Vacancies should be greater than zero");
			jobs.vacancies.focus();
			return false;
		}
		else
		{
			var vacancy=jobs.vacancies.value;
			vacancyRE=/^[1-9]*[0-9]$/;
			if(!vacancy.match(vacancyRE))
			{
				alert("Number of vacancies should be a number");
				jobs.vacancies.focus();
				return false;
			}
		}			
	}
	if(jobs.experience.value == "")
    {
		alert("Enter Years of Experience");
		jobs.experience.focus();
		return false;
	}
	else if(isNaN(jobs.experience.value))
	{
		alert("Experience should be a number");
		jobs.experience.focus();
		return false;
	}
	if(jobs.skillset.value == "")
    {
		alert("Enter Skill Set Required");
		jobs.skillset.focus();
		return false;
	}
	

	if(jobs.contactperson.value == "")
    {
		alert("Enter Contact Person Name");
		jobs.contactperson.focus();
		return false;
	}
	
	/*
	if(jobs.phone.value == "")
    {
		alert("Enter Phone Number");
		jobs.phone.focus();
		return false;
	}*/
	if(jobs.phone.value != "")
    
	{
		var telephone=jobs.phone.value;
		phoneRE=/^[0-9]*[0-9-\s]+[0-9]$/;
		if(!telephone.match(phoneRE))
		{
			alert("Invalid Phone Number");
			jobs.phone.focus();
			return false;
		}
	}
  
	
  if(jobs.email.value == "")
  {
		alert("Enter Email Address");
		jobs.email.focus();
		return false;
	}
	else
	{
		var email=jobs.email.value;
		emailRE=/^[a-zA-Z0-9]*[a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+\.[a-zA-Z]{2,4}$/;
		if(!email.match(emailRE))
		{
			alert("Invalid Email Address.\nEx:test@test.com");
			jobs.email.focus();
			return false;
		}
	}
	


	if(jobs.description.value == "")
    {
		alert("Enter Job Description");
		jobs.description.focus();
		return false;
	}
   return true;
}


function Validatephoto(thePhoto)
{
	
	if(thePhoto.galarytype.value=="")
	{
		alert("Plese Select The Type");
		return false;
	}
		
	if(thePhoto.exist.value=="" && thePhoto.photo.value=="")
	{
	   alert("Please Upload the photo");
	   thePhoto.photo.focus();
	   return false;
	}
	else if(thePhoto.photo.value!="")
	{
		var str=thePhoto.photo.value;
		var fname = str.lastIndexOf(".");
		var fname = str.substr(fname+1);
		var fname = fname.toLowerCase();
		//alert(fname);
		if (fname == 'jpg' || fname == 'gif')
		{
			
		}
		else
		{
			alert("Only .jpg or .gif files will be accepted");
			thePhoto.photo.focus();
			return false;
		}
		
	
	}
	return true;
	
	}

	
function ValidateEditphoto(thePhoto)
{
	
	if(thePhoto.galarytype.value=="")
	{
		alert("Plese Select The Type");
		thePhoto.galarytype.focus();
		return false;
	}
	
	
	if(thePhoto.exist.value=="" && thePhoto.photo.value=="")
	{
	   alert("Please Upload the photo");
	   thePhoto.photo.focus();
	   return false;
	}
	else if(thePhoto.photo.value!="")
	{
		var str=thePhoto.photo.value;
		var fname = str.lastIndexOf(".");
		var fname = str.substr(fname+1);
		var fname = fname.toLowerCase();
		//alert(fname);
		if (fname == 'jpg' || fname == 'gif')
		{
			
		}
		else
		{
			alert("Only .jpg or .gif files will be accepted");
			thePhoto.photo.focus();
			return false;
		}
		
	
	}
	return true;
	
	}

function getInnerLinks()
{
	var url="www.kbpcollegevashi.net/cms.php?page=" + document.frmmain.innerpage.value;
	document.getElementById('innerlink').innerHTML=url;
	
}
function page(page1)
{
	frmpage.PageNo.value = page1;
	frmpage.submit();
}
function ChkEmployeeValidation(employee)
{
	

	if(employee.name.value == "")
    {
		alert("Please Enter Full Name");
		employee.name.focus();
		return false;
	}
	if(employee.qualification.value == "")
    {
		alert("Please Enter Qualification");
		employee.qualification.focus();
		return false;
	}

	if(employee.experience.value == "")
    {
		alert("Please Enter Years of Experience");
		employee.experience.focus();
		return false;
	}
	else if(isNaN(employee.experience.value))
	{
		alert("Experience should be a number");
		employee.experience.focus();
		return false;
	}
	if(employee.city.value == "")
    {
		alert("Please Enter City");
		employee.city.focus();
		return false;
	}
	
	
	if(employee.phone.value == "")
    {
		alert("Please Enter Phone Number");
		employee.phone.focus();
		return false;
	}
	else
	{
		var telephone=employee.phone.value;
		phoneRE=/^[0-9]*[0-9-\s]+[0-9]$/;
		if(!telephone.match(phoneRE))
		{
			alert("Invalid Phone Number");
			employee.phone.focus();
			return false;
		}
	}
	
	if(employee.email.value == "")
    {
		alert("Please Enter Email Address");
		employee.email.focus();
		return false;
	}
	else
	{
		var email=employee.email.value;
		emailRE=/^[a-zA-Z0-9]*[a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+\.[a-zA-Z]{2,4}$/;
		if(!email.match(emailRE))
		{
			alert("Invalid Email Address.\nEx:test@test.com");
			employee.email.focus();
			return false;
		}
	}
	
	if(employee.cv.value == "")
    {
		alert("Upload CV");
		employee.cv.focus();
		return false;
	}
	else
	{
		var str=employee.cv.value;
		var fname = str.lastIndexOf(".");
		var fname = str.substr(fname+1);
		var fname = fname.toLowerCase();
		//alert(fname);
		if (fname == 'doc')
		{
			
		}
		else
		{
			alert("Only .doc files will be accepted");
			employee.cv.focus();
			return false;
		}
		
	
	}
	
   return true;
}

		
function ChkContactValidation(frm)
{

   if(frm.fullname.value == "")
   {
	alert("Name cannot be left blank");
	frm.fullname.focus();
	return false;
   }
   if(frm.address.value == "")
   {
	alert("Address cannot be left blank");
	frm.address.focus();
	return false;
   }
    if(frm.city.value == "")
   {
	alert("City cannot be left blank");
	frm.city.focus();
	return false;
   }
    if(frm.email.value == "")
   {
	alert("Please Enter Email Address");
	frm.email.focus();
	return false;
   }
   if(frm.email.value!='')
	{
		var email=frm.email.value;
		emailRE=/^[a-zA-Z0-9]*[a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+\.[a-zA-Z]{2,4}$/;
		if(!email.match(emailRE))
		{
			alert("Invalid Email Address.");
			frm.email.focus();
			return false;
		}
	}
	if(frm.phone.value=='')
	{
		alert("Please Enter Phone Number");
		frm.phone.focus();
		return false;
	}
	if(frm.phone.value!='')
	{
		var phone=frm.phone.value;
		phoneRE=/^[0-9]*[0-9 -]*[0-9]$/;
		if(!phone.match(phoneRE))
		{
			alert("Invalid Phone Number.");
			frm.phone.focus();
			return false;
		}
	}
	if(frm.comments.value == "")
   {
	alert("Please Enter Comments");
	frm.comments.focus();
	return false;
   }
	
	return true;
  
}
function trim(str, chars) {
    return ltrim(rtrim(str, chars), chars);
}

function ltrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}

function rtrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}

function page(page1)
{
	frmpage.PageNo.value = page1;
	frmpage.submit();
}

function delchkd(del)
	{
		var v = 0;
		for (i=0; i<del.elements.length; i++) 
		{
			if (del.elements[i].type=="checkbox") 
			{
				if (del.elements[i].checked) 
				{
					v += 1;
				}
			}
		}
		
		if (v==0) 
		{
			alert("Please check atleast one check box to delete!");
			return false;
		} 
		else 
		{
			if (confirm("are you sure you want to delete the selected option(s)?")) 
			{
				return true;
			}
			else 
			{
				return false;
			}
		}
	}

	function ChkAluminiValidation(alumini)
{
	

	if(alumini.name.value == "")
    {
		alert("Please Enter Name");
		alumini.name.focus();
		return false;
	}
	if(alumini.batch.value == "")
    {
		alert("Please Enter Batch");
		alumini.batch.focus();
		return false;
	}
	if(alumini.year.value == "")
    {
		alert("Please Enter Year");
		alumini.year.focus();
		return false;
	}
	else
	{
		var year=alumini.year.value;
		yearRE=/^[0-9]*[0-9-\s]+[0-9]$/;
		if(!year.match(yearRE))
		{
			alert("Invalid Year");
			alumini.year.focus();
			return false;
		}
		var le=year;
		
	}


	if(alumini.address.value == "")
    {
		alert("Please Enter Address");
		alumini.address.focus();
		return false;
	}
	
	
	
	if(alumini.email.value == "")
    {
		alert("Please Enter Email Address");
		alumini.email.focus();
		return false;
	}
	else
	{
		var email=alumini.email.value;
		emailRE=/^[a-zA-Z0-9]*[a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+\.[a-zA-Z]{2,4}$/;
		if(!email.match(emailRE))
		{
			alert("Invalid Email Address.\nEx:test@test.com");
			alumini.email.focus();
			return false;
		}
	}
	if(alumini.phone.value == "")
    {
		alert("Please Enter Mobile Number");
		alumini.phone.focus();
		return false;
	}
	else
	{
		var telephone=alumini.phone.value;
		phoneRE=/^[0-9]*[0-9-\s]+[0-9]$/;
		if(!telephone.match(phoneRE))
		{
			alert("Invalid Mobile Number");
			alumini.phone.focus();
			return false;
		}
	}
	
	/*if(alumini.photo.value == "")
    {
		alert("Upload Photo");
		alumini.photo.focus();
		return false;
	}*/
	if(alumini.photo.value != "")
	{
		var str=alumini.photo.value;
		var fname = str.lastIndexOf(".");
		var fname = str.substr(fname+1);
		var fname = fname.toLowerCase();
		//alert(fname);
		if (fname == 'jpg' || fname == 'jpeg' || fname == 'gif')
		{
			
		}
		else
		{
			alert("Only .jpg, .gif files will be accepted");
			alumini.photo.focus();
			return false;
		}
	if(alumini.commen.value == "")
    {
		alert("Please Enter Comments");
		alumini.commen.focus();
		return false;
	}
	
	}
	
   return true;
}	

