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,NoItems) //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=NoItems;
						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
 }




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) != null)
	{
		 if (document.getElementById(obj).value.replace(/^\s+|\s+$/,'')=='')
			{
				return false;
			}
		else
			{
				 return true;
			}
	}
	else
	{
		return false;
	}
     
 }
 
 //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;
					alert(count)
				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.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 setPopUpPoistion(popUpId)
{
   var divHeight = 300;
   var divWidth = 200;
   
   if(parseInt(document.getElementById(popUpId).style.heigh) > 0)
   {
        divHeight = parseInt(document.getElementById(popUpId).style.heigh);
   }
        
   if(parseInt(document.getElementById(popUpId).style.width) > 0)
   {
        divWidth = parseInt(document.getElementById(popUpId).style.width);
   }
        
   document.getElementById(popUpId).style.top = ((screen.availHeight - divHeight)/2 + document.documentElement.scrollTop) + "px";
   document.getElementById(popUpId).style.left = ((screen.availWidth - divWidth)/2 + document.documentElement.scrollLeft) + "px";
}