function Trim(nStr){return nStr.replace(/(^\s*)|(\s*$)/g, "");}
function fnPaste(){event.returnValue=false;}
function isNull(obj,msg){
	if(msg!="Password")
		obj1=Trim(obj.value);
	else
		obj1=obj.value;
	if (obj1==""){
		alert("Please enter the " +msg);
		obj.focus();
		return true;
	}else
		return false;
}
function isNullDate(obj,msg){
	if(msg!="Password")
		obj1=Trim(obj.value);
	else
		obj1=obj.value;
	if (obj1==""){
		alert("Please select the " +msg);
		obj.focus();
		return true;
	}else
		return false;
}

function isLen(obj,siz,msg){
	if(msg!="Password")
		obj1=Trim(obj.value);
	else
		obj1=obj.value;
	if(obj1!=""){
		var strLen=obj.value;
		if(strLen.length < siz){
			alert(msg+" should be atleast " + siz + " characters");
			obj.focus();
			return true;  
		} 
	}else
		return false;
}
function isSame(obj1,obj2,msg1,msg2){
	if((Trim(obj1.value))==(Trim(obj2.value))){
		alert(msg1+" is matched with the "+msg2);
		obj2.focus();
		return true;
	}else
		return false;
}	
function isNotSame(obj1,obj2,msg1,msg2){
	if((Trim(obj1.value))!=(Trim(obj2.value))){
		alert(msg1+" does not match");
		obj2.focus();
		return true;
	}else
		return false;
}	
function isCorrect(obj1,obj2,msg1,msg2){
	if((Trim(obj1.value)) >= (Trim(obj2.value))){
		alert(msg1+" should be less than "+msg2);
		obj2.focus();
		return true;
	}else
		return false;
}	
function isCorrect1(obj1,obj2,msg1,msg2){
	if((Trim(obj1.value)) > (Trim(obj2.value))){
		alert(msg1+" should be less than "+msg2);
		obj2.focus();
		return true;
	}else
		return false;
}	
function isTxtareaNull(obj,msg){
	if(Trim(obj.innerText) == ""){
		alert("Please enter " + msg);
		obj.focus();
		return true;
	}else
		return false;
}
function isTxtareaLen(obj,msg){
	if(obj.innerHTML.length > 255){
		alert("Please enter below 256 characters in " + msg);
		obj.focus();
		return true;
	}else
		return false;
}
function notEmail(obj,msg){
	var exp=/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/;
	if (!exp.test(obj.value)){
		alert("Please enter valid "+msg);
		obj.focus();
		return true;		
	}else
		return false;
}
function notZipcode(obj,msg){
	exp = /[a-zA-Z|\d]-{1}/;
	if (!exp.test(obj.value)){
		alert("Please enter valid "+msg);
		obj.focus();
		return true;
	}else
		return false;
}
function notChecked(obj,msg){
	checked = false;
	if(obj.length){
		for(i=0;i<obj.length;i++){
			if(obj[i].checked){
				checked = true;break;
			}
		}
	}else if(obj.checked)
		checked = true;
	if(!(checked)){
		alert("Please select the "+msg);
		//if(obj.length)
		//	obj[0].focus();
		//else
		//	obj.focus();
		return true;
	}
}
function notSelected(obj,msg){
	
	if (obj.options[obj.selectedIndex].value == ""){
		alert("Please select the "+ msg);
		obj.focus();
		return true;		
	}else
		return false;
}
function fnTel(obj,msg){
	exp = /^\+?[0-9+ -]*$/;
	if (!exp.test(obj.value)){
		alert("Please enter only numeric values in "+msg);
		obj.focus();
		return true;
	}else
		return false;
}
function notImageFile(obj,msg){
	var exp = /^.+\.(jpg|gif|jpeg|JPG|JPEG|GIF)$/;
	if (!exp.test((obj.value).toLowerCase())){
		alert("Please choose jpg or gif file for "+msg);
		obj.focus();
		return true;
	}else
		return false;
}
function notPdfFile(obj,msg){
	var exp = /^.+\.(pdf|PDF)$/;
	if (!exp.test((obj.value).toLowerCase())){
		alert("Please choose pdf file for "+msg);
		obj.focus();
		return true;
	}else
		return false;
}

function notCsvFile(obj,msg){
	var exp = /^.+\.(csv|CSV)$/;
	if (!exp.test((obj.value).toLowerCase())) {
		alert("Please choose csv file for "+msg);
		obj.focus();
		return true;
	}else
		return false;
}

function notPdfFileORWordDoc(obj,msg){
	var exp = /^.+\.(pdf|PDF|doc|DOC)$/;
	if (!exp.test((obj.value).toLowerCase())){
		alert("Please choose pdf or word document file for "+msg);
		obj.focus();
		return true;
	}else
		return false;
}
function notVideo(obj,msg){
	var exp = /^.+\.(mp4|MP4|mov|MOV|asf|ASF|flv|FLV|mpg|MPG|avi|AVI|mpeg|MPEG|mpeg4|MPEG4|wmv|WMV|rm|RM|dat)$/;
	if (!exp.test((obj.value).toLowerCase())){
		alert("Please choose a valid video format for "+msg);
		obj.focus();
		return true;
	}else
		return false;
}
function notDocFile(obj,msg){
	if(Trim(obj.value)!=""){
		var exp = /^.+\.(RTF|rtf|DOC|doc|TXT|txt)$/;
		if (!exp.test((obj.value).toLowerCase())){
			alert("Please choose doc or txt file for "+msg);
			obj.value="";
			obj.focus();
			return true;
		}else
			return false;	
	}else
		return false;
}
function notPdfDocFile(obj,msg){
	var exp = /^.+\.(pdf|doc|PDF|DOC)$/;
	if (!exp.test((obj.value).toLowerCase())){
		alert("Please choose pdf or doc file for "+msg);
		obj.value="";
		obj.focus();
		return true;
	}else
		return false;
}

function notPrice(obj,msg){
	exp = /^[\d]*[\.]{0,1}[\d]{1,2}$/;
	if (!exp.test(obj.value)){
		alert("Please enter valid "+msg);
		obj.focus();
		return true;
	}else
		return false;
}
function fnChkNum(obj,msg){
	exp = /^[\d]/;
	if (!exp.test(obj.value)){
		alert("Please enter only numeric values in "+msg);
		obj.focus();
		return true;
	}else
		return false;
}
function fnChkNum1(obj)
{
  	exp1 = /[^0-9]/;
	if (exp1.test(obj.value))
	{
		alert("Only  numbers(0-9) are allowed");
		obj.value = "";
		obj.focus();
		return true;
	}
 }
function fnChkNum2(obj)
{
  	exp1 = /[^0-9]/;
	if (exp1.test(obj.value))
	{
		alert("Only  numbers(0-9) are allowed");
		obj.value = "";
		obj.focus();
		return true;
	}
 }


function fnChkAlpha(obj,msg)
{
	exp = (/(^([a-z]|[A-Z]|["."]|[\s])*$)/);
	if (!exp.test(obj.value))
	{
		alert("Please enter only alphabets in "+msg);
		obj.focus();
		return true;
	}
	else
		return false;
}	

function fnChkAlphaNum(obj,msg){
	exp = (/(^([a-z]|[A-Z]|[0-9])*$)/);
	if (!exp.test(obj.value)){
		alert("Please enter only alphanumeric in "+msg);
		obj.focus();
		return true;
	}else
		return false;
}
function fnChkAlphaNumeric(obj,msg){
	var alpha = /[a-zA-Z|]/;
	var Num = /[\d]/;
	if (!(Alpha.test(obj.value) && Num.test(obj.value))){
		alert("Please enter only alphanumeric in "+msg);
		obj.focus();
		return true;
	}else
		return false;
}
//Search Function Search Starts
function SearchValidate(e,links){
	if (e.keyCode == 13){
		var Search = document.getElementById("search");
		if(Search.value == 'Search...' || Trim(Search.value) == ''){
			alert("Please enter the keyword to search");
			Search.focus();
			return false;
		}
		document.SearchForm.action = links+"search.php";
		document.SearchForm.submit();	
	}
}
function setfocus(){
  if(document.getElementById("search").value=="Search...")  {
		document.getElementById("search").value="";
  }
}
function offfocus(){
  if(document.getElementById("search").value=="") {
		document.getElementById("search").value="Search...";
  }
}
function fnKeySearch(links){
	var Search = document.getElementById("search");
	if(Search.value == 'Search...' || Trim(Search.value) == ''){
		alert("Please enter the keyword to search");
		Search.focus();
		return false;
	}
	document.SearchForm.action = links+"search.php";
	document.SearchForm.submit();	
}
//Search Function Search Ends

/* Registration Vlidation*/

function validateRegister(){
	if(isNull(document.frmRegister.txtUser,"username")){ return false; }
	if(isNull(document.frmRegister.txtPass,"password")){ return false; }
	if(isLen(document.frmRegister.txtPass,5,"password")){return false;}
	if(isNull(document.frmRegister.txtName,"name")){ return false; }
	if(isNull(document.frmRegister.txtDate,"DOB")) { return false; }
	age=document.frmRegister.txtDate.value;
	year=age.split("-");
	var today = new Date();
	var year11  = today.getYear();
	if (year11 < 1900)
	{
	  year11 += 1900;
	}
	year11=year11-15;	
	if(year[2]>=year11)
	{
	  alert("Please Enter valid Date of Birth");
	  return false;
	}
	if(notSelected(document.frmRegister.cmbFrom,"batch starting year")) { return false; }
	if(notSelected(document.frmRegister.cmbTo,"batch ending year")) { return false; }
	if(eval(document.frmRegister.cmbFrom.value)>eval(document.frmRegister.cmbTo.value))  
		{
			alert("Starting Year Should be less than Ending Year");
			return false;
		}
		
	if (isNull(document.frmRegister.txtEmail,"email id")){ return false; }
	if (notEmail(document.frmRegister.txtEmail,"email id")){ return false; }	
	if(notSelected(document.frmRegister.cmbDepart,"department")) { return false; }
	if(notSelected(document.frmRegister.cmbCourse,"course")) { return false; }
	
	if (isNull(document.frmRegister.txtContactaddr,"contact address")){ return false; }
	if (isNull(document.frmRegister.txtCCity,"city")){ return false; }
	if (isNull(document.frmRegister.txtCState,"state")){ return false; }
	if (notSelected(document.frmRegister.cmbCCountry,"country")){ return false; }
	if (isNull(document.frmRegister.txtCPin,"pincode")){ return false; }
	if(document.frmRegister.txtCPin.value!=""){
		if (fnTel(document.frmRegister.txtCPin,"pincode")){ return false; }
	}
	if (isNull(document.frmRegister.txtCPhone,"pincode")){ return false; }
	if(document.frmRegister.txtCPhone.value!=""){
		if (fnTel(document.frmRegister.txtCPhone,"phone")){ return false; }
	}
	
	
	
	$count=document.frmRegister.hidcount.value;
	objimagetitle 		= document.getElementsByName("txtcompany[]");
	objimagefile		= document.getElementsByName("cmbJfrom[]");
	objhidFile             = document.getElementsByName("cmbJto[]");
	for($i=0;$i<objimagetitle.length;$i++){
		if(isNull(objimagetitle[$i],"company")){ return false; }
		if(notSelected(objimagefile[$i],"year from")) { return false; }
		if(notSelected(objhidFile[$i],"year to")) { return false; }
	}
	
	
}
function fnPerm() {
	if(document.frmRegister.chkPerm.checked==true){
		document.getElementById('txtPermaddr').value =document.getElementById('txtContactaddr').value;
		document.frmRegister.txtPCity.value = document.frmRegister.txtCCity.value;
		document.frmRegister.txtPState.value = document.frmRegister.txtCState.value;
		document.frmRegister.cmbPCountry.selectedIndex = document.frmRegister.cmbCCountry.selectedIndex;
		document.frmRegister.txtPPhone.value = document.frmRegister.txtCPhone.value;
		document.frmRegister.txtPPin.value = document.frmRegister.txtCPin.value;
	}else{
		document.getElementById('txtPermaddr').value =null;	
		document.frmRegister.txtPermaddr.innerText = '';
		document.frmRegister.txtPCity.value = '';
		document.frmRegister.txtPState.value = '';
		document.frmRegister.cmbPCountry.selectedIndex = '';
		document.frmRegister.txtPPhone.value ='';
		document.frmRegister.txtPPin.value = '';
	}

}

function hidetext(arg,arg1){
	if(arg=="frmSearch"){
		if (Trim(arg1) == 'Enter a Keyword')
		{
			document.getElementById('txtSearch').value = '';
		}else if(Trim(arg1) ==''){
			document.getElementById('txtSearch').value = 'Enter a Keyword';	
		}
		
	}
	
	if(arg=="frmLogin"){
		if (Trim(arg1) == 'Enter Username')
		{
			document.getElementById('txtUser').value = '';
		}else if(Trim(arg1) ==''){
			document.getElementById('txtUser').value = 'Enter Username';	
		}
		
		if (Trim(arg1) == 'Enter Password')
		{
			document.getElementById('txtPass').value = '';
		}else if(Trim(arg1) ==''){
			document.getElementById('txtPass').value = 'Enter Password';	
		}
		
	}
	
}

function validateLogin(){
	
	if(document.frmLogin.txtUser.value=='Enter Username'){
			alert("Please enter username");
			document.frmLogin.txtUser.focus();
			return false;
	}
	if(document.frmLogin.txtPass.value=='Enter Password'){
			alert("Please enter password");
			document.frmLogin.txtPass.focus();
			return false;
	}
	if(isNull(document.frmLogin.txtUser,"username")){ return false;}
	if(isNull(document.frmLogin.txtPass,"password")){ return false;}
}

function validateSearch(){
	if(document.frmSearch.txtSearch.value=='Enter a Keyword'){
		alert("Please enter keyword");
		document.frmSearch.txtSearch.focus();
		return false;
	}
}
function fnValidate(){
		if(isNull(document.thisForm.txtEmail,"email id")){return false; }
		if (notEmail(document.thisForm.txtEmail,"email id")){ return false; }	
}
