//Login Validation
function loginFrmValid(){
	if (IsEmpty(document.getElementById("txtUsername"))) {
		alert("Please enter username");
		document.getElementById("txtUsername").focus();
		return false;
	}
	if (IsEmpty(document.getElementById("txtPassword"))) {
		alert("Please enter password");
		document.getElementById("txtPassword").focus();
		return false;		
	}
}
//Update Display Status Validation
function updateDisplay(act,name,frmName){
	frmName[name].value = act;
	if(confirm("Do you want to update display status?")){
		frmName.action = "functions.php";
		frmName.submit();
		return false;
	}
	else {
		return false;
	}
	return false;
}
//Update Order
function updateOrd(act,name,frmName){
	frmName[name].value = act;
	if(confirm("Do you want to update display order?")){
		frmName.action = "functions.php";
		frmName.submit();
		return false;
	}
	else {
		return false;
	}
	return false;
}
function check(name,frmName) {
	if(!isNaN(frmName[name].length))	{	
		for( i=0;i<frmName[name].length;i++ ) {
			if(frmName[name][i].checked == true) {
				return true;
			}
		}
	return false;
	}
	else if( frmName[name].checked == false ) {
		return false;
	}
	else if( frmName[name].checked == true ) {
		return true;
	}
	return false;
}

function confrm(str,msg,name,frmName,act,dName)
{
	if(check(name,frmName)) {
		if(confirm(str))
		{
			frmName[dName].value = act;
			frmName.action = "functions.php";
			frmName.submit();
		}
		else
		{	
			return false;
		}
	}
	else{alert(msg);return false;}
}
//Update News Validation
function Neditvalid(){
	if(IsEmpty(document.frmAddNews.txtName)){
		alert("Please enter a title");
		document.frmAddNews.txtName.focus();
		return false;
	}
	if(IsEmpty(document.frmAddNews.txtDate)){
		alert("Please select date");
		document.frmAddNews.txtDate.focus();
		return false;
	}
	var editorcontent = CKEDITOR.instances["txtContent"].getData().replace(/<[^>]*>/gi, '');
	if (!editorcontent.length){
      alert("Please enter a description");
      return false;
      }
}
//Add news validation
function Naddvalid(){
	if(IsEmpty(document.frmAddNews.txtName)){
		alert("Please enter a title");
		document.frmAddNews.txtName.focus();
		return false;
	}
	if(IsEmpty(document.frmAddNews.txtDate)){
		alert("Please select date");
		document.frmAddNews.txtDate.focus();
		return false;
	}
	var editorcontent = CKEDITOR.instances["txtContent"].getData().replace(/<[^>]*>/gi, '');
	if (!editorcontent.length){
      alert("Please enter a description");
      return false;
      }
}
//Add content validation
function Ceditvalid() {
	var editorcontent = CKEDITOR.instances["txtContent"].getData().replace(/<[^>]*>/gi, '');
	if (!editorcontent.length){
    	alert("Please enter content");
    	return false;
      }
}
//Add staff validation
function Saddvalid() {
	if(IsEmpty(document.frmAddStaff.txtName)){
		alert("Please enter a Name");
		document.frmAddStaff.txtName.focus();
		return false;
	}
	var editorcontent = CKEDITOR.instances["txtContent"].getData().replace(/<[^>]*>/gi, '');
	if (!editorcontent.length){
    	alert("Please enter content");
    	return false;
   }
	if(IsEmpty(document.frmAddStaff.fileImage)){
		alert("Please attach a photo for staff");
		document.frmAddStaff.fileImage.focus();
		return false;
	}
		if(!IsEmpty(document.frmAddStaff.fileImage)){
		path=document.frmAddStaff.fileImage;
		if(checkext(path,".jpg")==false && checkext(path,".JPG")==false && checkext(path,".gif") == false && checkext(path,"jpeg")==false && checkext(path,"JPEG")==false  && checkext(path,".GIF")==false && checkext(path,".png")==false && checkext(path,".PNG")==false && checkext(path,".bmp")==false && checkext(path,".BMP")==false ){
			alert("Please select a photo with valid extension");
			document.frmAddStaff.fileImage.focus();
			return false;
		}
	}
}
function Seditvalid() {
	if(IsEmpty(document.frmAddStaff.txtName)){
		alert("Please enter a Name");
		document.frmAddStaff.txtName.focus();
		return false;
	}
	var editorcontent = CKEDITOR.instances["txtContent"].getData().replace(/<[^>]*>/gi, '');
	if (!editorcontent.length){
    	alert("Please enter content");
    	return false;
   }
	if(!IsEmpty(document.frmAddStaff.fileImage)){
		path=document.frmAddStaff.fileImage;
		if(checkext(path,".jpg")==false && checkext(path,".JPG")==false && checkext(path,".gif") == false && checkext(path,"jpeg")==false && checkext(path,"JPEG")==false  && checkext(path,".GIF")==false && checkext(path,".png")==false && checkext(path,".PNG")==false && checkext(path,".bmp")==false && checkext(path,".BMP")==false ){
			alert("Please select a photo with valid extension");
			document.frmAddStaff.fileImage.focus();
			return false;
		}
	}
}
function NLaddvalid() {
	if(IsEmpty(document.frmAddNewsletter.txtTitle)){
		alert("Please enter a title");
		document.frmAddNewsletter.txtTitle.focus();
		return false;
	}
	if(IsEmpty(document.frmAddNewsletter.txtPos)){
		alert("Please enter a position");
		document.frmAddNewsletter.txtPos.focus();
		return false;
	}
	if(IsEmpty(document.frmAddNewsletter.fileNews)){
		alert("Please attach a newsletter file");
		document.frmAddNewsletter.fileNews.focus();
		return false;
	} 
	if(!IsEmpty(document.frmAddNewsletter.fileNews)){
		path=document.frmAddNewsletter.fileNews;
		if(checkext(path,".pdf")==false && checkext(path,".doc")==false && checkext(path,".docx") == false){
			alert("Please attach a file with valid extension");
			document.frmAddNewsletter.fileNews.focus();
			return false;
		}
	}
}
function NLeditvalid() {
	if(IsEmpty(document.frmAddNewsletter.txtTitle)){
		alert("Please enter a title");
		document.frmAddNewsletter.txtTitle.focus();
		return false;
	}
	if(IsEmpty(document.frmAddNewsletter.txtPos)){
		alert("Please enter a position");
		document.frmAddNewsletter.txtPos.focus();
		return false;
	}
	if(!IsEmpty(document.frmAddNewsletter.fileNews)){
		path=document.frmAddNewsletter.fileNews;
		if(checkext(path,".pdf")==false && checkext(path,".doc")==false && checkext(path,".docx") == false){
			alert("Please attach a file with valid extension");
			document.frmAddNewsletter.fileNews.focus();
			return false;
		}
	}
}
function FLaddvalid() {
	if(IsEmpty(document.frmAddFiles.txtTitle)){
		alert("Please enter a title");
		document.frmAddFiles.txtTitle.focus();
		return false;
	}
	if(IsEmpty(document.frmAddFiles.fileFile)){
		alert("Please attach a newsletter file");
		document.frmAddFiles.fileFile.focus();
		return false;
	} 
	if(!IsEmpty(document.frmAddFiles.fileFile)){
		path=document.frmAddFiles.fileFile;
		if(checkext(path,".pdf")==false && checkext(path,".doc")==false && checkext(path,".docx") == false){
			alert("Please attach a file with valid extension");
			document.frmAddFiles.fileFile.focus();
			return false;
		}
	}
}
function FLeditvalid() {
	if(IsEmpty(document.frmAddFiles.txtTitle)){
		alert("Please enter a title");
		document.frmAddFiles.txtTitle.focus();
		return false;
	}
	if(!IsEmpty(document.frmAddFiles.fileFile)){
		path=document.frmAddFiles.fileFile;
		if(checkext(path,".pdf")==false && checkext(path,".doc")==false && checkext(path,".docx") == false){
			alert("Please attach a file with valid extension");
			document.frmAddFiles.fileFile.focus();
			return false;
		}
	}
}
function Subscribevalid(frm) {
	name = document.getElementById("cm-name");
	email = document.getElementById("cm-oiduuj-oiduuj");
	if(IsEmpty(name)){
		alert("Please enter a name");
		name.focus();
		return false;
	} else if(IsEmpty(email)){
		alert("Please enter an email address");
		email.focus();
		return false;
	} else if(!hcheck(name.value, "Please enter a valid name")) {
		name.focus();
		name.value = "";
		return false;
	} else if(!echeck(email.value) || !hcheck(email.value, "Please enter a valid email address")) {
		email.focus();
		email.value = "";
		return false;
	} else {
		return true;
	}
}

function LOaddvalid() {
	var title = document.getElementbyID("txtTitle");
	var url = document.getElementbyID("txtUrl");
	var pos = document.getElementbyID("txtPos");
	if(IsEmpty(title)){
		alert("Please enter a title");
		title.focus();
		return false;
	} else if((url.value != "")){
		alert("Please enter a valid url");
		url.focus;
		return false;
	} else if(IsEmpty(pos)){
		alert("Please enter a weight");
		pos.focus();
		return false;
	} else {
		return true;
	}
}

function LOeditvalid() {

	var url_title = document.getElementById("txtTitle");
	var logo_url = document.getElementById("txtUrl");
	var pos = document.getElementById("txtPos");

	
	if(IsEmpty(url_title)){
		alert("Please enter a title");
		url_title.focus();
		return false;
	} else if( (logo_url.value == "")){
		alert("Please enter a valid url");
		logo_url.focus;
		return false;
	} else if(IsEmpty(pos)){
		alert("Please enter a weight");
		pos.focus();
		return false;
	} else {
		return true;
	}
}

function FSaddvalid() {
	var title = document.getElementById("txtTitle");
	var pos = document.getElementById("txtPos");
	if(IsEmpty(title)){
		alert("Please enter a title");
		title.focus();
		return false;
	} else if(IsEmpty(pos)){
		alert("Please enter a weight");
		pos.focus();
		return false;
	} else {
		return true;
	}	
}

function FSeditvalid() {
	var title = document.getElementById("txtTitle");
	var pos = document.getElementById("txtPos");
	if(IsEmpty(title)){
		alert("Please enter a title");
		title.focus();
		return false;
	} else if(IsEmpty(pos)){
		alert("Please enter a weight");
		pos.focus();
		return false;
	} else {
		return true;
	}	
}

