//ajax code
		var Xmlhttp; 
		var xmlDoc;
			
	function createXmlHttp()
		{
         var moz = (typeof document.implementation != 'undefined') && (typeof 
         document.implementation.createDocument != 'undefined');
         if (moz)
          {
          Xmlhttp = new XMLHttpRequest();
          }
	    else // for Ie
	    {
	   try
	     {
		 Xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	     }
	  catch(e)
	    {
		try
		{
			Xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		} 
		catch(oc)
		{
			Xmlhttp = null;
		}
	    }
	   }  //end else;	
		}// end createXmlhttp;
				
		

  
 function GetXMLHTTP() //Creating the XMLHTTP object for AJAx functionality
{
	if(document.all)
	{
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP")
	}
	else
	{
	 //   alert('in fire fox')
		xmlhttp = new XMLHttpRequest();
		//alert('after http request object creation in fire fox')
	}
	return xmlhttp
}				

function OnFocus()//for text box on foucs
{onfocus="javascript:this.style.backgroundColor='#F3F6FA'";}

function OnBlur()//for text box if focus is lost
{onblur="javascript:this.style.backgroundColor=''";}

function GETMETHOD(xmlobj,URL,handleresponse)  //here xmlobj is the xmlhttp object,handleresponse is the function to be called to handle the returned data from the server
{                                              //URL is the URL  
	if(xmlobj != null)
		{
		  if(document.all)
		  {
			xmlobj.open("POST", URL, true);
			xmlobj.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
		  }
		  else
		    {xmlobj.open("GET", URL, true); }	
		    
			xmlobj.onreadystatechange = handleresponse;
			xmlobj.send(null);
		}		

}

 
/*
	For Assigning the retirved data to the Browser

*/


 function HttpResponseHandler(xmlobj,objError,GridLabel,Pages) //xmlhttp is the XML object,Error Label Name,object to which the data is to be binded
		{
			if (xmlobj.readyState == 4)
			{  	  
				if(xmlobj.responseText.indexOf('notfound')==0)
					{
						document.getElementById(objError).innerHTML='Sorry! You do not have any category items for this category.';
						document.getElementById(GridLabel).innerHTML=''; 
					}
				else if(xmlobj.responseText.indexOf('deleteerror')==0)
					{
						document.getElementById(objError).innerHTML='There was an error in the deletion process.';
					}	
				else if(xmlobj.responseText!='')
					{ 
						document.getElementById(GridLabel).innerHTML=xmlobj.responseText;
						document.getElementById(objError).innerHTML='' //Once data is displayed
					}
				//if the Session Expires
				else if(xmlobj.responseText.indexOf('SessionExpire')==0)
						{  if (Pages=='Admin')
								{window.location='Signout.aspx';}
							else if(Pages=='User')
						         {window.location='../Signout.aspx';} 		
							
						}
				else
					{
						//document.getElementById(objError).innerHTML='There was a error in the process.';
						document.getElementById(GridLabel).innerHTML=''
					}
								   		
			}
		}



/*
Table Check/UnCheck funcationalites
*/
function Check_UncheckAll() //Header
{ 
	//debugger
	var intLoop=0 ;
	while (document.getElementById('chk_' + intLoop)!=null)
			{document.getElementById('chk_' + intLoop).checked = document.getElementById('chk_header').checked; intLoop+=1;}
	}
	
/*
 For CHild items
*/

function Check_UncheckHeader() //Header
	{

		var intLoop = 0;
		var intCount = 0;
		var rowCount = 0;
		
		while (document.getElementById('chk_' + intLoop)!=null)
		{
				if(document.getElementById("chk_" + intLoop).checked)
				{intCount++;}
				rowCount++;
				intLoop+=1;
		}
		if(intCount == (rowCount))
		document.getElementById("chk_header").checked = true;
		else
		{ 
		document.getElementById("chk_header").checked = false;
		//alert("bye");
		}
		return false;
	}
                
                
	
//Delete funcationality For the Table
 function GETIDS()
 {
	var intLoop=0;
	var strids='0';
	while (document.getElementById('chk_' + intLoop)!=null)
		{
			if(document.getElementById('chk_' + intLoop).checked)
				{
				if(document.getElementById('lblId_' + intLoop) !=null)
					{strids= document.getElementById('lblId_' + intLoop).innerHTML + ',' + strids; }
				}
			
			intLoop+=1;   
		}
	return strids; //string format of ids
 }

//for opening the div helptag
function Open(obj)
{document.getElementById(obj).style.display='';}

//for opening the div helptag
function Close(obj)
{document.getElementById(obj).style.display='none';}

/*function TxtEntered(obj)  
 {
	if(document.getElementById(obj) != null)
	{
		 if (document.getElementById(obj).value.replace(/^\s+|\s+$/,'')=='')
			{
				return false;
			}
		else
			{
				 return true;
			}
	}
	else
	{
		return false;
	}
     
 }*/ 


///for back button navigation  --ganesh
function NavigateBack()
{
		if(window.location.search.indexOf('Right')>-1)
		{
			//document.getElementById('btnback').style.display='none';
		}

}

function ValidatePhone(p1,p2,p3)
{
	var valid=true
	if((p1.value.length!=3)||(p2.value.length!=3)||(p3.value.length!=4))
	 {
		valid=false
	 }
	 var i1=parseInt(p1.value)
	 var i2=parseInt(p1.value)
	 var i3=parseInt(p1.value)
	 if(!(i1 && i2 && i3))
	 {
		valid=false
	 }
	 return valid
} 

function ValidateZip(z)
{
	
	var valid=true
	if( (z.length!=5)&& (z.length!=6) )
	{
		valid=false
	}
	var i= parseInt(z)
	if(!i)
	{
		valid=false
	}
	return valid

}

//verifying the input whether it is ''
function TxtEntered(obj)
 {
  if (document.getElementById(obj).value.replace(/^\s+|\s+$/, '')=='')
     {return false;}
  else return true;   
     
 }
 
 //Validating the phone number length should be 10 to 12 digits
 
 function ValidatePhone(obj)
 {
	if(parseInt(document.getElementById(obj).value.replace(/^\s+|\s+$/, '').length) < 10)
		{return false;}
  else if(parseInt(document.getElementById(obj).value.replace(/^\s+|\s+$/, '').length) > 12)
		{return false;}	
 else return true;		
 
 
 }
 
 
  //if a checkbox group is selected
	function ChkSelected(obj)
	{ 
	   try
	     {
				var bo=false;
				
				var count=document.getElementById(obj).options.length;
				
				var i;
				for (i=0;i<=count-1;i++)
					{
					if(document.getElementById(obj+'_'+i).checked)
						{bo=true;return bo;}
					}
					return bo
		}
	  catch(err)
		   					{
		   						return;
		   					} 
				
	}
 
 function ComboSelected(obj)
 {
  if (document.getElementById(obj).value.replace(/^\s+|\s+$/, '')==-1)
     {return false}
  else return true   
     
 }

 //if check box is checked
 function ChkChecked(obj)
 {
  if (document.getElementById(obj).checked)
     {return true}
  else return false   
     
 }

	
function ExpDate(textbox_id)
{
	/*
	var DateVal = window.showModalDialog('../Includes/calendar.htm','Calendar','dialogwidth:275px;dialogheight:308px;center:yes')
	if (typeof(DateVal)=="string")
	{	
	
		document.getElementById(obj).value = DateVal; //date of birth
	}
	*/
	
				var cal1 = new calendar2(document.getElementById(textbox_id));
				cal1.year_scroll = true;
				cal1.time_comp = false;
				cal1.popup();
}
			
function ValidateEmail(mail)
	{
	var email
	var splitted = new Array()
	var valid=true
	email =Trim(mail);
		
		if (email.replace(/^\s+|\s+$/, '')=='')
			 {return false}
						   
	     splitted = email.match("^(.+)@(.+)$");

		if(splitted == null) 
			{return false}
		if (splitted.length==3)
		  {
			
			if(splitted[1]!= null)
				{
						var regexp_user=/^\'?[\w-_\.]*\'?$/;
						
						if(splitted[1].match(regexp_user) == null) 
							{valid=false}
				}

			if(splitted[2]!= null)
				{
						var regexp_domain=/^[\w-\.]*\.[A-Za-z]{2,4}$/;
							if(splitted[2].match(regexp_domain) == null) 
							{
									var regexp_ip =/^\[\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\]$/;
										if(splitted[2].match(regexp_ip) == null)
	    									{valid=false}
							}
						
				}
		}
		else {valid=false;}	
	return valid
}




/*function Trim(s)
{
	while(s.substring(0,1)==' ')
	{
		s=s.substring(1,s.length);
	}
	return s
}*/

function ValidateCreditCard(cc)
{
	
	var valid=true
	if(cc.value.length!=16)
	{
		valid=false
	}
	var i= parseInt(cc.value)
	if(!i)
	{
		valid=false
	}
	return valid

}

/*function ValidateEmail(mail)
{

	var valid=true
	var v1=mail.split('@')
	if(v1.length!=2)

	{
		valid=false
	}
	else
	{ 
		var v2=v1[1].split('.')
		if(v2.length!=2)
		{
			valid=false
		} 
	}
	
	return valid

}*/
//For setting the Focus
function Focus(obj)
		{
			if(document.getElementById(obj)!=null)
				{document.getElementById(obj).focus();}
		}
		
		




function calonkey(e)
			{
				  var Keyval;
					  Keyval=window.event?window.event.keyCode:e.which;
			
				if (Keyval == 13)
				{
					//cal(obj)
				}
				else 
				{				
					if (Keyval == 39)
					{window.event?window.event.keyCode=null:e.preventDefault();}					
				}
			}
			
function calonkeyInt32(e)
			{
				//according to the browser
			  var Keyval;
			  //alert(e.which)
			  Keyval=window.event?window.event.keyCode:e.which;
			   
			  			
				if ((Keyval == 13)||(Keyval == 8))
				{//cal(obj)
				}
				else if (Keyval == 39)
					{window.event?window.event.keyCode=null:e.preventDefault();}	
				else
				{
					if (!((Keyval >= 48) && (Keyval <= 57))) 
					{window.event?window.event.keyCode = null:e.preventDefault();}
				}				
			}	

function AllowFloat(e,obj)
	{
		  var Keyval;
			  Keyval=window.event?window.event.keyCode:e.which;
		if (Keyval == 13)
		{
			//do nothing
		}
		else
		{	
			if (!((Keyval >= 48) && (Keyval <= 57))) 
			{
				if (!(Keyval == 46))
				{window.event?window.event.keyCode = null:e.preventDefault();}
				else if (Keyval == 46)
				{
					if (document.getElementById(obj).value.lastIndexOf(".") > -1)
					{window.event?window.event.keyCode = null:e.preventDefault();}
				}
			}
		}
	}



function calonkeyDouble(e)
{
	 var Keyval;
		Keyval=window.event?window.event.keyCode:e.which;
		
	if (Keyval == 13)
	{
		//cal(obj)
	}
	else if (Keyval == 39)
		{window.event?window.event.keyCode = null:e.preventDefault();}	
	else
	{
		if (!((Keyval >= 48) && (Keyval <= 57))) 
		{
			if (!(Keyval == 46))
			{window.event?window.event.keyCode = null:e.preventDefault();}
			else if (Keyval == 46)
			{
				/*if (document.getElementById(obj).value.lastIndexOf(".") > 0)
				{
					window.event.keyCode = null;
				}*/
			}
		}
	}				
}	
			
function calonkeydate(e)
{
	 var Keyval;
		Keyval=window.event?window.event.keyCode:e.which;
		
	if (Keyval == 13 || Keyval == 47)
	{
		/*if(txtvalue.lastIndexOf("/") > 6)
		{
			window.event.keyCode = null
		}*/
	}
	else if (!Keyval == 32)
		{window.event?window.event.keyCode = null:e.preventDefault();}	
	else
	{	
		if (!((Keyval >= 48) && (Keyval <= 58))) 
		{window.event?window.event.keyCode = null:e.preventDefault();}
	}
}

function calonkeydatetime(e)
{
	 var Keyval;
		Keyval=window.event?window.event.keyCode:e.which;
		
	if (Keyval == 13)
	{window.event?window.event.keyCode = null:e.preventDefault();}
	else
	{
		 if(Keyval == 32)
		{
			//accept :
		}
		else
		{
			 if(Keyval == 47)
			{
				//accept '/'
			}
			else
			{
				if (!((Keyval >= 48) && (Keyval <= 58)))
				{window.event?window.event.keyCode = null:e.preventDefault();//accept only numeric
				}
			}	
		}
	}
	
}

function Trim(TRIM_VALUE){
if(TRIM_VALUE == null) TRIM_VALUE = "";
if(TRIM_VALUE.length < 1){
return"";
}
TRIM_VALUE = RTrim(TRIM_VALUE);
TRIM_VALUE = LTrim(TRIM_VALUE);
if(TRIM_VALUE==""){
return "";
}
else{
return TRIM_VALUE;
}
} //End Function

function RTrim(VALUE){
var w_space = String.fromCharCode(32);
var v_length = VALUE.length;
var strTemp = "";
if(v_length < 0){
return"";
}
var iTemp = v_length -1;

while(iTemp > -1){
if(VALUE.charAt(iTemp) == w_space){
}
else{
strTemp = VALUE.substring(0,iTemp +1);
break;
}
iTemp = iTemp-1;

} //End While
return strTemp;

} //End Function

function LTrim(VALUE){
var w_space = String.fromCharCode(32);
if(v_length < 1){
return"";
}
var v_length = VALUE.length;
var strTemp = "";

var iTemp = 0;

while(iTemp < v_length){
if(VALUE.charAt(iTemp) == w_space){
}
else{
strTemp = VALUE.substring(iTemp,v_length);
break;
}
iTemp = iTemp + 1;
} //End While
return strTemp;
} //End Function

/*
function CheckAll(dgid)
	{
		var intLoop;
		var rowCount = <%= dgid.Items.Count %>;
		for(intLoop = 3; intLoop <= rowCount + 2; intLoop++)
		{
			document.getElementById("dgid__ctl" + intLoop + "_chkDelete").checked = true;
		}
		return false;
	}	
				
function UnCheckAll(dgid)
	{
		var intLoop;
		var rowCount = <%= dgid.Items.Count %>;
		for(intLoop = 3; intLoop <= rowCount + 2; intLoop++)
		{
			document.getElementById("dgid__ctl" + intLoop + "_chkDelete").checked = false;
		}
		return false;
	}*/
	
	
	//debugger
	
	 function TextCount(obj,span,E)
	   {
			//alert('innerHTML:  '+document.getElementById(obj).innerHTML +'  value:'+ document.getElementById(obj).value)
		 try
		   {
				if(document.getElementById(obj).value.length > 300)
				{
					
					if(window.event)
						{
						if((window.event.keyCode !=32)||(window.event.keyCode !=127))
							{window.event.keyCode=null}
						}
					else if ((E.which !=32) || (E.which !=127))
						{ E.preventDefault();//alert(E.which)
						}	 
					
				}
				document.getElementById(span).innerHTML= 'Number of characters:&nbsp;<b>' + document.getElementById(obj).value.length + '</b> of 300';
		 }
		 catch(ex) //for functional keys
		  {}			 
		
	   }			
	   
	   
	   
	   
	   //Validations in ajis
	   
	   function removeLeadingAndTrailingChar (inputString, removeChar) 
{
	var returnString = inputString;
	if (removeChar.length)
	{
		while(''+returnString.charAt(0)==removeChar)
		{
			returnString=returnString.substring(1,returnString.length);
		}
		while(''+returnString.charAt(returnString.length-1)==removeChar)
		{
			returnString=returnString.substring(0,returnString.length-1);
		}
	}
	return returnString;
}

function trim(str)
{
	return removeLeadingAndTrailingChar (str, " ");
}

function NotEmpty(source, arguments)
{
    var idr = source.id.replace("cv_", "rdo");
    var b = document.getElementById('' + idr + '').checked;
    
    if (b)
    {
        if (trim(arguments.Value) == "" )
        {
            arguments.IsValid = false;
        }
        else
        {
            arguments.IsValid = true;
        }
    }
    else 
    {
        arguments.IsValid = true;
    }
}

function NotEmptyfax(source, arguments)
{
    var nopat=/^\d+$/;
    var phno=arguments.Value;
    var idr = source.id
    var text1=document.getElementById(idr.replace("cv_", "txt") +"Part1").value;
    var text2=document.getElementById(idr.replace("cv_", "txt") +"Part2").value;

    var matchArray = phno.match(nopat);
    var matcharray2=text1.match(nopat);
    var matcharray3=text2.match(nopat);
    if (arguments.Value != "" && text1 != "" && text2 != "")
    {
        if (matchArray != null && matcharray2!= null && matcharray3 !=null) 
        {
            if (arguments.Value.length == 4 && text1.length ==3 && text2.length ==3)
            {
                arguments.IsValid = true;
            }
            else
            {
                arguments.IsValid=false;
            }
        }
        else
        {
            arguments.IsValid=false;
        }
    }
    else if(arguments.Value == "" && text1 == "" && text2 == "") 
    {
        arguments.IsValid=true;
    }
    else
    {
        arguments.IsValid=false;
    }
}

function ShowViewPage(id,showall)
{
    window.open("ViewAJIS.aspx?showall=" + showall + "&jobid=" + id, "ViewAJIS", "width=800,height=600,left=0,top=0,titlebar=0,location=0,resizable=1,directories=0,status=1,scrollbars=1")
}

	   
	   
	   
	   
	   
	   
	   