// function to check alpha numaric values with space
function alphanumeric(alphane)
{
	var numaric = alphane;
	for(var j=0; j<numaric.length; j++)
		{
		  var alphaa = numaric.charAt(j);
		  var hh = alphaa.charCodeAt(0);
		  if((hh > 47 && hh<59) || (hh > 64 && hh<91) || (hh > 96 && hh<123)||(hh==32))
		  {
		  }
		else	{
			 return false;
		  }
		}
 return true;
}


//function to check special character
function special_char(input_value){
    var iChars = "!#%^&*()+=-[]\\\';,/{}|\":<>?$";
    var ster12=input_value.length;
    for (var i = 0; i < ster12;  i++) {
      	if (iChars.indexOf(input_value.charAt(i)) != -1) {
//      	alert ("Special characters are not allowed.\n Please remove them and try again.");
     return false;
  	}
  }

}
//function to check numaric value

function IsNumeric(strString)
   //  check for valid numeric strings	
   {
       var strValidChars = "0123456789";
       var strChar;
       var blnResult = true;
    
       if (strString.length == 0) return false;
    
       //  test strString consists of valid characters listed above
       for (i = 0; i < strString.length && blnResult == true; i++)
          {
          strChar = strString.charAt(i);
          if (strValidChars.indexOf(strChar) == -1)
             {
             blnResult = false;
             }
          }
       return blnResult;
   }



// function to trim the values

function trim(input_val)
{
	while(''+input_val.charAt(input_val.length-1)==' ')
	{
		input_val = input_val.substring(0,input_val.length-1);
	}
	return input_val;
 }


 // email validation check

 function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("Invalid email address")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid email address")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		   alert("Invalid email address")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		   alert("Invalid email address")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		   alert("Invalid email address")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		   alert("Invalid email address")
		    return false
		 }

		 if (str.indexOf(" ")!=-1){
		   alert("Invalid email address")
		    return false
		 }

 		 return true
	}
	
	//function url validation
	function checkURL(value) {

	   var urlregex = new RegExp("^(www.){1}([0-9A-Za-z]+\.)");
        if(urlregex.test(value))
        {
            return(true);
        }
            return(false); 
    }

	
	
	
//admin login form validation check

function login_validation(){

    var fa= document.Login_frm;

    if(fa.user.value==""){
        alert("Please enter user name");
        fa.user.focus();
        return false;
    }

    if(fa.password.value==""){
        alert("Please enter password");
        fa.password.focus();
        return false;

    }
    return true;

}

//admin change password validation

function validate_change_pass(){
     var fa= document.change_pw;
    if(fa.old_pass.value==""){
        alert("Please enter old password");
        fa.old_pass.focus();
        return false;
    }
    if(fa.new_pass.value==""){
        alert("Please enter new password");
        fa.new_pass.focus();
        return false;
    }
    if(fa.con_pass.value==""){
        alert("Please confirm password");
        fa.con_pass.focus();
        return false;
    }
    if(fa.con_pass.value!=fa.new_pass.value){
        alert("Both password must match");
        fa.con_pass.focus();
        return false;
    }
    return true;

}


function Validate_Numeric(Ctrl,valid_chars,msg)
{
	if(chkNumeric(Ctrl.value,valid_chars) == false)
	{
		alert(msg);
		Ctrl.focus();
		return false;
	}
	return true;
}

function chkNumeric(strString,strValidChars)
{
   var strChar;
   var blnResult = true;

   for (i = 0; i < strString.length && blnResult == true; i++)
   {
	  strChar = strString.charAt(i);
      if (strValidChars.indexOf(strChar) == -1)
      {
    	   blnResult = false;
      }
   }
   return blnResult;
}


function addMemberValidation(){

    var fa=document.frmAddMember;
    if(trim(fa.txtmemberid.value)==""){
        
        alert("Please enter member id ");
        fa.txtmemberid.focus();
        return false;
        
    }
    if(special_char(fa.txtmemberid.value)==false){
        alert("Special characters are not allowed");
        fa.txtmemberid.focus();
        return false;
    }
    if(trim(fa.password.value)==""){
        
        alert("Please enter password");
        fa.password.focus();
        return false;
        
    }
    if(trim(fa.cpassword.value)==""){
        
        alert("Please confirm password");
        fa.cpassword.focus();
        return false;
        
    }
    if(fa.cpassword.value!=fa.password.value){
    
        alert("Both password must match");
        fa.cpassword.focus();
        return false;
    
    }
    if(trim(fa.txtmembername.value)==""){
        
        alert("Please enter name");
        fa.txtmembername.focus();
        return false;
        
    }
    if(trim(fa.txtemail.value)==""){
        
        alert("Please enter email address");
        fa.txtemail.focus();
        return false;
        
    }
    if(!echeck(fa.txtemail.value)){

        fa.txtemail.focus();
        return false;
    }
    if(trim(fa.level.value)==""){
        
        alert("Please select level");
        fa.level.focus();
        return false;
        
    }

    return true;
}

function addPageValidation(){

    var fa=document.frmAddPage;
    
    if(trim(fa.txtTitle.value)==""){
        
        alert("Please enter page title");
        fa.txtTitle.focus();
        return false;
        
    }
    if(trim(fa.txtKey.value)==""){
        
        alert("Please enter meta keywords");
        fa.txtKey.focus();
        return false;
        
    }
    if(trim(fa.txtDescription.value)==""){
        
        alert("Please enter meta description");
        fa.txtDescription.focus();
        return false;
        
    }
    return true;
    

}

function addUserValidation(){
    
    var fa=document.frmAddUser;
    if(trim(fa.txtUserName.value)==""){
        
        alert("Please enter user name");
        fa.txtUserName.focus();
        return false;
        
    }
    
    if(trim(fa.password.value)==""){
        
        alert("Please enter password");
        fa.password.focus();
        return false;
        
    }
    if(trim(fa.cpassword.value)==""){
        
        alert("Please confirm password");
        fa.cpassword.focus();
        return false;
        
    }
    if(fa.cpassword.value!=fa.password.value){
    
        alert("Both password must match");
        fa.cpassword.focus();
        return false;
    
    }
   if(trim(fa.txtTitle.value)==""){
        
        alert("Please enter title");
        fa.txtTitle.focus();
        return false;
    }
  if(trim(fa.txtFirstName.value)==""){
        
        alert("Please enter first name");
        fa.txtFirstName.focus();
        return false;
    }

      if(trim(fa.txtLastName.value)==""){
        
        alert("Please enter last name");
        fa.txtLastName.focus();
        return false;
    }

   if(trim(fa.txtCompany.value)==""){
        
        alert("Please enter company");
        fa.txtCompany.focus();
        return false;
    }

   if(trim(fa.txtDesignation.value)==""){
        
        alert("Please enter designation");
        fa.txtDesignation.focus();
        return false;
    }

   if(trim(fa.txtAddress.value)==""){
        
        alert("Please enter address");
        fa.txtAddress.focus();
        return false;
    }

   if(trim(fa.txtCountry.value)==""){
        
        alert("Please select country");
        fa.txtCountry.focus();
       return false;
    }

   if(trim(fa.txtEmail.value)==""){
        
        alert("Please enter email address");
        fa.txtEmail.focus();
        return false;
    }
     if(!echeck(fa.txtEmail.value)){

        fa.txtEmail.focus();
        return false;
    }
    if(fa.txtAlterEmail.value!=""){

        if(!echeck(fa.txtAlterEmail.value)){
            
            fa.txtAlterEmail.focus();
            return false;
            }
        
    }
    if(trim(fa.txtHomePhone.value)==""){
        
        alert("Please enter home phone");
        fa.txtHomePhone.focus();
        return false;
    }

    return true;
}

function addBusinessValidation(){
    
    var fa=document.frmAddBussiness;
    if(trim(fa.txtBusinessName.value)==""){
        
        alert("Please enter business name");
        fa.txtBusinessName.focus();
        return false;
    
    }

    if(trim(fa.txtcategoryid.value)==""){
        
        alert("Please select category");
        fa.txtcategoryid.focus();
        return false;
    
    }
    if(trim(fa.txtVillage.value)==""){
        
        alert("Please select village");
        fa.txtVillage.focus();
        return false;
    
    }

    if(fa.txtDescription.value!=""){
        
        var maxlth=5000; 
        
        if ( fa.txtDescription.value.length>maxlth)
        {
            alert("Please enter character less then 5000");
             fa.txtDescription.focus();
            return false;
        }

        
    }
    
        if(fa.txtRoom.value!=""){
        
        var maxlth=5000; 
        
        if ( fa.txtRoom.value.length>maxlth)
        {
            alert("Please enter character less then 5000");
             fa.txtRoom.focus();
            return false;
        }

        
    }
    if(fa.level.value=="enhanced"){
         if(fa.txtMoreInfo.value!=""){
            
            var maxlth=5000; 
            if ( fa.txtMoreInfo.value.length>maxlth)
            {
                alert("Please enter character less then 5000");
                 fa.txtMoreInfo.focus();
                return false;
            }
    
            
        }


    if(fa.txtEmail.value!=""){
        
        if(!echeck(fa.txtEmail.value)){

            fa.txtEmail.focus();
            return false;
        } 
        
    }
    if(fa.txtWeb.value!=""){
        
        if(checkURL(fa.txtWeb.value)==false){
            
            alert("Please enter website url like 'www.test.com'");
            fa.txtWeb.focus();
            return false;
        }
    
    }
    
  }
    return true;

}
function validate_category(){
    
    var fa=document.frmAddCategory;
    if(trim(fa.txtcategoryname.value)==""){
        alert("Please enter category name");
        fa.txtcategoryname.focus();
        return false;
    }  



}
function validate_village(){
    
    var fa=document.frmAddVillage;
    if(trim(fa.txtcategoryname.value)==""){
        alert("Please enter village name");
        fa.txtcategoryname.focus();
        return false;
    }  
    if(trim(fa.txtcategorydesc.value)==""){
        alert("Please pick village color");
        fa.txtcategorydesc.focus();
        return false;
    }
	 if(trim(fa.page.value)==""){
        alert("Please select a page");
        fa.txtcategorydesc.focus();
        return false;
    }

}

function validate_icon(){

    var fa =document.frmAddIcon;

    if(trim(fa.icon_name.value)==""){
        alert("Please enter icon name");
        fa.icon_name.focus();
        return false;
    }  
    if(trim(fa.picture_upload.value)==""){
        alert("Please select icon to uploade");
        fa.picture_upload.focus();
        return false;
    }
}

function validate_ads(bEdit){

    var fa =document.frmAddAds;

    if(fa.ads_title.value==""){
        alert("Please enter advertisement title");
        fa.ads_title.focus();
        return false;
    }
     if(fa.ads_link.value=="")
	 {
        alert("Please enter advertisement link");
        fa.ads_link.focus();
        return false;
    }
	if(!bEdit)
    {  
    	if(trim(fa.ads_picture.value)==""){
	        alert("Please upload a file");
	        fa.ads_picture.focus();
	        return false;
	    }
   	}
}
function validate_header_image(bEdit){

    var fa =document.frmAddHeaderImg;

    if(trim(fa.headimg_title.value)==""){
        alert("Please enter header image title");
        fa.headimg_title.focus();
        return false;
    }
    if(!bEdit)
    {  
    	if(trim(fa.headimg_picture.value)==""){
	        alert("Please upload a file");
	        fa.headimg_picture.focus();
	        return false;
	    }
   	}
}


function validate_icon_edit(){

    var fa =document.frmAddIcon;

    if(trim(fa.icon_name.value)==""){
        alert("Please enter icon name");
        fa.icon_name.focus();
        return false;
    }  

}
function addLinkValidation(){

    
    var fa =document.frmAddlink;

    if(trim(fa.txtLinkName.value)==""){
        alert("Please enter link name");
        fa.txtLinkName.focus();
        return false;
    } 
    if(trim(fa.txtLinkURL.value)==""){
        alert("Please enter navigation url");
        fa.txtLinkURL.focus();
        return false;
    } 
    if(trim(fa.txtLinkPosition.value)==""){
        alert("Please enter position");
        fa.txtLinkPosition.focus();
        return false;
    }
    if(IsNumeric(fa.txtLinkPosition.value)==false){
        
        alert("Please enter numaric value");
        fa.txtLinkPosition.focus();
        return false;
    
    }
    return true;
}



function addNewsValidation(){

    var fa= document.frmAddNews;
    
    if(trim(fa.txtNewsTitle.value)=="" ){
        alert("Please enter news title");
        fa.txtNewsTitle.focus();
        return false;
    }
    if(trim(fa.txtShortDescription.value)=="" ){
        alert("Please enter short description");
        fa.txtShortDescription.focus();
        return false;
    }
    if(trim(fa.txtLongDescription.value)=="" ){
        alert("Please enter long description");
        fa.txtLongDescription.focus();
        return false;
    }
    
    return true;

}

function addPDFValidation(){

    var fa= document.frmAddpdf;
    
    if(trim(fa.txtPdftitle.value)=="" ){
        alert("Please enter pdf title");
        fa.txtPdftitle.focus();
        return false;
    }
    if(trim(fa.txtShortDescription.value)=="" ){
        alert("Please enter short description");
        fa.txtShortDescription.focus();
        return false;
    }
	if(fa.pdffile.value=="" ){
        alert("Please upload a file");
      	fa.pdffile.focus();
        return false;
    }
	if(-1 == fa.pdffile.value.indexOf('.pdf'))
	{
        alert("Please upload a pdf file");
      	fa.pdffile.focus();
        return false;	
	}
    return true;

}
function updatePDFValidation(){

    var fa= document.frmUpdpdf;
    
    if(trim(fa.txtPdftitle.value)=="" ){
        alert("Please enter pdf title");
        fa.txtPdftitle.focus();
        return false;
    }
    if(trim(fa.txtShortDescription.value)=="" ){
        alert("Please enter short description");
        fa.txtShortDescription.focus();
        return false;
    }
	if(fa.pdffile.value!='')
	{
		if(-1 == fa.pdffile.value.indexOf('.pdf'))
		{
			alert("Please upload a pdf file");
			fa.pdffile.focus();
			return false;	
		}
	}
    return true;

}
function addFaqValidation(){

    var fa=document.frmAddFaq;
    
    if(trim(fa.txtcategoryid.value)==""){

        alert("Please select category");
        fa.txtcategoryid.focus();
        return false;

    }   

    if(trim(fa.txtsubcategoryid.value)==""){

        alert("Please select sub category");
        fa.txtsubcategoryid.focus();
        return false;

    }   
    
    if(trim(fa.txtQuestion.value)==""){

        alert("Please enter question");
        fa.txtQuestion.focus();
        return false;

    }  
    
    if(trim(fa.txtAnswer.value)==""){

        alert("Please enter answer");
        fa.txtAnswer.focus();
        return false;

    }  

    return true;

}

function validate_contactus()
{

    var fa=document.frmContactus;
    
    if(trim(fa.txtName.value)==""){

        alert(fa.txtName.title);
        fa.txtName.focus();
        return false;

    }   
 
	if(trim(fa.txtBusiness.value)==""){

        alert(fa.txtBusiness.title);
        fa.txtBusiness.focus();
        return false;

    }   
    
    if(trim(fa.txtEmail.value)==""){

        alert(fa.txtEmail.title);
        fa.txtEmail.focus();
        return false;

    }  
    
    if(!echeck(fa.txtEmail.value)){

        fa.txtEmail.focus();
        return false;
    }
    if(trim(fa.txtTel.value)==""){

        alert(fa.txtTel.title);
        fa.txtTel.focus();
        return false;

    }
	 if(trim(fa.txtareaEnquiry.value)==""){

        alert(fa.txtareaEnquiry.title);
        fa.txtareaEnquiry.focus();
        return false;

    }
	
    return true;

}

function ShowHideAllDiv(cls,action)
{
	var objs;
	if (document.all)
	{ 
		objs = document.all.tags("DIV");
	}
	else if (document.getElementsByTagName)
	{ 
		objs = document.getElementsByTagName("DIV");
	}
	else if (document.layers)
	{ 
		objs = document.layers["DIV"];
	}
	for (var i=0; i<objs.length; i++) 
	{
		if (objs[i].className == cls)
		{
			if(action=="hide")
				objs[i].style.display = "none";
			else
				objs[i].style.display = "block";
		}
	}
}
function ValidateFormGB(f,abc)
{
	 var name=trim(f.name.value);if(name==''){alert('Please enter name');f.name.focus();return false}
	 var email=trim(f.email.value);if(email==''){alert('Please enter email');f.email.focus();return false}
	 if(!echeck(f.email.value)){f.email.focus();return false;}
	 var comment=trim(f.comment.value);
	 if(comment==''){alert('Please enter comment');f.comment.focus();return false}
	if(abc!=undefined && trim(f.security_code.value)==""){alert("Please enter security code");f.security_code.focus(); return false;}
	 return true;
}

function validateFeedback(fa)
{

    if(trim(fa.feedback_question.value)=="" ){
        alert("Please enter feedback question.");
        fa.feedback_question.focus();
        return false;
    }
    return true;
}
function openRequestedPopup(url,Wname,w,h,bresizable,scrollbar,statusbar)
{
	WindowObjectReference = window.open(url,
   Wname,
   "width=" + w + ",height=" + h + "," + (bresizable?'resizable':'') + ",scrollbars=" + scrollbar +",status=" + statusbar);
	WindowObjectReference.moveTo(0,0);
}
function feedBackValidation(f)
{
 	var ques=trim(f.feedback_question.value);
 	if(ques==''){alert('Please enter question');f.feedback_question.focus();return false}
	 return true;
}
function validate_feedback(f)
{
    if(trim(f.txtName.value)=="" ){
        alert("Please enter name");
        f.txtName.focus();
        return false;
    }
	if(trim(f.txtBusiness.value)=="" ){
        alert("Please enter business name");
        f.txtBusiness.focus();
        return false;
    }
	if(trim(f.txtEmail.value)=="" ){
        alert("Please enter email address");
        f.txtEmail.focus();
        return false;
    }	
	if(!echeck(f.txtEmail.value)){f.txtEmail.focus();return false;}
	if(trim(f.txtTel.value)=="" ){
        alert(f.txtTel.title);
        f.txtTel.focus();
        return false;
    }
	if(trim(f.txtareaEnquiry.value)=="" ){
        alert(f.txtareaEnquiry.title);
        f.txtareaEnquiry.focus();
        return false;
    }	
    return true;	
}
function validateClassifidesAds(f)
{
    if(trim(f.ads_title.value)=="" ){
        alert("Please enter ad title");
        f.ads_title.focus();
        return false;
    }
	 if(trim(f.ads_description.value)=="" ){
        alert("Please enter short description");
        f.ads_title.focus();
        return false;
    }
}
function validateClassifidesCategory(f)
{
    if(trim(f.category_name.value)=="" ){
        alert("Please enter category name");
        f.category_name.focus();
        return false;
    }
	 if(trim(f.category_desc.value)=="" ){
        alert("Please enter short description");
        f.category_desc.focus();
        return false;
    }
}
 
 //---------------------shepherd 06-07-07----------------
 
function validatebanner()
{
	if(document.frmbanner.page_id.value=="")
	{
	alert("Please select a page");
	return false;
	}
	
	if(document.frmbanner.bname.value=="")
	{
	alert("Please enter banner name.");
	document.frmbanner.bname.focus();
	return false;
	}
	
	if(document.frmbanner.urllink.value=="")
	{
	alert("Please enter link.");
	document.frmbanner.urllink.focus();
	return false;
	}
	
	if(document.frmbanner.pos.value=="")
	{
	alert("Please select page position.");
	return false;
	}
	
	return true;
}
function validateFrmbanner()
{
if(document.frmbanner.page_name.value=="")
	{
	alert("Please select a page");
	document.frmbanner.page_name.focus();
	return false;
	}
	
	if(document.frmbanner.uploadbanner.value=="")
	{
	alert("Please upload a file");
	document.frmbanner.uploadbanner.focus();
	return false;
	}
	if(document.frmbanner.urllink.value=="")
	{
	alert("Please enter link.");
	document.frmbanner.urllink.focus();
	return false;
	}
	if(document.frmbanner.bname.value=="")
	{
	alert("Please enter banner name.");
	document.frmbanner.bname.focus();
	return false;
	}
	if(document.frmbanner.pos.value=="")
	{
	alert("Please select page position.");
	document.frmbanner.pos.focus();
	return false;
	}
	return true;
}
function actiontakenByuser(banid)
{
var popupurl="http://localhost/cms/bannerhitreport.php?bannerid="+banid;
winpops=window.open(popupurl,"","width=450, height=200, scrollbars=yes, resizable=no");
}

function openImage(wi,hi,imgid)
{

var tep="width="+wi+", height="+hi+", scrollbars=no, resizable=no";

var popupurl="http://www.cairngormparki.com/bigimageshow.php?bannerid="+imgid;
winpops=window.open(popupurl,"",tep);
}
function cssProperty()
{

var cssclassid=document.cssmng.classname.value;
window.location="index.php?classid="+cssclassid;
}
function cssRecord()

{
var cssfile=document.cssmng.filename.value;

window.location="index.php?filename="+cssfile;
}
function opencssFile()
{
if(document.frmfiletype.ft.value=="admin")
window.location="../admincss/";
}

function opencssuserFile()
{
if(document.frmfiletype1.ft1.value=="usersite")
window.location="../css_mng/";
}