var email = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z])+$/;
var numr= /^([0-9]{3})/;
var nam =/^([a-zA-Z])/;
function ltrim(string)
  {
    string=new String(string);
    var string1=new Array();
    var i,j;
    for(i=0,j=0;i<string.length;i++)
    {
      if(j==0)
      {
        if(string.charAt(i)!=" ")
        {
            string1[j++]=string.charAt(i);
        }
      }
      else
      {
        string1[j++]=string.charAt(i);
      }
        
    }
    string="";
    for(i=0;i<string1.length;i++)
    {
      string+=string1[i];
    } 
    return string;
  }

function rtrim(string)
  {
    string=new String(string);
    var string1=new Array();http://localhost/ashcroft/ashcroft/admin/add_project.php
    var i,j;
    for(i=string.length;i>=0;i--)
    {
      if(string.charAt(i-1)==" ")
      {
        continue;
      }
      else
      {
        for(j=0;j<i;j++)
        {
          string1[j]=string.charAt(j);
        }
        break;
      }
        
    }
    string="";
    for(i=0;i<string1.length;i++)
    {
      string+=string1[i];
    }
    
    
    return string;
  }
 function trim(string)
  {
    string=ltrim(string); // // This function is used to trim the left side of a String
    string=rtrim(string);// This function is used to trim the right side of a String
    return string;
  }
////////////////////////////////////////////////////////////////////////////////////////////////////////////
function validatelogin()
{
    if(trim(document.admin_login.uname.value) == ""){ 
	
        alert("Please enter username."); 
        document.admin_login.uname.focus();         
    } 
    else if(trim(document.admin_login.pass.value) == ""){ 
        alert("Please enter password."); 
        document.admin_login.pass.focus();         
    }
	else
	{
		document.admin_login.submit();
	}
}

function validateprofile()
{
    if(trim(document.frm_updateprofile.new_username.value) == ""){ 
        alert("Please enter username."); 
        document.frm_updateprofile.new_username.focus();         
    } 
    else if(trim(document.frm_updateprofile.email.value) == ""){ 
        alert("Please enter an email id."); 
        document.frm_updateprofile.email.focus();         
    }
	else if(!email.test(trim(document.frm_updateprofile.email.value)) != ""){ 
        alert("Please enter a valid email id."); 
        document.frm_updateprofile.email.focus();         
    }
	else
	{
		document.frm_updateprofile.submit();
	}
}

function validatepassword()
{
    if(trim(document.frm_updatepassword.password.value) == ""){ 
        alert("Please enter old password/current password."); 
        document.frm_updatepassword.password.focus();         
    } 
    else if(trim(document.frm_updatepassword.new_password.value) == ""){ 
        alert("Please enter new  password."); 
        document.new_password.email.focus();         
    }
	else if(trim(document.frm_updatepassword.c_new_password.value) == ""){ 
        alert("Please confirm new password."); 
        document.frm_updatepassword.c_new_password.focus();  		
    }
	else if(trim(document.frm_updatepassword.c_new_password.value) != trim(document.frm_updatepassword.new_password.value)){
		alert("password didnt match."); 
        document.frm_updatepassword.c_new_password.focus(); 
	}
	else
	{
		document.frm_updatepassword.submit();
	}
}

function validatecatagory()
{
    if(trim(document.frm_addcatagory.cat_name.value) == ""){ 
        alert("Please enter category name."); 
        document.frm_addcatagory.cat_name.focus();         
    } 
    else if(trim(document.frm_addcatagory.cat_description.value) == ""){ 
        alert("Please enter category description."); 
        document.frm_addcatagory.cat_description.focus();         
    }
    	else
	{
		document.frm_addcatagory.submit();
	}
}

function validateclient()
{
    if(trim(document.frm_addclient.client_name.value) == ""){ 
        alert("Please enter client name."); 
        document.frm_addclient.client_name.focus();         
    } 
    else if(trim(document.frm_addclient.client_description.value) == ""){ 
        alert("Please enter client description."); 
        document.frm_addclient.client_description.focus();         
    }
    	else
	{
		document.frm_addclient.submit();
	}
}

//////function to confirm deleteing catagory

function deletecatagory(cat_id)
{
var question = confirm ("Are you sure you want to delete this category ?")
if (question)
{
window.location.href='deletesetting.php?catagory_id='+cat_id+'&type=catagory';
}
else
{
document.location.href='settings.php';
}
}

////function to confirm deleting client

function deleteclient(cli_id)
{
var questionc = confirm ("Are you sure you want to delete this client ?")
if (questionc)
{
window.location.href='deletesetting.php?client_id='+cli_id+'&type=client';
}
else
{
document.location.href='settings.php';
}
}

////function to confirm deleting client

function deleteproject(pjt_id)
{
var question = confirm ("Are you sure you want to delete this project ?")
if (question)
{
window.location.href='deletesetting.php?project_id='+pjt_id+'&type=project';
}
else
{
window.location.href='gallery_manager.php';
}
}

////function to validate flash


function validateflash()
{

   if(trim(document.frm_flash.uploadedfile.value) == ""){ 
        alert("Please enter a flash file."); 
        document.frm_flash.uploadedfile.focus();         
     } 
   else
      {
		document.frm_flash.submit();
      }
}

function validateproject()
{
if(trim(document.frm_addproject.project_name.value) == ""){ 
        alert("Please enter a project name."); 
        document.frm_addproject.project_name.focus();         
        }  
        else if(trim(document.frm_addproject.project_description.value) == ""){ 
        alert("Please enter project description."); 
        document.frm_addproject.project_description.focus();         
        }
        else if(trim(document.frm_addproject.uploadthumb.value) == ""){ 
        alert("Please upload a thumbnail for project."); 
        document.frm_addproject.uploadthumb.focus();         
        } 
    	else{
document.frm_addproject.submit();
}
}
function validateupdateproject()
{
        if(trim(document.frm_editproject.project_name.value) == ""){ 
        alert("Please enter a  project name."); 
        document.frm_editproject.project_name.focus();         
        }  
        else if(trim(document.frm_editproject.project_description.value) == ""){ 
        alert("Please enter project description."); 
        document.frm_editproject.project_description.focus();           
        } 
    	else
        {
document.frm_editproject.submit();
}

}
///function to validate the content in content manager 

function contentvalidate()
 {
   if(trim(document.frm_contentmanager.ascontent.value) == ""){ 
        alert("Please enter some content ."); 
        document.frm_contentmanager.ascontent.focus();         
     } 
 else{ 
        document.frm_contentmanager.action="editcontent.php";
        document.frm_contentmanager.submit();}
     }

//////function to select the page for content edting

function contentselect()
 {        
        document.frm_contentmanager.action="content_manager.php";
        document.frm_contentmanager.submit();
}

function selectproject()
{
    if(trim(document.frm_galleryselect.catagory.value) == "select"){ 
        alert("Please enter category name."); 
        document.frm_galleryselect.catagory.focus();         
         } 
        else if(trim(document.frm_galleryselect.client.value) == "select"){ 
        alert("Please select client name."); 
        document.frm_galleryselect.client.focus();         
        } 
    	else
	{
		document.frm_galleryselect.submit();
	}
}
function updateorder()
{
document.frm_order.submit();
}


function validatecontact()
{
   if(!nam.test(trim(document.frm_mail.firstname.value)) != "")
    {
      alert("Please enter first name.");
      document.frm_mail.firstname.focus();
    }
       else if(!nam.test(trim(document.frm_mail.lastname.value)) != "")
    {
      alert("Please enter last name.");
      document.frm_mail.lastname.focus();
    }
      else if(!email.test(trim(document.frm_mail.email.value)) != ""){ 
        alert("Please enter a valid email id."); 
        document.frm_mail.email.focus();         
    }
       else if(!numr.test(trim(document.frm_mail.phone.value)) != "")
    {
      alert("Please enter the phone number.");
      document.frm_mail.phone.focus();
    }
     else if(trim(document.frm_mail.mailmessage.value) == "")
    {
      alert("Please enter the message.");
      document.frm_mail.mailmessage.focus();
    }
    else
	{
	document.frm_mail.submit();
	}
}

/*function to show image from thumbnail */

function imagedisplay(imgpath)
{
document.getElementById('imga1').style.background= "url(" + imgpath + ") no-repeat center"; 
}

/*function to validate design essential title */

function design_essential_update()
{
      alert(FCKeditorAPI.__Instances['asessental'].GetHTML());
	  if(!nam.test(trim(document.frm_design_ess_title_update.page_title.value)) != "")
    {
      alert("Please enter a page title.");
      document.frm_design_ess_title_update.page_title.focus();
    }
	//  else if(trim(FCKeditorAPI.__Instances['asessental'].GetHTML())=="")
  //  {
  //                     alert("Please enter intro text.");
                     //  return false;        
  //  }
	else
	{
	//document.frm_design_ess_title_update.action="designactiontest.php?msg=1";
	//alert('test');
	document.frm_design_ess_title_update.action="designaction.php?msg=1";
	document.frm_design_ess_title_update.submit();
	}	
}


/*function to testimonials title */

function testimonials_update()
{
    //  alert(FCKeditorAPI.__Instances['asessental'].GetHTML());
	  if(!nam.test(trim(document.frm_testimonials_update.page_title.value)) != "")
    {
      alert("Please enter a page title1.");
      document.frm_testimonials_update.page_title.focus();
    }
/*	  else if(trim(FCKeditorAPI.__Instances['asessental'].GetHTML())=="")
    {
                       alert("Please enter intro text.");
                       return false;        
    }
	else if((trim(document.frm_testimonials_update.asessental.value)) != "")
    {
      alert("Please enter some description.");
      document.frm_testimonials_update.asessental.focus();
    }*/
	else
	{
	//document.frm_testimonials_update.action="designactiontest.php?msg=1";
	//alert('test');
	document.frm_testimonials_update.action="testimonialsaction.php?msg=1";
	document.frm_testimonials_update.submit();
	}	
}

/* functio to validate article management section */

function validatearticlemanager()
{
	if(!nam.test(trim(document.frm_manage_design_essentials.article_title.value)) != "")
    {
      alert("Please enter a page title.");
      document.frm_manage_design_essentials.article_title.focus();
    }
/*       else if(trim(document.frm_manage_design_essentials.asessential_intro.value) == "")
    {
      alert("Please enter some intro text.");
      document.frm_manage_design_essentials.asessential_intro.focus();
    }
	   else if(trim(document.frm_manage_design_essentials.asessential_content.value) == "")
    {
      alert("Please enter some article text.");
      document.frm_manage_design_essentials.asessential_content.focus();
    }*/
	else if(trim(document.frm_manage_design_essentials.article_thumb.value) == "" ||  trim(document.frm_manage_design_essentials.article_image.value) == "")
	{
      alert("Please upload an image and its thumbnail.");
      document.frm_manage_design_essentials.article_thumb.focus();		
	}
	else if(trim(FCKeditorAPI.__Instances['asessential_intro'].GetHTML())=="")
                {
                       alert("Please enter intro text.");
                       return false;        
                }
	else if(trim(FCKeditorAPI.__Instances['asessential_content'].GetHTML())=="")
                {
                       alert("Please enter some content.");
                       return false;        
                }
		else
		{
		   // document.frm_manage_design_essentials.action="designaction.php?msg=3";
			document.frm_manage_design_essentials.submit();			
		}
//document.frm_manage_design_essentials.submit();

}

function validatearticlemanager1()
{
	if(!nam.test(trim(document.frm_manage_design_essentials.article_title.value)) != "")
    {
      alert("Please enter a page title.");
      document.frm_manage_design_essentials.article_title.focus();
    }
/*       else if(trim(document.frm_manage_design_essentials.asessential_intro.value) == "")
    {
      alert("Please enter some intro text.");
      document.frm_manage_design_essentials.asessential_intro.focus();
    }
	   else if(trim(document.frm_manage_design_essentials.asessential_content.value) == "")
    {
      alert("Please enter some article text.");
      document.frm_manage_design_essentials.asessential_content.focus();
    }*/
	else if(trim(FCKeditorAPI.__Instances['asessential_intro'].GetHTML())=="")
                {
                       alert("Please enter intro text.");
                       return false;        
                }
	else if(trim(FCKeditorAPI.__Instances['asessential_content'].GetHTML())=="")
                {
                       alert("Please enter some content.");
                       return false;        
                }
		else
		{
		   // document.frm_manage_design_essentials.action="designaction.php?msg=3";
			document.frm_manage_design_essentials.submit();			
		}
//document.frm_manage_design_essentials.submit();

}
/* function to update article order */

function updatearticleorder(n)
{
/*	var i;
	alert(n);
	for(i=0;i<n;i++)
		{
			if(isNaN(trim(document.frm_de_order.order+i.value)))
   			 {
				 alert(document.frm_de_order.order+i.value);
     			 alert("Please enter a number.");
      			 document.frm_de_order.order+i.focus();
    		 }
			else
			{
				 document.frm_de_order+i.submit();
			}
		}*/
		 document.frm_de_order.submit();
}

/* functio to validate article management section on testimonials*/

function validate_testimonial_articlemanager()
{
	if(!nam.test(trim(document.frm_manage_testimonials.article_title.value)) != "")
    {
      alert("Please enter a page title.");
      document.frm_manage_testimonials.article_title.focus();
    }
	else if(trim(document.frm_manage_testimonials.article_thumb.value) == "" ||  trim(document.frm_manage_testimonials.article_image.value) == "")
	{
      alert("Please upload an image and its thumbnail.");
      document.frm_manage_testimonials.article_thumb.focus();		
	}
	else if(trim(FCKeditorAPI.__Instances['asessential_intro'].GetHTML())=="")
                {
                       alert("Please enter intro text.");
                       return false;        
                }
	else if(trim(FCKeditorAPI.__Instances['asessential_content'].GetHTML())=="")
                {
                       alert("Please enter some content.");
                       return false;        
                }
		else
		{
		   // document.frm_manage_design_essentials.action="designaction.php?msg=3";
			document.frm_manage_testimonials.submit();			
		}
//document.frm_manage_design_essentials.submit();

}

function validate_testimonial_articlemanager1()
{
	if(!nam.test(trim(document.frm_manage_testimonials.article_title.value)) != "")
    {
      alert("Please enter a page title.");
      document.frm_manage_testimonials.article_title.focus();
    }
	else if(trim(FCKeditorAPI.__Instances['asessential_intro'].GetHTML())=="")
                {
                       alert("Please enter intro text.");
                       return false;        
                }
	else if(trim(FCKeditorAPI.__Instances['asessential_content'].GetHTML())=="")
                {
                       alert("Please enter some content.");
                       return false;        
                }
		else
		{
			document.frm_manage_testimonials.submit();			
		}
}

/* function to update article order on testimonials*/

function update_testimonial_articleorder(n)
{
/*	var i;
	alert(n);
	for(i=0;i<n;i++)
		{
			if(isNaN(trim(document.frm_de_order.order+i.value)))
   			 {
				 alert(document.frm_de_order.order+i.value);
     			 alert("Please enter a number.");
      			 document.frm_de_order.order+i.focus();
    		 }
			else
			{
				 document.frm_de_order+i.submit();
			}
		}*/
		 document.frm_de_order.submit();
}

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 E-mail ID")
		   return false
		}

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

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

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

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

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid E-mail ID")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

 		 return true					
	}

/*function ValidateForm(){
	var emailID=document.frmSample.txtEmail
	
	if ((emailID.value==null)||(emailID.value=="")){
		alert("Please Enter your Email ID")
		emailID.focus()
		return false
	}
	if (echeck(emailID.value)==false){
		emailID.value=""
		emailID.focus()
		return false
	}
	return true
 }*/
///////////////////////////////////////////////////////////////////






////////////////////////////////////////////////////////////////////////////

