﻿// JScript File

  function strtrim()
	{
		return this.replace(/^\s+/,'').replace(/\s+$/,'');
	}
	String.prototype.trim = strtrim;
	
function checkspecialcharacter(target,str,status)
{    
     
    for (var i = 0; i < target.value.length; i++) 
     {
      if((str.indexOf(target.value.charAt(i)) != -1) && (status==false) )
  	   {
  	      alert ("Special characters...." + str + " are not allowed... ");
  	     return false;
	    }
      }

    return (true);
}

function textMatter(ctrlName)
{

    var editorText;
    var oEditor = FCKeditorAPI.GetInstance(ctrlName);
    
    editorText=oEditor.GetXHTML();
    editorText=editorText.replace(/(<br \/>)+/,"");
    editorText=editorText.replace(/(<div>&nbsp;<\/div>)+/,"");
    editorText=editorText.replace(/(<p>&nbsp;<\/p>)+/,"");
    editorText=editorText.replace(/<br type="_moz" \/>+/,"");
    return editorText;
}

	
	
	
	// -----------------------------------for News-----------------------------------
	
	function addNews_validate()
	{
	
		var tArticleName;
		tArticleName = document.add_category.txtArticleName.value;   
		tArticleName = tArticleName.trim();
		if (tArticleName == "")
		{
			alert ("Please enter Article Name.");
			document.add_category.txtArticleName.focus();   
			return (false);
		}
		else 
		{
		
		    if(!checkspecialcharacter(document.add_category.txtArticleName,"\"\<\>\\\/\:\*\?\|\'",false))
	        {
		       document.add_category.txtArticleName.focus();
		       return (false);
	        }
	    }
	    
	     if (textMatter(document.getElementById("FCKeditor2").id)=="")
			{
				alert ("Please enter Article Short Description.");
				return (false);
			}
	    
	    
	    if (textMatter(document.getElementById("FCKeditor1").id)=="")
			{
				alert ("Please enter Article Full Description.");
				return (false);
			}
	         
	        
	        

		
		var tCatImage;
		tCatImage = document.add_category.ExtCatImg.value;
		tCatImage = tCatImage.trim();

		
		if (tCatImage != "")
		{
			var uploadpdf=document.add_category.ExtCatImg.value;
			var filelen=uploadpdf.length;
			var pos=uploadpdf.lastIndexOf(".");
			pos=pos+1;
			var extn=uploadpdf.substr(pos,filelen);
			extn=extn.toUpperCase();

			if(document.add_category.ExtCatImg.value.lastIndexOf(".")==-1)
			{
				alert("Please browse for an Image file !");
				document.add_category.ExtCatImg.focus();
				return false;
			}
			else if(!((extn=="GIF")||(extn=="JPG")||(extn=="JPEG")||(extn=="JPE")))
			{
				alert("Only .gif, .jpg, .jpeg, jpe files are accepted.");
				document.add_category.ExtCatImg.focus();
				return false;
			}
			
		}
		
		
		// added by sandeep make alt tag manadatory when img exist else not mandatory-------------start----------
		
		
		
		
		
		
		var tArticleListAltTag;
		tArticleListAltTag = document.add_category.txtArticleImageAltTag.value;   
		tArticleListAltTag = tArticleListAltTag.trim();
		
		
		
		
		if (tCatImage != "")
		{
		
		        if (tArticleListAltTag == "")
		        {
        		
        		
        		
			        alert ("You have not entered  Article List Image Alt Tag.");
			        document.add_category.txtArticleImageAltTag.focus();   
			        return (false);
		        }
		        else 
		        {
        		
		            if(!checkspecialcharacter(document.add_category.txtArticleImageAltTag,"\"\<\>\\\/\:\*\?\|\'",false))
	                {
		               document.add_category.txtArticleImageAltTag.focus();
		               return (false);
	                }
	            }
		
		
		}
		
		
		
		
		
		
		
		
		
		var tCatImage2;
		tCatImage2 = document.add_category.imgArticleDetailImage.value;
		tCatImage2 = tCatImage2.trim();
		if (tCatImage2 != "")
		{
			var uploadpdf=document.add_category.imgArticleDetailImage.value;
			var filelen=uploadpdf.length;
			var pos=uploadpdf.lastIndexOf(".");
			pos=pos+1;
			var extn=uploadpdf.substr(pos,filelen);
			extn=extn.toUpperCase();

			if(document.add_category.imgArticleDetailImage.value.lastIndexOf(".")==-1)
			{
				alert("Please browse for an Image file !");
				document.add_category.imgArticleDetailImage.focus();
				return false;
			}
			else if(!((extn=="GIF")||(extn=="JPG")||(extn=="JPEG")||(extn=="JPE")))
			{
				alert("Only .gif, .jpg, .jpeg, jpe files are accepted.");
				document.add_category.imgArticleDetailImage.focus();
				return false;
			}
			
		}
		
		
		var tArticleDetailAltTag;
		tArticleDetailAltTag = document.add_category.txtArticleDetailImageAltTag.value;   
		tArticleDetailAltTag = tArticleDetailAltTag.trim();
		
		if (tCatImage2 != "")
		{
		if (tArticleDetailAltTag == "")
		{
			alert ("You have not entered  Article Detail Image Alt Tag.");
			document.add_category.txtArticleDetailImageAltTag.focus();   
			return (false);
		}
		else 
		{
		
		    if(!checkspecialcharacter(document.add_category.txtArticleDetailImageAltTag,"\"\<\>\\\/\:\*\?\|\'",false))
	        {
		       document.add_category.txtArticleDetailImageAltTag.focus();
		       return (false);
	        }
	    }
		
		}
		
			//------------------------------end ---------------------------
		
	
		
  	    if (document.add_category.txtFromDate.value != "" && document.add_category.txtToDate.value !="")
       {
       
      
            var monthNames = new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
            var dt = new Date();
            var y  = dt.getFullYear();
            var m  = monthNames[dt.getMonth()]; 
            var d  = dt.getDate();
            var currentDate=d + "-" + m + "-" + y;
            
          
			var StartDate = document.add_category.txtFromDate.value;
			var EndDate = document.add_category.txtToDate.value;
			
			if(compareDates(EndDate,"dd-MMM-yyyy",currentDate,"dd-MMM-yyyy") == -1)
			{
			    alert("News expiry date can not be lesser than current date.");
                document.add_category.txtFromDate.focus();
                return false;
			
			
			}
			if(compareDates(StartDate,"dd-MMM-yyyy",EndDate,"dd-MMM-yyyy") == 1)
            {
                alert("News launch date can not be greater than news expiry date.");
                
                document.add_category.txtFromDate.focus();
                return false;
            }
                
                
       }
       
       
       
       if (document.add_category.txtFromDate.value == "")
       {
             
       var monthNames = new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");

       
            var dt = new Date();
            var y  = dt.getFullYear();
            var m  = monthNames[dt.getMonth()]; 
            var d  = dt.getDate();
            var currentDate=d + "-" + m + "-" + y;
            
         
			var StartDate = document.add_category.txtFromDate.value;
			var EndDate = document.add_category.txtToDate.value;
			
			if(compareDates(EndDate,"dd-MMM-yyyy",currentDate,"dd-MMM-yyyy") == -1)
			{
			    alert("News expiry date can not be lesser than current date.")
                document.add_category.txtToDate.focus();
                return false;
			
			
			}
			               
                
       }
       
  	    
  	
				
		var st;

		
		st=document.add_category.TxtSeoKeyword.value;  
		if(st.length>230)
		{
			alert ("Please enter SEO Page Keywords less than or equal to 230 characters\nYour current Keywords contains "+ st.length +" characters.");
			document.add_category.TxtSeoKeyword.focus();  
			return (false);
		}
	

	
		st=document.add_category.TxtSeoDesc.value;  
		if(st.length>230)
		{
			alert ("Please enter SEO Page Description less than or equal to 230 characters\nYour current description contain "+st.length+" character.");
			document.add_category.TxtSeoDesc.focus();  
			return (false);
		}
		


	
		
		return(true);
		
	}
	
	
	
	//-----------------------------------------Update News------------------------------------
	function updateNews_validate()
	{
		var tArticleName;
		tArticleName = document.add_category.TxtArticleName.value;   
		tArticleName = tArticleName.trim();
		if (tArticleName == "")
		{
			alert ("Please enter Article Name.");
			document.add_category.TxtArticleName.focus();   
			return (false);
		}
		else 
		{
		
		    if(!checkspecialcharacter(document.add_category.TxtArticleName,"\"\<\>\\\/\:\*\?\|\'",false))
	        {
		       document.add_category.TxtArticleName.focus();
		       return (false);
	        }
	    }
	    
	    
	    if (textMatter(document.getElementById("FCKeditor2").id)=="")
			{
				alert ("Please enter Article Short Description.");
				return (false);
			}
	    
	    if (textMatter(document.getElementById("FCKeditor1").id)=="")
			{
				alert ("Please enter Article Full Description.");
				return (false);
			}
	         
        
	        

		
		var tCatImage;
		tCatImage = document.add_category.ExtArticleImg.value;
		tCatImage = tCatImage.trim();

		
		if (tCatImage != "")
		{
			var uploadpdf=document.add_category.ExtArticleImg.value;
			var filelen=uploadpdf.length;
			var pos=uploadpdf.lastIndexOf(".");
			pos=pos+1;
			var extn=uploadpdf.substr(pos,filelen);
			extn=extn.toUpperCase();

			if(document.add_category.ExtArticleImg.value.lastIndexOf(".")==-1)
			{
				alert("Please browse for an Image file !");
				document.add_category.ExtArticleImg.focus();
				return false;
			}
			else if(!((extn=="GIF")||(extn=="JPG")||(extn=="JPEG")||(extn=="JPE")))
			{
				alert("Only .gif, .jpg, .jpeg, jpe files are accepted.");
				document.add_category.ExtArticleImg.focus();
				return false;
			}
			
		}
		
		// -------------------start---------------------------------------------
		var tArticleListAltTag;
		tArticleListAltTag = document.add_category.txtArticleImageAltTag.value;   
		tArticleListAltTag = tArticleListAltTag.trim();
		
		if (tCatImage != "")
		{
		        if (tArticleListAltTag == "")
		        {
			        alert ("You have not entered  Article List Image Alt Tag.");
			        document.add_category.txtArticleImageAltTag.focus();   
			        return (false);
		        }
		        else 
		        {
        		
		            if(!checkspecialcharacter(document.add_category.txtArticleImageAltTag,"\"\<\>\\\/\:\*\?\|\'",false))
	                {
		               document.add_category.txtArticleImageAltTag.focus();
		               return (false);
	                }
	            }
        		
		}
		
		
		var tCatImage;
		tCatImage = document.add_category.imgArticleDetailImage.value;
		tCatImage = tCatImage.trim();

		
		if (tCatImage != "")
		{
			var uploadpdf=document.add_category.imgArticleDetailImage.value;
			var filelen=uploadpdf.length;
			var pos=uploadpdf.lastIndexOf(".");
			pos=pos+1;
			var extn=uploadpdf.substr(pos,filelen);
			extn=extn.toUpperCase();

			if(document.add_category.imgArticleDetailImage.value.lastIndexOf(".")==-1)
			{
				alert("Please browse for an Image file !");
				document.add_category.imgArticleDetailImage.focus();
				return false;
			}
			else if(!((extn=="GIF")||(extn=="JPG")||(extn=="JPEG")||(extn=="JPE")))
			{
				alert("Only .gif, .jpg, .jpeg, jpe files are accepted.");
				document.add_category.imgArticleDetailImage.focus();
				return false;
			}
			
		}
		
		
		var tArticleDetailAltTag;
		tArticleDetailAltTag = document.add_category.imgArticleDetailImageAltTag.value;   
		tArticleDetailAltTag = tArticleDetailAltTag.trim();
		
		if (tCatImage != "")
		{
		            if (tArticleDetailAltTag == "")
		            {
			            alert ("You have not entered  Article Detail Image Alt Tag.");
			            document.add_category.imgArticleDetailImageAltTag.focus();   
			            return (false);
		            }
		            else 
		            {
            		
		                if(!checkspecialcharacter(document.add_category.imgArticleDetailImageAltTag,"\"\<\>\\\/\:\*\?\|\'",false))
	                    {
		                   document.add_category.imgArticleDetailImageAltTag.focus();
		                   return (false);
	                    }
	                }
            		
		}
		
		// -------------------end---------------------------------------------
		
		
		
		 if (document.add_category.txtFromDate.value != "" && document.add_category.txtToDate.value !="")
       {
       
      
       var monthNames = new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");

       
            var dt = new Date();
            var y  = dt.getFullYear();
            var m  = monthNames[dt.getMonth()]; 
            var d  = dt.getDate();
            var currentDate=d + "-" + m + "-" + y;
            
          
			var StartDate = document.add_category.txtFromDate.value;
			var EndDate = document.add_category.txtToDate.value;
			
			if(compareDates(EndDate,"dd-MMM-yyyy",currentDate,"dd-MMM-yyyy") == -1)
			{
			    alert("News expiry date can not be lesser than current date.")
                document.add_category.txtFromDate.focus();
                return false;
			
			
			}
			if(compareDates(StartDate,"dd-MMM-yyyy",EndDate,"dd-MMM-yyyy") == 1)
                {
                alert("News launch date can not be greater than news expiry date.")
                
                document.add_category.txtFromDate.focus();
                return false;
                }
                
                
       }
       
       
       
       if (document.add_category.txtFromDate.value == "")
       {
             
       var monthNames = new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");

       
            var dt = new Date();
            var y  = dt.getFullYear();
            var m  = monthNames[dt.getMonth()]; 
            var d  = dt.getDate();
            var currentDate=d + "-" + m + "-" + y;
            
         
			var StartDate = document.add_category.txtFromDate.value;
			var EndDate = document.add_category.txtToDate.value;
			
			if(compareDates(EndDate,"dd-MMM-yyyy",currentDate,"dd-MMM-yyyy") == -1)
			{
			    alert("News expiry date can not be lesser than current date.")
                document.add_category.txtToDate.focus();
                return false;
			
			
			}
			               
                
       }
		
			
		var st;
       
		st=document.add_category.TxtSeoKeyword.value;  
		if(st.length>230)
		{
			alert ("Please enter SEO Page Keywords less than or equal to 230 characters\nYour current Keywords contains "+ st.length +" characters.");
			document.add_category.TxtSeoKeyword.focus();  
			return (false);
		}
	

		st=document.add_category.TxtSeoDesc.value;  
		if(st.length>230)
		{
			alert ("Please enter SEO Page Description less than or equal to 230 characters\nYour current description contain "+st.length+" character.");
			document.add_category.TxtSeoDesc.focus();  
			return (false);
		}
		
		


	
		
		return(true);
		
	}
	
	
	
	
	// -------------------------------------------front end for comments --------------------------------------
	
	function addComments_validate()
	{
	
	
		var tCommentName;
		tCommentName = document.getElementById("leaveacomment_commentname").value;   
		tCommentName = tCommentName.trim();
		
		if (tCommentName == "")
		{
			alert ("You have not entered Name.");
			document.getElementById("leaveacomment_commentname").focus();   
			return (false);
		}
		else 
		{
		
		    if(!checkspecialcharacter(document.getElementById("leaveacomment_commentname"),"\"\<\>\\\/\:\*\?\|\'",false))
	        {
		      document.getElementById("leaveacomment_commentname").focus();
		       return (false);
	        }
	    }
	    
	    if(!checkspecialcharacter(document.getElementById("leaveacomment_commentcompany"),"\"\<\>\\\/\:\*\?\|\'",false))
	        {
		      document.getElementById("leaveacomment_commentcompany").focus();
		       return (false);
	        }
	    
	    
	    var txtemail;
        txtemail=document.getElementById("leaveacomment_commentemail").value;
	    var emailexp;
        emailexp = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
         if(emailexp.test(txtemail) == 0)
	    {
			alert("Please enter your valid email.");
			document.getElementById("leaveacomment_commentemail").focus();
			return false;
	    }
	    
	    
	    var st;
		st=document.getElementById("leaveacomment_comment").value;  
		st = st.trim();
		
		if (st == "")
		{
			alert ("You have not entered Comment.");
			document.getElementById("leaveacomment_comment").focus();   
			return (false);
		}
		
	    
		if(st.length>500 || st.length<5)
		{
			alert ("Please enter comment between 5 to 500 characters.\nYour current comment contains "+ st.length +" characters.");
			document.getElementById("leaveacomment_comment").focus();  
			return (false);
		}
	
	    
	  
		
		
		  var str;
		str=document.getElementById("leaveacomment_hdnRating").value;  
		str = str.trim();
		
		if (str == "No")
		{
			alert ("Please choose review.");
			 
			return (false);
		}
		if (str == "")
		{
			alert ("Please choose review.");
			 
			return (false);
		}
	    


	
		
		return(true);
		
	}