function goodnum(string) 
    {
		var status=true;
		var good="0123456789";
		
			for (var i = 0; i < string.length; i++) 
			{
			   if (good.indexOf(string.charAt(i)) == -1) 
			   {
				  status= false;
				  break;
			   }
			}   
			   return status;
   }//end of function

function goodph1(string) 
    {
		var status=true;
		var good="0123456789-()";
		
			for (var i = 0; i < string.length; i++) 
			{
			   if (good.indexOf(string.charAt(i)) == -1) 
			   {
				  status= false;
				  break;
			   }
			}   
			   return status;
   }//end of function
 function SelectValidation(Element,Message) {
		if(Element.value == "0") {
			alert("Please select "+Message+" from the list");
			Element.focus();
			return 0;
		}
	
	}//// closing the function SELECTVALIDATION

	function GenValidation(Element,MessageLen0,MessageLen4,spl) {
			if(Element.value.length == 0)
			{
				alert("Please enter the "+ MessageLen0);
				Element.focus();
				return 0;
			}
			else if(isBlank(Element.value))
			{
				alert("Please enter the "+ MessageLen0);
				Element.focus();
				return 0;
			}
		
		if(MessageLen4.length != 0)
		{
			if(Element.value.length < 3)
			{
				alert( MessageLen4 + " should be minimum 3 characters");
				Element.focus();
				return 0;
			} // closing the if - else condtion for if(MessageLen4.length != 0)
		}
	
		if(spl == "spl")
		{
			if(SplCharacters(Element) == 0)
			return 0;
		}
		else if(spl == "space")
		{
			if(SplCharactersSpace(Element) == 0)
			return 0;
		}
		else if(spl == "spl1")
		{
			if(SplCharactersBlank(Element) == 0)
			return 0;
		}
		else if(spl == "name")
		{
			if(SplCharactersName(Element) == 0)
			return 0;
		}

		
	} // closing the function GenValidation()
	
	
	
	/**
	 FUNCTION SPLCHARACTERS(element) 
	 **/
	
	function SplCharacters(Val) {
	
		var alp = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_";
	
		for (var i=0;i<Val.value.length;i++){
			temp=Val.value.substring(i,i+1);
			if (alp.indexOf(temp)==-1){
				alert("No special characters \nValid entries are [a-z][A-Z][0-9][ _ ]");
				Val.focus();
				return 0;
			}
		} // closing the for loop
	
	} // closing the function SplCharacters()
	
	function SplCharactersBlank(Val) {
	
		var alp = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_ ";
	
		for (var i=0;i<Val.value.length;i++){
			temp=Val.value.substring(i,i+1);
			if (alp.indexOf(temp)==-1){
				alert("No special characters \nValid entries are [a-z][A-Z][0-9][ _ ]");
				Val.focus();
				return 0;
			}
		} // closing the for loop
	
	} // closing the function SplCharacters()
	
	/**
	 FUNCTION SPLCHARACTERS(element) 
	 **/

	 function SplCharactersName(Val) {
	
		var alp = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ ";
	
		for (var i=0;i<Val.value.length;i++){
			temp=Val.value.substring(i,i+1);
			if (alp.indexOf(temp)==-1){
				alert("Please enter Only Alphabets!.. \nValid entries are [a-z][A-Z]");
				Val.focus();
				return 0;
			}
		} // closing the for loop
	
	} // closing the function SplCharacters()
	
	/**
	 FUNCTION SPLCHARACTERS(element) 
	 **/
	
	function SplCharactersSpace(Val)
	{
		var alp = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 ";
	
		for (var i=0;i<Val.value.length;i++){
			temp=Val.value.substring(i,i+1);
			if (alp.indexOf(temp)==-1){
				alert("No special characters \nValid entries are [a-z][A-Z][0-9][ space ]");
				Val.focus();
				return 0;
			}
		} // closing the for loop
	} // closing the function SplCharactersSpace()
	
	/**
	 FUNCTION SPLNUMBERS(element) 
	 **/
	
	function SplNumbers(Val)
	{
		var alp = "0123456789+-)(";
	
		for (var i=0;i<Val.value.length;i++){
			temp=Val.value.substring(i,i+1);
			if (alp.indexOf(temp)==-1){
				alert("No special characters \nValid entries are [0-9][ + - ]");
				Val.focus();
				return 0;
			}
		} // closing the for loop
	
	} // closing the function SplNumbers()
	
	
	/**
	 FUNCTION FOR CHECKING THE FIELD CONTAINS BLANK VALUES ISBLANK(Element.value)
	 **/
	//To check if trim(value) is blank
function isBlank(txt, minlen)
{
	/*
		This fucntion can be used to check if a given text contains only spaces or 0 in length.

		INPUT: Text [txt]
					Minimum Length [minlen] optional
					Indicates that the text should be atleast 'minlen' in length

		OUTPUT: returns true if blank else false
	*/

	if( txt.length == getCountOf('\n', txt) )
	{
		/*
			This condition avoids the entry of just newlines in text areas.
		*/
		return true;
	}

	if( txt.length == getCountOf(' ', txt) || txt.length == 0 )
	{
		return true;
	}
	else if( minlen > 0 )
	{
		if( txt.length < minlen )
		{
			return true;
		}
		else
		{
			return false;
		}
	}
	else
	{
		return false;
	}
}
	
	//This can be used for any character validation.
	//For example in a valid date the count of - or / should not be more than 2
	//Likewise in a valid numer there should be only one .
	function getCountOf(vChr, txt)
	{
		var i = 0;
		var iCount = 0;
	
		for( i=0; i < txt.length; i++ )
		{
			if( txt.charAt(i) == vChr )
			{
				iCount++;
			}
		}
		return iCount;
	}
	
	
	function getSelectedIndex(radgroup)
	{
		/* Returns back the id of selected radio button in a radio button group  */
		var j = -1;
	
		for( i=0; i < radgroup.length; i++ )
		{
			if( radgroup[i].checked )
			{
				j = i;
			}
		}
		return j;
	}
	
	
	
	/**
	 FUNCTION EMAILVALIDATION(element) 
	 **/
	 
	function EmailValidation(Element)
	{
		Flag  = 1;
		count = 0;
	
		var alp = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_@.-";
		
		if(Element.value.length > 0)
		{
			for (var i=0; i<Element.value.length; i++)
			{
				temp = Element.value.substring(i, i+1);
	
				if (alp.indexOf(temp) == -1)
				{
					Flag = 0;
				}
			} // closing the for loop
		}
		else
		{
			Flag = 0;
		}
	
		for(var i=0; i <= Element.value.length; i++)
		{
			if(Element.value.charAt(0)=='@')
			{
				Flag = 0;
				break;
			}

			if(Element.value.charAt(Element.value.length-1)=='@')
			{
				Flag = 0;
				break;
			}

			if(Element.value.charAt(i)=='@') 
			{
				count = count + 1;

				if(count>1)
				{
					Flag = 0;
					break;
				}
			  
				if((Element.value.charAt(i-1)=='.') || (Element.value.charAt(i+1)=='.'))
				{
					Flag = 0;
					break;
				}
			}
			if(Element.value.indexOf('@')==-1)
			{
				Flag = 0;		    	
				break;
			}
			if(Element.value.charAt(0)=='.')
			{
				Flag = 0;
				break;
			}
			if(Element.value.indexOf('.')==-1)
			{
				Flag = 0;		    	
				break;
			}
		  } //closing the for loop
		
		if(Element.value.charAt(Element.value.length-1) == '.')
			Flag = 0;
			
		if(Flag != 1)
		{
			alert("Invalid Email Address.\nValid Characters [a-z][A-Z][0-9][ _ @ . - ].\n\nlike test@test.com, test1942@test.co.uk ...");
			Element.focus();
			return 0;
		}	
		else
			return 1;
	}
	


function TextareaValidation(elem,msg,len) {
	
		   if(elem.value.length > 0)
		   {
			if(isBlank(elem.value)) 
			{
				alert("Please enter the value");
				elem.focus();
				return 0;
			}else if(elem.value.length > len) 
			{
				alert(msg+" should not exceed "+len+" characters");
				elem.focus();
				return 0;
			}	
		   }
		
	} // closing the function TextareaValidation()
  
//-------------------------------------------------------------This functions are related to index.jsp
function displayprod(pid)
 {
   document.frmpd.action.value=pid;
   frmpd.submit();
 }//end of function   
 //-------------------------------------------------------------This functions are related to productinfo.jsp
	function checkvaild()
	{
	  if(document.frmgati.txttotalqty.value.length==0)
	  {
	   alert("Quantity Can not be blank");
	   document.frmgati.txttotalqty.value = "";
	   document.frmgati.txttotalqty.focus();
  	    return false;
	  }//end of if
	  else
	  {
	  if(document.frmgati.txttotalqty.value==0)
 	    {
		 alert("Quantity Can not be Zero");
	  document.frmgati.txttotalqty.value = "";
	   document.frmgati.txttotalqty.focus();
		 return false;
		 } 
	 if ((!goodnum(document.frmgati.txttotalqty.value)))
	  {
		alert("Quantity Number must Numeric");
		document.frmgati.txttotalqty.value = "";
		document.frmgati.txttotalqty.focus();
		return false;
	  }//end of if
	 }//end of else
	 if(document.frmgati.dcountry.type=="select-one")
	 {
	  if(SelectValidation(document.frmgati.dcountry,'Delievery to which Country','','') == 0)
        return false;
	  }//end of if	
 	 if(document.frmgati.dcountry.type=="text")
	 {
	 	if(GenValidation(document.frmgati.dcountry,'Delievery to which Country',",")==0)
	   return false;
	  }//end of if
	  if(document.frmgati.flag_vtype.value=="true")
		{
	     if(SelectValidation(document.frmgati.vtype,'options','','') == 0)
         return false;
		}	
 
}//end of function

	function check_number_ent()
	{
	 var frm=document.frmgati;
	 var result=true;
	 if(event.keyCode == 13)	
    	{
		 result=checkvaild();
		}
	else if ( (event.keyCode < 48 || event.keyCode > 57) )
		{
			alert("Invalid input only numeric values accepted");
			event.returnValue = false;
		}//else if
		return result;
    }//end of function


 function checkenq()
 {
  	if(GenValidation(document.frmgatienq.txttoname,'Your Name',",")==0)
	return false;
	if(EmailValidation(document.frmgatienq.txtemail)==0)
	    return false; 
	if(GenValidation(document.frmgatienq.txtphno,'Your Phone Number',",")==0)
	return false;

 }//end of function  
 
 
 //--------------------------this functions are for orderinser.jsp
 
 function chkvalidpayment()
{
		if(GenValidation(document.frm.txtname,'Name',",")==0)
		return false;
    	if(GenValidation(document.frm.address,'Address',",")==0)
		return false;
		if(GenValidation(document.frm.txtcity,'City',",")==0)
		return false;
		
	if(document.frm.state1.type=="select-one")
	 {
	  if(SelectValidation(document.frm.state1,'State Name','','') == 0)
	   return false;
	  }//end of if	
 	 if(document.frm.state1.type=="text")
	 {
	 	if(GenValidation(document.frm.state1,'State Name',",")==0)
	   return false;
	  }//end of if
	//if(SelectValidation(document.frm.state1,'State Name','','') == 0)
       // return false;
	   if(GenValidation(document.frm.txtpin,'Pin Code',",")==0)
		return false;
		if ((!goodnum(document.frm.txtpin.value)))
	     {
		alert("Pin Code must Numeric");
		document.frm.txtpin.value = "";
		document.frm.txtpin.focus();
		return false;
	     }//end of if
        if(GenValidation( document.frm.txtphone,'Phone Number',",")==0)
  	    return false;
	    if ((!goodph1(document.frm.txtphone.value)))
	     {
		alert("Phone Number must Numeric");
		document.frm.txtphone.value = "";
		document.frm.txtphone.focus();
		return false;
	     }//end of if
 		if(EmailValidation(document.frm.txtemail)==0)
 	    return false;
		/*if(document.frm.flag_vtype.value=="true")
		{
	     if(SelectValidation(document.frm.vtype,'options','','') == 0)
         return false;
		}*/
if(document.frm.dgroup[0].checked==true)
{
  if(document.frm.dcountry.value=="INDIA") {
   if(SelectValidation(document.frm.dcity,'Delievery City','','') == 0)
    return false;
    }
}
		if(document.frm.dgroup[1].checked==true)
		{
		//if(GenValidation(document.frm.yourmessage,'Your Message',",")==0)
		//return false;
      //  if(TextareaValidation(document.frm.yourmessage,'Your Message',300) == 0)
       //return false;
		if(GenValidation(document.frm.dname,'Delievery to Name',",")==0)
		return false;
    	if(GenValidation(document.frm.daddress,'Delievery Address',",")==0)
		return false;
		if(document.frm.dcountry.value=="INDIA")
		{
		if(SelectValidation(document.frm.dcity,'Delievery City','','') == 0)
              return false;
		if(GenValidation(document.frm.dstate,'State Name',",")==0)
		return false;
		}
		if(GenValidation(document.frm.dpin,'Delievery Pin Code',",")==0)
		return false;
		if ((!goodnum(document.frm.dpin.value)))
	       {
		alert("Delievery Pin Code must Numeric");
		document.frm.dpin.value = "";
		document.frm.dpin.focus();
		return false;
	     }//end of if
        if(GenValidation( document.frm.dphone,'Delievery Phone Number',",")==0)
  	    return false;
		if ((!goodph1(document.frm.dphone.value)))
	     {
		alert("Delievery Phone Number must Numeric");
		document.frm.dphone.value = "";
		document.frm.dphone.focus();
		return false;
	     }//end of if
        if(GenValidation( document.frm.dphone2,'Delievery Land Phone Number',",")==0)
  	    return false;
		if ((!goodph1(document.frm.dphone2.value)))
	     {
		alert("Delievery Phone Number must Numeric");
		document.frm.dphone2.value = "";
		document.frm.dphone2.focus();
		return false;
	     }//end of if

	  //  if(EmailValidation(document.frm.txtemail)==0)
 	  //  return false;
		}
}//end of function

function distext(val)
{
if(document.frm.dcountry.value=="India")
document.frm.dcity.value=0;

	if(val==1)
	 {
         document.frm.dname.value=document.frm.txtname.value;
         document.frm.daddress.value=document.frm.address.value;
		 if(document.frm.dcountry.value=="India")
         document.frm.dstate.value=document.frm.state1[document.frm.state1.selectedIndex].text;
 		 document.frm.dpin.value=document.frm.txtpin.value;
		 document.frm.dphone.value=document.frm.txtphone.value;
	 }
	 else
	 if(val==2)
	 {
		 document.frm.dname.value="";
		 document.frm.daddress.value="";
		  if(document.frm.dcountry.value=="India")
		 document.frm.dstate.value="";
 		 document.frm.dpin.value="";
		 document.frm.dphone.value="";
	 }
}//distext


function check_number_ent1()
	{
	 var frm=document.frm;
	  frm.totalamount.value="";
	 if(parseInt(frm.noboxes.value)>0)
	    frm.totalamount.value=parseInt(frm.rate.value)*parseInt(frm.noboxes.value);
    }//end of function
	
	
function checkpaylast()
{
if(document.frmshow1.rg2[1].checked==true)
	{
        if(GenValidation( document.frmshow1.ddnumber,'DD Number',",")==0)
  	    return false;
        if(GenValidation( document.frmshow1.ddamount,'DD Amount',",")==0)
  	    return false;
       if(GenValidation( document.frmshow1.dddate,'DD Date',",")==0)
  	    return false;
        if(GenValidation( document.frmshow1.bank,'Bank Name',",")==0)
  	    return false;
   }//end of if
	  if(document.frmshow1.confirm1.checked==false)
	  {
	   alert("confirm Your order(s)");
	   document.frmshow1.confirm1.focus();
	    return false;
	  }
}//end of function



function checkpaylast_ca()
{
     
  if(document.frmshow1.confirm1.checked==false)
	  {
	   alert("confirm the order for Haleem Pack");
	   document.frmshow1.confirm1.focus();
	    return false;
	  }
 if(GenValidation( document.frmshow1.ddnumber,'CA Number',",")==0)
  	return false;
}//end of function




function showmgsddd(val){
var cdiv=document.getElementById('select');
if(cdiv.options[cdiv.selectedIndex].value=='Gati_Employee')
document.getElementById('Gati_Employee').style.display = 'block';
else
document.getElementById('Gati_Employee').style.display = 'none';

if(cdiv.options[cdiv.selectedIndex].value=='Call_Center')
document.getElementById('Gati_Employee2').style.display = 'block';
else
document.getElementById('Gati_Employee2').style.display = 'none';

}//end of function
