function returnFalse(obj){
	obj.focus();
	return false;
}

function checkLogin(){
	if (trim(document.loginFrm.pwd.value)=="")	{
		alert("Please enter password.");
		return returnFalse(document.loginFrm.pwd);
	}else{
		if (validatePassword(trim(document.loginFrm.pwd.value))==false){
			alert("Invalid password.");
			return returnFalse(document.loginFrm.pwd);
		}
	}
	document.loginFrm.submit();
}

function NewsValidate(id){		
		if(trim(document.frm.title.value)==""){
			alert('Please enter the Title.');
			return returnFalse(document.frm.title);
		}
		if(trim(document.frm.description.value)==""){
			alert('Please enter the Description.');
			return returnFalse(document.frm.description);
		}
		if(trim(document.frm.f1.value)!=""){
			if(document.frm.f1.value.toLowerCase().indexOf(".pdf")<0){
				alert('Please enter PDF News File.');
				return returnFalse(document.frm.f1);
			}
		}
		/*if(trim(document.frm.f1.value)==""){
			alert('Please enter the News File.');
			return returnFalse(document.frm.f1);
		}*/
		if (id>0) document.frm.action="addnews.asp?u=u&id="+id
		document.frm.submit();
}
	function MarketingValidate(id){		
		if(trim(document.frm.title.value)==""){
			alert('Please enter the Title.');
			return returnFalse(document.frm.title);
		}
		if(trim(document.frm.f1.value)==""){
			alert('Please enter the News File.');
			return returnFalse(document.frm.f1);
		}
		if (id>0) document.frm.action="marketing.asp?u=u&id="+id
		document.frm.submit();
}
	
	function JobsValidate(id){		
		if(trim(document.frm.jobstitle.value)==""){
			alert('Please enter the Jobs Title.');
			return returnFalse(document.frm.jobstitle);
		}
		if(trim(document.frm.jobsdescription.value)==""){
			alert('Please enter the Jobs Description.');
			return returnFalse(document.frm.jobsdescription);
		}
		if (id>0) document.frm.action="addjobs.asp?u=u&id="+id
		
		document.frm.submit();
}


function RegistrationValidate(id)
{
	if(trim(document.frm.last_name.value)=="")
	{
		alert('Please enter the Last Name.');
		return returnFalse(document.frm.last_name);
	}
	else if(checksalutation(trim(document.frm.last_name.value))==false){
		alert('Invalid Last Name.');
		return returnFalse(document.frm.last_name);
	}
	if(trim(document.frm.first_name.value)=="")
	{
		alert('Please enter the First Name.');
		return returnFalse(document.frm.first_name);
	}
		
	else if(checksalutation(trim(document.frm.first_name.value))==false){
		alert('Invalid First Name.');
		return returnFalse(document.frm.first_name);
	}
	
	if(trim(document.frm.customer_number.value)=="")
	{
		alert('Please enter the Customer Number.');
		return returnFalse(document.frm.customer_number);
	}
	else if(checksalutation(trim(document.frm.customer_number.value))==false){
		alert('Invalid Customer Number.');
		return returnFalse(document.frm.customer_number);
	
	}
	if(trim(document.frm.attendees.value)=="")
	{
		alert('Please enter the Attendees.');
		return returnFalse(document.frm.attendees);
	}
	if(trim(document.frm.company.value)=="")
	{
		alert('Please enter the Company.');
		return returnFalse(document.frm.company);
	}
	//alert(id)
	if(id==0){
		document.frm.action="addregistration.asp?s=y"
	}
	else{
		document.frm.action="addregistration.asp?a=a&id="+id
	}
	document.frm.submit();
}




function editCategory( paraFlag, id ){	
		if(trim(document.frmCategory.category_name.value)==""){
			alert('Please enter the Category name.');
			return returnFalse(document.frmCategory.category_name);
		}
		document.frmCategory.action="save_category.php?id="+id;
		document.frmCategory.actionFlag.value=paraFlag;
		document.frmCategory.submit();
}
	
function delCategory( paraid ){
	if (confirm("Are you sure you want to delete this Category?"))	{
		document.frmCategoryList.category_id.value = paraid;
		document.frmCategoryList.actionFlag.value = "delCategory";		
		document.frmCategoryList.submit();
	}
}
			
function getEquipments(category){
	var form = document.frm;
	form.categoryID.value=category;
	form.action = "equipments.php";
	form.submit();
}

function countChars(){
	var form = document.frm1;
	if(form.descTxt.value.length>500){
		form.descTxt.value = form.descTxt.value.substr(0,500);
		form.lengthTxt.value = 0;
	}
	else form.lengthTxt.value=500-form.descTxt.value.length;
}

function addeditEquipment( paraFlag, id ){	
		if(trim(document.frmEquipment.parent_category_id.selectedIndex)==0){
			alert('Please select Equipment category.');
			return returnFalse(document.frmEquipment.parent_category_id);
		}
		if(trim(document.frmEquipment.equipment_name.value)==""){
			alert('Please enter the Equipment name.');
			return returnFalse(document.frmEquipment.equipment_name);
		}
		
		if((trim(document.frmEquipment.hrs2_rent.value)=="")&&
		  (trim(document.frmEquipment.hrs4_rent.value)=="")&&
		  (trim(document.frmEquipment.day1_rent.value)=="")&&
		  (trim(document.frmEquipment.week1_rent.value)=="")&&
		  (trim(document.frmEquipment.month1_rent.value)=="")){
			alert('Please enter the rent.');
			return returnFalse(document.frmEquipment.hrs2_rent);
		}
		
		if(trim(document.frmEquipment.hrs2_rent.value)!=""){
			if (!isFloat(trim(document.frmEquipment.hrs2_rent.value))){
				alert('Invalid rent amount for 2 hrs.');
				return returnFalse(document.frmEquipment.hrs2_rent);
			}
		}else document.frmEquipment.hrs2_rent.value=0;
		
		if(trim(document.frmEquipment.hrs4_rent.value)!=""){
			if (!isFloat(trim(document.frmEquipment.hrs4_rent.value))){
				alert('Invalid rent amount for 4 hrs.');
				return returnFalse(document.frmEquipment.hrs4_rent);
			}
		}else document.frmEquipment.hrs4_rent.value=0;
		
		if(trim(document.frmEquipment.day1_rent.value)!=""){
			if (!isFloat(trim(document.frmEquipment.day1_rent.value))){
				alert('Invalid rent amount for 1 day.');
				return returnFalse(document.frmEquipment.day1_rent);
			}
		}else document.frmEquipment.day1_rent.value=0;
		
		if(trim(document.frmEquipment.week1_rent.value)!=""){
			if (!isFloat(trim(document.frmEquipment.week1_rent.value))){
				alert('Invalid rent amount for 1 week.');
				return returnFalse(document.frmEquipment.week1_rent);
			}
		}else document.frmEquipment.week1_rent.value=0;
		
		if(trim(document.frmEquipment.month1_rent.value)!=""){
			if (!isFloat(trim(document.frmEquipment.month1_rent.value))){
				alert('Invalid rent amount for 1 month.');
				return returnFalse(document.frmEquipment.month1_rent);
			}
		}else document.frmEquipment.month1_rent.value=0;
		
		document.frmEquipment.action="save_equipment.php?id="+id;
		document.frmEquipment.actionFlag.value=paraFlag;
		document.frmEquipment.submit();
	}
	
function delEquipment( paraid ){
	if (confirm("Are you sure you want to delete this Equipment?"))
	{
		document.frmEquipmentList.equipment_id.value = paraid;
		document.frmEquipmentList.actionFlag.value = "delEquipment";		
		document.frmEquipmentList.submit();
	}
}

function validateChangedPassword(){
	if(trim(document.pwdFrm.old_pwd.value)==""){
		alert("Please enter old password.");
		return returnFalse(document.pwdFrm.old_pwd);
	}
	if(trim(document.pwdFrm.new_pwd.value)==""){
		alert("Please enter new password.");
		return returnFalse(document.pwdFrm.new_pwd);
	}
	else{
		if(validatePassword(document.pwdFrm.new_pwd.value)==false){
			alert("Invalid new password");
			return returnFalse(document.pwdFrm.new_pwd);
		}
	}
	if(trim(document.pwdFrm.new_pwd.value)!=trim(document.pwdFrm.conf_pwd.value)){
		alert("Confirm password failed.");
		return returnFalse(document.pwdFrm.conf_pwd);
	}
	document.pwdFrm.submit();
}


function validateFlower(id){
	form = document.frm;
	
	if(trim(form.parent_cat.value)==""){
		alert("Please select category.")
		return returnFalse(form.parent_cat);
	}
	if(trim(form.title.value)==""){
		alert("Please enter title.")
		return returnFalse(form.title);
	}
	/*if(trim(form.desc.value)==""){
		alert("Please enter description.")
		return returnFalse(form.desc);
	}*/
	
	if(id==0){
		if(trim(form.Flimg.value)==""){
			alert("Please browse for product image.");
			return returnFalse(form.Flimg);
		}
		else{
		rest = form.Flimg.value.substr(form.Flimg.value.length-3,form.Flimg.value.length);
		lower=rest.toLowerCase();
	
	if(lower!="jpg" && lower!="jpeg" && lower!="png")
	{
		alert("Please Upload Only JPG and PNG File");
		return returnFalse(form.Flimg);
	}
  }
}


	if(id==0) form.action="db_project.php?a=i";
	else form.action="db_project.php?a=u&id="+id;
	
	form.submit()
}

function validateFlower(id){
	form = document.frm;
	if(trim(form.parent_cat.value)==""){
		alert("Please select category.")
		return returnFalse(form.parent_cat);
	}
	if(trim(form.title.value)==""){
		alert("Please enter title.")
		return returnFalse(form.title);
	}
 	if(id==0){
		if(trim(form.Flimg.value)==""){
			alert("Please browse for product image.");
			return returnFalse(form.Flimg);
		} else {
			rest = form.Flimg.value.substr(form.Flimg.value.length-3,form.Flimg.value.length);
			lower=rest.toLowerCase();
			if(lower!="jpg" && lower!="jpeg" && lower!="png")
			{
				alert("Please Upload Only JPG and PNG File");
				return returnFalse(form.Flimg);
			}
	   }
	}
 	if(id==0) form.action="db_project.php?a=i";
	else form.action="db_project.php?a=u&id="+id;
 	form.submit()
}

function validateFeature(id){
	form = document.frm;
	if(trim(form.title.value)==""){
		alert("Please enter title.")
		return returnFalse(form.title);
	}
 	if(id==0){
		if(trim(form.Flimg.value)==""){
			alert("Please browse for product image.");
			return returnFalse(form.Flimg);
		} else {
			rest = form.Flimg.value.substr(form.Flimg.value.length-3,form.Flimg.value.length);
			lower=rest.toLowerCase();
			if(lower!="jpg" && lower!="jpeg" && lower!="png")
			{
				alert("Please Upload Only JPG and PNG File");
				return returnFalse(form.Flimg);
			}
	   }
	}
 	if(id==0) form.action="db_feature.php?a=i";
	else form.action="db_feature.php?a=u&id="+id;
 	form.submit()
}


function returnFalse(obj){
	obj.focus();
	return false;
}


function validateinnerimages(id){

	form = document.frm;	
	
	if(id==0){
		if(trim(form.innerimage.value)==""){
			alert("Please browse for product inner image.");
			return returnFalse(form.innerimage);
		}
		else{
		rest = form.innerimage.value.substr(form.innerimage.value.length-3,form.innerimage.value.length);
		lower=rest.toLowerCase();
	
	if(lower!="jpg" && lower!="jpeg" && lower!="png")
	{
		alert("Please Upload Only JPG and PNG File");
		return returnFalse(form.innerimage);
	}
  }
}
	if(id==0) form.action="db_feat_innerimages.php?a=i&e="+id;
	else form.action="db_feat_innerimages.php?a=u&e="+id;
	form.submit()
}




function validateLink(c,d){
	form = document.frm;
	
	if(trim(form.sellocation.value)==""){
		alert("Please enter Location");
		return returnFalse(form.sellocation);
	}
	if(trim(form.linkname.value)==""){
		alert("Please enter Link name.")
		return returnFalse(form.linkname);
	}
	if(trim(form.txtpdffile.value)!=""){
		var pdfval=form.txtpdffile.value;
		var file = pdfval.substring(pdfval.length -5);
		var ext = file.slice(file.indexOf(".")).toLowerCase();
		if(ext!=".pdf") 
		{
			 alert("Please upload file having .pdf/.PDF extensions.");
			 return returnFalse(form.txtpdffile);
		}
 	}

	
	form.action="db_links.php?c="+c+"&d="+d;
	
	form.submit()

}
function validateLocation(id){
	form = document.frm;
 	if(trim(form.title.value)==""){
		alert("Please enter title.")
		return returnFalse(form.title);
	}
  	if(id==0) form.action="db_locations.php?a=i";
	else form.action="db_locations.php?a=u&id="+id;
 	form.submit();
}
function validateCategory(id){
	form = document.frm;
 	if(trim(form.title.value)==""){
		alert("Please enter title.")
		return returnFalse(form.title);
	}
  	if(id==0) form.action="db_categories.php?a=i";
	else form.action="db_categories.php?a=u&id="+id;
 	form.submit();
}
