function validate_required(field,alerttxt)
{
    with (field)
    {
      if (value==null||value=="")
      {
        alert(alerttxt);
        return false;
      }
      else 
      {
        return true
      }
    }
}

function validate_contactform(thisform)
{
  
  with (thisform)
  {
    var usernameBits = email.value.split("@"); 
    
    var str= email.value;
    
    var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
    
    
    
    
    if (validate_required(name,"Please Enter Your First Name")==false)
    {
      name.style.background = '#CC9999'; 
      name.focus();
      return false;
    }
    else
    {
      name.style.background = 'white'; 
    }
    
    if (validate_required(email,"Please Enter Your email address")==false)
    {
      email.style.background = '#CC9999'; 
      email.focus();
      return false;
    }
    else if (str.indexOf(at)==-1)
    {
      alert("Invalid E-mail Address No @ Detected");
      email.style.background = '#CC9999'; 
      email.focus();
      return false
		}

		else if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr)
    {
      alert("Invalid E-mail Address");
      email.style.background = '#CC9999'; 
      email.focus();
      return false
		}

		else if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr)
    {
      alert("Invalid E-mail Address");
      email.style.background = '#CC9999'; 
      email.focus();
      return false
		}

		else if (str.indexOf(at,(lat+1))!=-1)
    {
      alert("Invalid E-mail Address");
      email.style.background = '#CC9999'; 
      email.focus();
      return false
		 }

		else if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot)
    {
      alert("Invalid E-mail Address");
      email.style.background = '#CC9999'; 
      email.focus();
      return false
		 }

		else if (str.indexOf(dot,(lat+2))==-1){
      alert("Invalid E-mail Address");
      email.style.background = '#CC9999'; 
      email.focus();
      return false
		 }
		
		 else if (str.indexOf(" ")!=-1){
		    alert("Invalid E-mail Address");
		          email.style.background = '#CC9999'; 
      email.focus();
		    return false
		 }
		 else {
		 
      enquiry.style.background = 'white'; 
     
     }
		  



    
    if (validate_required(enquiry,"Please Enter Your Enquiry")==false)
    {
      enquiry.style.background = '#CC9999'; 
      enquiry.focus();
      return false;
    }
    else
    {
      enquiry.style.background = 'white'; 
    }         
  }
}


function validate_feedbackform(thisform)
{
  
  with (thisform)
  {
    if (validate_required(strName,"Please Enter Your Name")==false)
    {
      strName.style.background = '#CC9999'; 
      strName.focus();
      return false;
    }
    else
    {
      strName.style.background = 'white'; 
    }         
    
     
    if (validate_required(txrFeedback,"Please Enter Your Feedback")==false)
    {
      txrFeedback.style.background = '#CC9999'; 
      txrFeedback.focus();
      return false;
    }
    else
    {
      txrFeedback.style.background = 'white'; 
    }         
  }
}

function validate_addnewsectionfrm(thisform)
{

  with (thisform)
  {
    if (validate_required(AddNewContent,"You Must Enter Some Section Content")==false)
    {
      AddNewContent.style.background = '#CC9999'; 
      AddNewContent.focus();
      return false;
    }
    else
    {
      AddNewContent.style.background = 'white'; 
    }  
  
    if (TitleType.value !=0 && SectionTitle.value =="")
    {
      SectionTitle.style.background = '#CC9999'; 
      alert("If you are selecting a Title Type You Must enter a Section Title.")  ;
      SectionTitle.focus();    
      return false;
    }       
    else
    {
      SectionTitle.style.background = 'white'; 
    }       
  
    if (SectionTitle.value !="" && TitleType.value == 0)
    {
      TitleType.style.background = '#CC9999'; 
      alert("If You are Entering a Section Title You Must Select a title type.") ;
      TitleType.focus();    
      return false;
    }
    else
    {
      TitleType.style.background = 'white'; 
    } 
            
    if (TitleType.value == 3 && TitleLink.value=="")
    {
      TitleLink.style.background = '#CC9999'; 
      alert("If You are Entering a Link Title Add you must enter the Link.") ;
      TitleLink.focus();    
      return false;      
    }
    else
    {
      TitleLink.style.background = 'white';        
    } 
      
  }
}

function validate_editsectionfrm(thisform)
{

  with (thisform)
  {
    if (validate_required(Content,"You Must Enter Some Section Content")==false)
    {
      Content.style.background = '#CC9999'; 
      Content.focus();
      return false;
    }
    else
    {
      Content.style.background = 'white'; 
    }

    if (TitleType.value !=0 && Title.value =="")
    {
      Title.style.background = '#CC9999'; 
      alert("If you are selecting a Title Type You Must enter a Section Title.")  ;
      Title.focus();    
      return false;
    }       
    else
    {
      Title.style.background = 'white'; 
    }

    if (Title.value !="" && TitleType.value == 0)
    {
      TitleType.style.background = '#CC9999'; 
      alert("If You are Entering a Section Title You Must Select a title type.") ;
      TitleType.focus();    
      return false;
    }
    else
    {
      TitleType.style.background = 'white'; 
    } 
            
    if (TitleType.value == 3 && TitleLink.value=="")
    {
      TitleLink.style.background = '#CC9999'; 
      alert("If You are Entering a Link Title Add you must enter the Link.") ;
      TitleLink.focus();    
      return false;      
    }
    else
    {
      TitleLink.style.background = 'white';        
    }            
      
  }
}

function validate_addnewuser(thisform)
{
  with (thisform)
  {
    var str= EmailAddress.value;
    
    var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)  
  
    if (validate_required(FullName,"Please Enter The Name")==false)
    {
      FullName.style.background = '#CC9999'; 
      FullName.focus();
      return false;
    }
    else
    {
      FullName.style.background = 'white'; 
    }

    if (validate_required(EmailAddress,"Please Enter Your email address")==false)
    {
      EmailAddress.style.background = '#CC9999'; 
      EmailAddress.focus();
      return false;
    }
    else if (str.indexOf(at)==-1)
    {
      alert("Invalid E-mail Address No @ Detected");
      EmailAddress.style.background = '#CC9999'; 
      EmailAddress.focus();
      return false
		}

		else if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr)
    {
      alert("Invalid E-mail Address");
      EmailAddress.style.background = '#CC9999'; 
      EmailAddress.focus();
      return false
		}

		else if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr)
    {
      alert("Invalid E-mail Address");
      EmailAddress.style.background = '#CC9999'; 
      EmailAddress.focus();
      return false
		}

		else if (str.indexOf(at,(lat+1))!=-1)
    {
      alert("Invalid E-mail Address");
      EmailAddress.style.background = '#CC9999'; 
      EmailAddress.focus();
      return false
		 }

		else if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot)
    {
      alert("Invalid E-mail Address");
      EmailAddress.style.background = '#CC9999'; 
      EmailAddress.focus();
      return false
		 }

		else if (str.indexOf(dot,(lat+2))==-1){
      alert("Invalid E-mail Address");
      EmailAddress.style.background = '#CC9999'; 
      EmailAddress.focus();
      return false
		 }
		
		 else if (str.indexOf(" ")!=-1){
		    alert("Invalid E-mail Address");
		          EmailAddress.style.background = '#CC9999'; 
      EmailAddress.focus();
		    return false
		 }
		 else {
		 
      EmailAddress.style.background = 'white'; 
     
     }
		  


  }
}
function validate_groups(thisform)
{
  with (thisform)
  {
    if (validate_required(GroupName,"Please Enter The Group Name")==false)
    {
      GroupName.style.background = '#CC9999'; 
      GroupName.focus();
      return false;
    }
    else
    {
      GroupName.style.background = 'white'; 
    }
    if (validate_required(GroupDescription,"Please Enter The Group Description")==false)
    {
      GroupDescription.style.background = '#CC9999'; 
      GroupDescription.focus();
      return false;
    }
    else
    {
      GroupDescription.style.background = 'white'; 
    }
    
  
    
  }
}

function validate_usersearch(thisform)
{
  with (thisform)
  {
    if (intSeachType.value == 0)
    {
      intSeachType.style.background = '#CC9999'; 
      alert("Please select the search type");
      intSeachType.focus();
      return false;
    }
    else
    {
      intSeachType.style.background = 'white';  
    }
    if (strSearchString.value =="" && intSeachType.value != 3)
    {
      strSearchString.style.background = '#CC9999'; 
      alert("Please enter your Search Criteria ");
      strSearchString.focus();
      return false;
    }
    else
    {
      strSearchString.style.background = 'white';  
    }

  }
}


function validate_searchtype(thisform)
{  
  with(thisform)
  {
    var SeachType = document.form1.intSeachType.value;
    if (SeachType.value == 3)
    {
      document.form1.strSearchString.style.background = '#999'; 
      document.form1.strSearchString.disabled=true;
     }
    else 
    {
      document.form1.strSearchString.style.background ='white'; 
      document.form1.strSearchString.disabled=false;
    } 
  }
}

function validate_sendmail(thisform)
{  
  with(thisform)
  {
    
    if (validate_required(EmailGroup,"Please Select the group you wish to send to.")==false)
    {
      EmailGroup.style.background = '#CC9999'; 
      EmailGroup.focus();
      return false;
    }
    else
    {
      EmailGroup.style.background = 'white'; 
    }
    if (validate_required(Subject,"Please enter the subject of the email")==false)
    {
      Subject.style.background = '#CC9999'; 
      Subject.focus();
      return false;
    }
    else
    {
      Subject.style.background = 'white'; 
    }    

    if (validate_required(EmailBody,"Please enter the body of the email")==false)
    {
      EmailBody.style.background = '#CC9999'; 
      EmailBody.focus();
      return false;
    }
    else
    {
      EmailBody.style.background = 'white'; 
    }      

  }
}
function validate_addnewgallery(thisform)
{  
  with(thisform)
  {
    
    if (validate_required(GalleryName,"Please Enter the GalleryName")==false)
    {
      GalleryName.style.background = '#CC9999'; 
      GalleryName.focus();
      return false;
    }
    else
    {
      GalleryName.style.background = 'white'; 
    }
    if (validate_required(GalleryDescription,"Please Enter the Gallery Description")==false)
    {
      GalleryDescription.style.background = '#CC9999'; 
      GalleryDescription.focus();
      return false;
    }
    else
    {
      GalleryDescription.style.background = 'white'; 
    }    
    if (validate_required(GalleryMainPic,"Please Select the Picture you wish to display as the main Gallery Picture")==false)
    {
      GalleryMainPic.style.background = '#CC9999'; 
      GalleryMainPic.focus();
      return false;
    }
    else
    {
      GalleryMainPic.style.background = 'white'; 
    }    
      

  }
}

function validate_addnewgallerypicture(thisform)
{
  with(thisform)
  {
    
    if (validate_required(PicName,"Please Enter the Picture Description")==false)
    {
      PicName.style.background = '#CC9999'; 
      PicName.focus();
      return false;
    }
    else
    {
      PicName.style.background = 'white'; 
    }
    if (validate_required(Picture,"Please select the picture you wish to add to the gallery.")==false)
    {
      Picture.style.background = '#CC9999'; 
      Picture.focus();
      return false;
    }
    else
    {
      Picture.style.background = 'white'; 
    }    
  }
}

function validate_picturedescription(thisform)
{
  with(thisform)
  {    
    if (validate_required(PicDesc,"Please Enter the Picture Description")==false)
    {
      PicDesc.style.background = '#CC9999'; 
      PicDesc.focus();
      return false;
    }
    else
    {
      PicDesc.style.background = 'white'; 
    }
  }
}


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					
	}


