
//This is GotoPage() function to open given page
function GotoPage(Pagename) 
{
	location.href=Pagename;
}
//=============================================================================================================================
//THIS FUNCTION POSTS FORM FOR NEXT PAGE ....
//THIS FUNCTION POSTS FORM FOR NEXT PAGE ....
//=============================================================================================================================
function NextPage()
{
   document.frmlist.PageCounter.value = eval(document.frmlist.PageCounter.value) + 1;
   document.frmlist.submit();
}
//===========================================================================================================================
//=============================================================================================================================
//THIS FUNCTION POSTS FORM FOR PREVIOUS PAGE ....
//THIS FUNCTION POSTS FORM FOR PREVIOUS PAGE ....
//=============================================================================================================================
function PrePage()
{
   
	document.frmlist.PageCounter.value = eval(document.frmlist.PageCounter.value) - 1  ;
	document.frmlist.submit();
}

//=============================================================================================================================
//=============================================================================================================================
//THIS FUNCTION POSTS FORM FOR SPECIFIED PAGE NUMBER....
//THIS FUNCTION POSTS FORM FOR SPECIFIED PAGE NUMBER....
//=============================================================================================================================
function NextPageLink(val)
{
    
	document.frmlist.PageCounter.value = eval(val)-1  ;
	document.frmlist.submit();
}
//=============================================================================================================================
//========function SubmitForPage used to submit form ==========================================================================
//=============================================================================================================================
function SubmitForPage(FormName, ControlName, ControlValue, FormAction)
{
	ControlName.value = ControlValue;
	FormName.action = FormAction;
	FormName.submit();
}
//=============================================================================================================================
//THIS FUNCTION POSTS FORM FOR ORDER BY....
//THIS FUNCTION POSTS FORM FOR ORDER BY....
//=============================================================================================================================
function OrderPage(OrderBy)
{
	
	document.frmlist.PageCounter.value = eval(document.frmlist.PageCounter.value);
	
	if(document.frmlist.orderby.value.search(OrderBy)<0)
		document.frmlist.orderby.value = OrderBy;
	else
	{
		if(document.frmlist.orderby.value.search(' desc')<0)
			document.frmlist.orderby.value = OrderBy +' desc';
		else
			document.frmlist.orderby.value = OrderBy;
	}
	document.frmlist.submit();
}
function OrderFunction(orderstr,type)
{
	//alert(orderstr + type);
    document.frmlist.orderby.value = "order by " + orderstr +" " + type ;
	document.frmlist.submit();
}
/**************************************************************************************/
//====================================================================
//REPLACEMENT FUNCTION FOR trim() FUNCTION.....
//REPLACEMENT FUNCTION FOR trim() FUNCTION.....
//====================================================================
//====================================================================
function Trimmer(pVal) { 
    TRs=0; 
    for (i=0; i<pVal.length; i++) 
	{ 
        if (pVal.substr(i,1)==" ") 
		{
			TRs++;
		} 
		else 
			{break;} 
    } 

    TRe=pVal.length-1; 
    for (i=TRe; i>TRs-1;i--)
	{ 
        if (pVal.substr(i,1)==" ") 
		{
			TRe--;
		}
		else 
			{break;} 
    } 

    return (pVal.substr(TRs, TRe-TRs+1)); 
} 

//====================================================================
//====================================================================
//====================================================================
//Trim by Object name.....
//====================================================================
//====================================================================
function TrimObj(theObj) 
{ 
	var pVal = theObj.value;

    var TRs=0; 
    for (var i=0; i<pVal.length; i++) 
	{ 
        if (pVal.substr(i,1)==" ") 
		{
			TRs++;
		} 
		else 
			{break;} 
    } 

   	var TRe=pVal.length-1; 
    for (i=TRe; i>TRs-1;i--)
	{ 
        if (pVal.substr(i,1)==" ") 
		{
			TRe--;
		}
		else 
			{break;} 
    } 

    theObj.value = pVal.substr(TRs, TRe-TRs+1); 
} 
//==================== trimmer() ends ============================
//===============================================================================================================================
//======================================== FUNCTION dateConversion() start =========================================
//=============================================================================================================================
//function for date
//compare date
function DateComparison(val,date1,date2)
{
    //alert("assaasss");
    if(date1=='')
	{
		alert("Please select news date.");
		//val.ndate.focus();
		return false;
	}
    var error=0;
    var d1,d2,m1,m2,y1,y2;
    var fromdate=date1.split('-');
    var todate=date2.split('-'); 
	var ARR_MONTH = ["JAN", "FEB", "MAR", "APR", "MAY", "JUN","JUL", "AUG", "SEP", "OCT", "NOV", "DEC"];
	var FromMonth='';
	var ToMonth='';
    var mon=fromdate[1];
	mon=mon.toUpperCase();
    var mon1=todate[1];
	mon1=mon1.toUpperCase(mon1);

	for(i=0;i<ARR_MONTH.length;i++)
	 {
	   if(mon==ARR_MONTH[i])
	   {
	     FromMonth=i+1;
	   }
	   if(mon1==ARR_MONTH[i])
	   {
	     ToMonth=i+1;
	   }
	 
	 }
	 
   d1=eval(fromdate[0]);
   d2=eval(todate[0]);
   m1=eval(FromMonth);
   m2=eval(ToMonth);
   y1=eval(fromdate[2]);
   y2=eval(todate[2]);

   //return true if second is greater  or equal to first date
   	if (y2 > y1)
	{
   		return true;
	}
	else
	{
		if(y1 > y2)
		{
		 // alert("please enter date less than current date");
		 // document.articlefrm.ndate.focus();
		  //alert(error);
		  error=1;
		//  return false;
			
		}
		else
		{
			if(m2>m1)
			{
				return true;
			}
			else
			{	
				if(m1>m2)
				{
				   // alert("please enter date less than current date");
		           // document.articlefrm.ndate.focus();
					error=1;
					//return false;
				}
				else
				{
					if(d2>=d1)
					{
						return true;
					}
					else
					{
					   // alert("please enter date less than current date");
		                //document.articlefrm.ndate.focus();
					    error=1;
						//return false;
					}

				}

			}

		}

	}  
	if(error==1)
	{
	    alert("Please enter date less than current date.");
		val.focus();
		return false;
	}					
 }
 
//=============================================================================================================================
//=====================================================
//THE FOLLOWING FUNCTION WILL CHECK THE EMAIL ID
//=====================================================
function CheckEmailId(val) {
// Check for a properly formatted email address.
   if ((val.value.length == 0)) {
      return false;
   }

   if (val.value.length != 0) {
     // var emailformat = /^.+@.+\..{2,3}$/;
      var emailformat = /^[^@\s]+@([-a-z0-9]+\.)+([a-z]{2}|com|net|edu|org|gov|mil|int|biz|pro|info|arpa|aero|coop|name|museum|nic|in|co.in|co|inc)$/;
      if (!emailformat.test(val.value))
	   {
         alert("Please enter a valid email-Id");
		 val.value="";
		 val.focus();
		 return false;
      }
   }
   return true;
}
//========================================================

		//=======================================================================\\
		
		//=======CHECK THAT FIELD IS A VALID NUMBER FIELD========================\\
		
		//=======================================================================\\
		
		function isNumberField(theField)
		
		{
		
		  var numFlag=true;
		
		  var countDot=0;
		
		  var ch="";
		
		  var newValue="";
		
		  theField.value=Trimmer(theField.value);
		
		  for(i=0;i<theField.value.length;i++)
		
		   {
		
			 ch=theField.value.charAt(i);
		
			 if(ch==".")
		
			  countDot+=1;
		
			 if ((ch >= "0" && ch <= "9") || (ch == "."))
		
			  {
		
				  if(countDot>1)
		
				  {
		
					//CODE TO ALERT THE USER
		
					//alert("Enter a valid number value");
		
				  //  theField.value="";
		
				  //  return false; 
		
				   //CODE TO REMOVE THE OTHER VALUES EXCEPT NUMBER
		
				   continue;
		
				  }
		
				  else
		
				  {
		
				   newValue+=ch;  //NEW VALUE OF THE NUMBER
		
				  }	
		
			  }
		
			 else
		
			 {
		
					//CODE TO ALERT THE USER
		
				//alert("Enter a valid numeric value");
		
				//theField.value="";
		
				//return false; 
		
				continue;
		
			 } 
		
		   } 
		   //====for correct new value==\
		
		   theField.value=newValue;
		
		}

///////////////////=========================================
		function validDate(dateComponent, displayStr)
		{
			if(dateComponent.value!='')
			{
					
			//========================= validation code =======================================\\
					var Arr_Kishor = ["01", "02", "03", "04", "05", "06","07", "08", "09", "10", "11", "12"];
					var d1, flag=0;
					d1 = dateComponent.value.split("-");	
					if(d1.length < 2)
						flag=1;
					else if(d1[0].length!=2 || d1[1].length!=2  || d1[2].length!=4)
					{
						flag=1;
					}
					else
					{
						
						 flag=1;
						for(i=0;i<Arr_Kishor.length;i++)
						 {
						   if(d1[1]==Arr_Kishor[i])
								 flag=0; 		
						}
						if(d1[0] > 31 || d1[0] < 0)
							flag=1;
						if(d1[2] > 2200 || d1[2] < 1950)
							flag=1;
					}	
					if(flag==1)
						{
							alert("Please enter a valid "  + displayStr + " date  ");
							//dateComponent.value='';
							dateComponent.focus();
							return false;
						}
					return true;
			//========================= END.... validation code =======================================\\		
			}
			return true;
			
		}	
/////////////////////////////////////////
		function checkall(form)

		 {

		  var val=form;

		  var count=0;

		  for(;count <val.elements.length;count++)

			val.elements[count].checked=true;

		 }

		// uncheck all

		function uncheckall(form)

		 {

		  var val=form;

		  var count=0;

		  for(;count <val.elements.length;count++)

			val.elements[count].checked=false;

		 }

function BisEmail(val, req) {
// Check for a properly formatted email address.
   if ((val.value.length == 0) && (req == "R")) {
      alert("This field is required.");
      val.focus();
      val.select();
      return false;
   }
   var email = val.value.toLowerCase();
   if (val.value.length != 0) 
   {
		  var emailformat = /^[^@\s]+@([-a-z0-9]+\.)+([a-z]{2}|com|net|edu|org|gov|mil|int|biz|pro|info|arpa|aero|coop|name|museum)$/;
		//var emailformat = /^.+@.+\..{2,3}$/;
	  	if (!emailformat.test(email)) {
         alert("Please enter a valid email Id.");
         val.focus();
         val.select();
         return false;
      }
   }
	val.value=email;
   return true;
}
//=====================================================================================================//
//............................for date validation......................................................
function isDate(val) 
{
	var IsValid = 0;
	 if (val.value.length != 0) 
     {
        var longform =  /^[0-9]{2}-[0-1][0-9]-[1-9][0-9]{3}$/;
        if(longform.test(val.value))
		  {
		  		var DateArr = val.value.split("-");
				if(DateArr[0]> 31 || DateArr[1] >12)
					IsValid = 0;
				else
					IsValid = 1;
          }
		
				  if(IsValid == 0)
				  {
				  	
					  val.value='';
					  alert("Please Enter Date in a Valid Format");
					 val.focus();
					 return false;
				  }
   }
   
   return true;
}
//==============================================================================================
//..........................function for validation for only alphabetic values..................
function isAlpha(val) 
{
  if (val.value.length != 0)
   {
       for (i = 0; i < val.value.length; i++)
	   {
		   var ch = val.value.charAt(i);
		   if ((ch >= "A" && ch <= "Z") || (ch >= "a" && ch <= "z") || (ch == " ") || (ch == ".") || (ch == "&")|| (ch == "/")|| (ch == "'")|| (ch == '"') || (ch == ","))
		   {
              continue;
            } 
		   else
		   {
		    val.value='';
            alert("Please enter valid value.");
		    val.focus();
            return false;
           }
      }
  }

   return true;
}
//======================================================================================================
/*function ifdelete(val)
{
	
	if(confirm("Delete this member?"))
	{
		document.frmlist.member.value=val;
		document.frmlist.submit();
	}
}*/

//...............................validation function for only numeric values..............................

function isNum(val)
 {
    if (val.value.length != 0) 
    {
      for (i = 0; i < val.value.length; i++) 
	      {
              var ch = val.value.charAt(i);
              if ((ch >= "0" && ch <= "9") || (ch == ".") || (ch == "-")) 
		      {
                continue;
              } 
		      else
		      { 
		      val.value='';
              alert("Please enter only numbers.");
			  val.focus();
              return false;
             }
         }
   }
 
}

//============This function is used for deleting any consultant=======================================
function ifdelete(val)
{
  if(confirm("Delete this consultant?"))
	{
		document.getElementById('member').value=val;
		document.forms[0].submit();
	}
}
//============This function is used for deleting any supplier=======================================
function ifdel(val)
{
  if(confirm("Delete this supplier?"))
	{
		document.getElementById('member').value=val;
		document.forms[0].submit();
	}
}
