    //CHECK SPECIAL CHARACTERS FOR LIGHTBOX NAME
 function CheckChar(boxname)
        {
        var charToCheck = new Array("&","%","+","'");
  	    var len=charToCheck.length; 
  	    var returnValue = true;	
	
  	    for (i=0;i<len;i++) 
  	    {
  	        if(boxname.indexOf(charToCheck[i]) != -1)
  		    {			
  		      returnValue = false;
  		    }
  	    }
  	    return returnValue; 
        }
    //CHECK SPECIAL CHARACTERS FOR LIGHTBOX KEY & DESC
    function CheckChar2(boxkey,boxdesc)
        {
        var charToCheck = new Array("~","`","#","$","%","^","*","+","|","{","}",";","<",">","?","@","_","]","[",".","'","(",")","&");
  	    var len=charToCheck.length; 
  	    var returnValue = true;	
	
  	    for (i=0;i<len;i++) 
  	    {
  	        if(boxkey.indexOf(charToCheck[i]) != -1)
  		    {			
  		      returnValue = false;
  		    }
  	    }
  	    return returnValue; 
  	    
        }
 //SEARCH FOR EVERY PAGE   
    function search()
    {
    strSearch =document.frmsearch.strsearch.value;
    searchType=document.frmsearch.searchType.value;
    document.getElementById("error").style.display = "none";
    document.getElementById("errorSpecialCharacters").style.display = "none";
    var error=0;
    if(strSearch =="")
    {
        document.getElementById("error").style.display = "inline";
        document.getElementById("errorSpecialCharacters").style.display = "none";
        error=1;
    }
    if((strSearch !="") && (CheckChar(strSearch) == false))
    {
       document.getElementById("errorSpecialCharacters").style.display = "inline";
       document.getElementById("error").style.display = "none";
       error=1;
    }
    if(error == 0)
    {
        if (searchType == "I")
        {
            document.frmsearch.action="../photo/search_image.asp?strSearch="+ strSearch + "&searchtype=" +searchType;
	        document.frmsearch.submit();
	    }
	    else if(searchType == "L")
	    {
	        document.frmsearch.action="../lightbox/search_lightbox.asp?strSearch="+ strSearch + "&searchtype=" +searchType;
	        document.frmsearch.submit();
	    }
	 }
	  else
        return false;
    
}
//SEARCH IN DEFAULT PAGE
    function searchDefault()
    {
    strSearch =document.frmsearch.strsearch.value;
    searchType=document.frmsearch.searchType.value;
    document.getElementById("error").style.display = "none";
    var error=0;
    if(strSearch =="")
    {
        document.getElementById("error").style.display = "inline";
        error=1;
    }
    if((strSearch !="") && (CheckChar(strSearch) == false))
    {
       document.getElementById("errorSpecialCharacters").style.display = "inline";
       document.getElementById("error").style.display = "none";
       error=1;
    }
    if(error ==0)
    {
        if (searchType == "I")
        {
            document.frmsearch.action="photo/search_image.asp?strSearch="+ strSearch + "&searchtype=" +searchType;
	        document.frmsearch.submit();
	    }
	    else if(searchType == "L")
	    {
	        document.frmsearch.action="lightbox/search_lightbox.asp?strSearch="+ strSearch + "&searchtype=" +searchType;
	        document.frmsearch.submit();
	    }
	 }
	  else
        return false;
    
}
//ADD COMMENT
function chkEmptyComment()
{
      document.getElementById("errorUser").style.display = "none";
      document.getElementById("ErrorDesc").style.display = "none";

      
      UserName=document.frm_addcomment.UserName.value;
      CommentDesc=document.frm_addcomment.CommentDesc.value;
      var errorComment=0;
      if(UserName == "")
      {
            document.getElementById("errorUser").style.display = "inline";
            errorComment=1;
      }

      if(CommentDesc=="")
      {
            document.getElementById("ErrorDesc").style.display = "inline";
            errorComment=1;
      }
      if(errorComment==0)
      {
        document.frm_addcomment.hiddAdd.value="CommentSubmit";
        document.frm_addcomment.submit();
      }

}
//RECOMMEND PAGE
function chkEmptyEmail()
{
      document.getElementById("errsender").style.display = "none";
      document.getElementById("errReceiverEmail").style.display = "none";
      document.getElementById("errmessage").style.display = "none";
      document.getElementById('errorInvalid').style.display = 'none';
      var errorEmail=0;
      var emails = document.getElementById("emails").value;
	  var emailArray = emails.split(",");

	  var invEmails = "";
      if(  document.getElementById('sendername').value == "")
      {
            document.getElementById("errsender").style.display = "inline";
            errorEmail=1;
      }

      if(document.frm_recommend.ReceiverEmail.value=="")
      {
            document.getElementById("errReceiverEmail").style.display = "inline";
            errorEmail=1;
      }
      if(document.frm_recommend.ReceiverEmail.value!="")
      {
        for(i = 0; i <= (emailArray.length - 1); i++)
        {
		    if(!(checkEmail(emailArray[i])))
		    {
			     document.getElementById('errorInvalid').style.display = 'inline';
			     errorEmail=1;
		    }
		
	    }
      }
      if(document.frm_recommend.message.value=="")
      {
            document.getElementById("errmessage").style.display = "inline";
            errorEmail=1;
      }
      if(errorEmail==0)
      {
        document.frm_recommend.hiddSend.value="SendEmail";
        document.frm_recommend.submit();
      }

}
function checkEmail(email) 
{
//var regExp = /(^[a-z]([a-z_\.]*)@([a-z_\.]*)([.][a-z]{3})$)|(^[a-z]([a-z_\.]*)@([a-z_\.]*)(\.[a-z]{3})(\.[a-z]{2})*$)/i;
var regExp = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
return regExp.test(email);
}

function Trim(str)
{  while(str.charAt(0) == (" ") )
  {  str = str.substring(1);
  }
  while(str.charAt(str.length-1) == " " )
  {  str = str.substring(0,str.length-1);
  }
  return str;
  alert(str);
}


function chkEmpty()
{
      document.getElementById("errorbox").style.display = "none";
      document.getElementById("errKey").style.display =  "none";
      document.getElementById("errorduplicate").style.display =  "none";
      document.getElementById("specChar1").style.display = "none";
      document.getElementById("specChar2").style.display = "none";
      document.getElementById("specChar3").style.display = "none";

      var boxname =document.frm_addbox.boxname.value
      
// --IF NEW LIGHTBOX IS CLICKED--
  if(document.frm_addbox.hiddentype.value =="N")
  {
        document.getElementById("errorSelect").style.display = "none";
         document.getElementById("errorSelectLightbox").style.display = "none";
          document.getElementById('errorExistPhoto').style.display = "none";
        if((boxname ==""))
        {
            document.getElementById("errorbox").style.display = "inline";
            document.getElementById('errorExistPhoto').style.display = 'none';
           document.frm_addbox.boxname.focus();
        }
        else if (CheckChar(boxname) == false)
        {
            document.getElementById("specChar1").style.display = "inline";
            document.frm_addbox.boxname.focus();
        }
        else
     {
           if(window.XMLHttpRequest)
           {
               oRequest = new XMLHttpRequest();
           }
            else if(window.ActiveXObject)
            {
               oRequest = new ActiveXObject("Microsoft.XMLHTTP");
            }

           oRequest.open("POST", "../checks/checkduplicate.asp", true);
           oRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
           oRequest.send("act=add&lightboxname=" +  boxname);
           oRequest.onreadystatechange = UpdateCheckAvailability;  //CALL TO NEXT FUNCTION UPDATECHECKAVAILABILITY
       }
        if((document.frm_addbox.boxdesc.value!="")&&(CheckChar2(document.frm_addbox.boxdesc.value) == false))
        {
            document.getElementById("specChar2").style.display = "none";
            document.frm_addbox.boxdesc.focus();
        }
        if((document.frm_addbox.boxkey.value ==""))
        {
            document.getElementById("errKey").style.display = "inline";
            document.frm_addbox.boxkey.focus();
        }                
       if(CheckChar2(document.frm_addbox.boxkey.value) == false)
       {
          document.getElementById("specChar3").style.display = "inline";
          document.frm_addbox.boxkey.focus();
        }
 }
 // --- IF EXIST RADIO BUTTON IS CHECKED---
 if (document.frm_addbox.hiddentype.value =="E")
    {
	  var errorSubmit =0;
	  document.getElementById("errorSelect").style.display = "none";
	  document.getElementById("errorSelectLightbox").style.display = "none";
	  document.getElementById('errorExistPhoto').style.display = "none";

	  if(document.frm_addbox.lightbox.value =="")
	  {
	   //alert("aa")
	     document.getElementById("errorSelectLightbox").style.display = "inline";
	     document.getElementById('errorExistPhoto').style.display = "none";
	     document.getElementById("errorSelect").style.display = "none";
	     errorSubmit =1;
	  }
	
	  if(((document.frm_addbox.hiddentype.value !="N"))&&((boxname !="") || (document.frm_addbox.boxdesc.value!="") || (document.frm_addbox.boxkey.value!="")))
        {
            // alert("bb")
            document.getElementById("errorSelect").style.display = "inline";
            document.getElementById("errorSelectLightbox").style.display = "none";
            document.getElementById('errorExistPhoto').style.display = "none";
            errorSubmit =1;
        }
      //CHECK THE PHOTO ID IS EXIST IN THE LIGHTBOX OR NOT    
     if((document.frm_addbox.lightbox.value !="")&&((boxname =="") && (document.frm_addbox.boxdesc.value=="") && (document.frm_addbox.boxkey.value=="")))
     {
        //alert("cc")
        if(window.XMLHttpRequest)
           {
               objectRequest = new XMLHttpRequest();
           }
           else if(window.ActiveXObject)
           {
               objectRequest = new ActiveXObject("Microsoft.XMLHTTP");
           }
            objectRequest.open("POST", "../checks/checkduplicate.asp", true);
            objectRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
            objectRequest.send("act=checkInside&boxid="+document.frm_addbox.lightbox.value + "&boxphoto="+document.frm_addbox.hidphotoid.value);
            objectRequest.onreadystatechange = CheckExist;
            errorSubmit =1;
     
     
     }
		if(errorSubmit ==0)
		{
            document.frm_addbox.hidsubmit.value="Submit";
            document.frm_addbox.submit();
		}
    }
}
function UpdateCheckAvailability()
{
 document.getElementById('errKey').style.display = 'none';
 document.getElementById("errorduplicate").style.display =  "none";
 document.getElementById("errKey").style.display =  "none";
 document.getElementById("specChar1").style.display = "none";
 document.getElementById("specChar2").style.display = "none";
 document.getElementById("specChar3").style.display = "none";

if(oRequest.readyState == 4)
{ 
if(oRequest.status == 200)
{
    //document.getElementById("Available").innerHTML = oRequest.responseText;
    var ab =oRequest.responseText;
    var error =0;
    if(ab==1)
    {
         document.getElementById('errorduplicate').style.display = "inline";
         document.getElementById('errorbox').style.display = "none";
          document.getElementById('errorExistPhoto').style.display = "none";
         document.frm_addbox.boxname.focus();
         error =1;
    }
    if(ab==2)
    {
         error =0;
    }
    if((document.frm_addbox.boxdesc.value !="")&&(CheckChar2(document.frm_addbox.boxdesc.value) == false))
    {
         document.getElementById('specChar2').style.display = 'inline';
		 document.frm_addbox.boxdesc.focus();
         error =1;
    }
    if(document.frm_addbox.boxkey.value =="")
    {
         document.getElementById('errKey').style.display = 'inline';
		 document.frm_addbox.boxkey.focus();
         error =1;
    }
    if(CheckChar2(document.frm_addbox.boxkey.value) == false)
    {
          document.getElementById('specChar3').style.display = 'inline';
		  document.frm_addbox.boxkey.focus();
          error=1;
    }
    
    if(error ==0)
    {
        document.frm_addbox.hidsubmit.value="Submit";
        document.frm_addbox.submit();
    }
}
}//close oRequest.readyState
}


function CheckExist()
{
   document.getElementById('errorExistPhoto').style.display ="none";
    if(objectRequest.readyState == 4)
    { 
        if(objectRequest.status == 200)
        {
            var abc =objectRequest.responseText;
            var errorExit =0;
           // alert(abc);
            if(abc==3)
            {
                document.getElementById('errorExistPhoto').style.display = "inline";
                document.getElementById('errorSelectLightbox').style.display = 'none';
                
                errorExit =1;
            }
            if(abc==4)
            {
               errorExit=0;
            }
            if(errorExit==0)
            {
               document.frm_addbox.hidsubmit.value="Submit";
               document.frm_addbox.submit();
            }
                        
        }
    }
}


function CheckPwordChar(x)
{
    var iChars = "`~!@#$%^&*()+=_-[]\\\';,./{}|\":<>?";
    for (var i = 0; i < x.length; i++)
    {
        if (iChars.indexOf(x.charAt(i)) != -1)
            return false;
    }
}


function chkPublishcomment()
{
document.getElementById('errorPublish').style.display = 'none';
var errPublish=0;
if(document.frm_publishcomment.statuspublish.value=="0")
{
    document.getElementById('errorPublish').style.display = 'inline';
    errPublish=1;
}
if (errPublish ==0)
{
    document.frm_publishcomment.hiddenPublish.value="Publishcomment";
    document.frm_publishcomment.submit();
}
}