function trimchar(pastr){

	var lenstr = pastr.length;

	for(var i = 0 ; pastr.charAt(i) == " "; i++);

	for(var j = pastr.length - 1; pastr.charAt(j)== " "; j--);

	j++;

	if (i > j)

		pastr = "";

	else

		pastr = pastr.substring(i,j);

	return pastr;

}



//For checking Null values



function isNull(aStr)

{

	var index;		

	for (index=0; index < aStr.length; index++)

		if (aStr.charAt(index) != ' ')

			return false;

	return true;

}

	

	//For checking invalid E-Mail address

var reEmail=/^[0-9a-zA-Z_\.-]+\@[0-9a-zA-Z_\.-]+\.[0-9a-zA-Z_\.-]+$/



function checkEmail(obj){

 	if(!reEmail.test(obj))

	{

		return false;

	}

	return true;

	

	

	

}

	function checkphone(val)

	{

	

	str = "^0";	

	var reg = new RegExp(str);

		return reg.test(val);

	}

	

	

	

	

	// For checking and allowing only certain numeric values for Quantity

	function isNumeric(val,allow_dec,allow_neg)

	{

		var str = "";

		if(allow_neg)         //value can be negative

		{

			str += "^-";

		}		

		if(allow_dec)         //value can be decimal 

		{

			str += "[0-9]{1,}\.{0,1}"; 

		}	

		str += "^[0-9]{1,}$";				

		var reg = new RegExp(str);

		return reg.test(val);

	}

	function validateEmail(email)
{
	if(email=="") return false;

	badstuff=";:/,'\"\\";

	for(i=0;i<badstuff.length;i++)
	{
		badcheck=badstuff.charAt(i);
		if(email.indexOf(badcheck,0)!=-1)
		return false;
	}//for

	posofAtsign=email.indexOf("@",1);
	if(posofAtsign==-1)
	return false;

	if(email.indexOf("@",posofAtsign+1) !=-1)
	return false;

	posofPeriod=email.indexOf(".",posofAtsign)
	if(posofPeriod==-1) return false;

	if(posofPeriod+2 > email.length)
	return false;

	return true;
}//validateEmail()


function isAlphaNumeric(varData)

{

	varRegExp = new RegExp("^[A-Za-z0-9_]+$");

	if(!varRegExp.test(varData))

	{

		return true

	}	

	return false

}

function IsValidImageName(strVal)

{

	nNoOfArguments = IsValidImageName.arguments.length;



	//if parameter is not supplied

	if(nNoOfArguments < 1)

	{

		return false;

	}

		

	//valid characters a supplied string value can have

	var sValidChars = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_-";

	

	strVal = new String(strVal);	//convert the value to a string object

	

	var bReturn = true	

	var i = new Number(0);

	while ((bReturn) && (i < strVal.length))

	{

		bReturn = (sValidChars.indexOf(strVal.charAt(i)) >= 0)

		i++

	}

	return (bReturn);	

}



/* 

	Date Should be in MM/DD/YY

	date 1 > date 2 return 1

	date 1 < date 2 return -1

	date 1 = date 2 return 0



*/



function compareDates(dt1,dt2)

{

	var datepart1 = dt1.split("/");

	var datepart2 = dt2.split("/");

	

	for(i=0;i<datepart1.length;i++)

	{

		datepart1[i] = parseInt(parseFloat(datepart1[i]));

		datepart2[i] = parseInt(parseFloat(datepart2[i]));		

	}	

	

	if(datepart1[2] > datepart2[2])

		return 1;

	else if(datepart1[2] < datepart2[2])	 

		return -1;

	else if(datepart2[2] == datepart1[2])	 	

	{

		if(datepart1[0] > datepart2[0])

			return 1;

		else if(datepart1[0] < datepart2[0])	

			return -1;

		else if(datepart1[0] == datepart2[0])					 

		{

			if(datepart1[1] > datepart2[1])

				return 1;

			else if(datepart1[1] < datepart2[1])	

				return -1;			

		}

	}

		return 0;	

}

function LeapYear(intYear) {
	if (intYear % 100 == 0) {
		if (intYear % 400 == 0) { return true; }
	}
	else { 
		if ((intYear % 4) == 0) { return true; }
	}
	return false;
}


/* Date format mm/dd/yyyy */
function checkDate(dt)
{
	var reg = new RegExp("[0-9]{1,2}/[0-9]{1,2}/[0-9]{4}$");
	if(reg.test(dt))
	{
		var datepart = dt.split("/");
		for(i=0;i<datepart.length;i++)
			datepart[i] = parseInt(parseFloat(datepart[i]));
		if(datepart[1] > 31 || datepart[0] > 12)
			return false;
		else if((datepart[0] == 4 || datepart[0] == 6 || datepart[0] == 9 || datepart[0] == 11) && datepart[1] == 31)
			return false;	
		else if(datepart[0] == 2)
		{
			if(datepart[1] > 29)
				return false;
			if(!LeapYear(datepart[2]) && datepart[1] == 29)
				return false;
		}
		return true;						
	}
	return false;			
}
		
/*  
     Dates accepted in mm/dd/yyyy format
     Return Code          Condition
	 -------------------------------
	    -1              dt1 less than dt2
	     0              dt1 equal to dt2
  	     1     	        dt1 greater than dt2		        
*/

function compareDates(dt1,dt2)
{
	var datepart1 = dt1.split("/");
	var datepart2 = dt2.split("/");
		
	for(i=0;i<datepart1.length;i++)
	{
		datepart1[i] = parseInt(parseFloat(datepart1[i]));
		datepart2[i] = parseInt(parseFloat(datepart2[i]));		
	}	
	
	if(datepart1[2] > datepart2[2])
		return 1;
	else if(datepart1[2] < datepart2[2])	 
		return -1;
	else if(datepart2[2] == datepart1[2])	 	
	{
		if(datepart1[0] > datepart2[0])
			return 1;
		else if(datepart1[0] < datepart2[0])	
			return -1;
		else if(datepart1[0] == datepart2[0])					 
		{
			if(datepart1[1] > datepart2[1])
				return 1;
			else if(datepart1[1] < datepart2[1])	
				return -1;			
		}
	}
	return 0;	
}


function changeDateFormat(dt,from_format,to_format)
{
	var converted_date  = new Array(3);		
	var datepart        = dt.split("/");        
	var from_formatpart = from_format.split("/");
	var to_formatpart   = to_format.split("/");
	for(i=0;i<3;i++)
	{
		for(j=0;j<3;j++)
		{
			if(to_formatpart[j] == from_formatpart[i])  	
			{
				converted_date[j] = datepart[i];  			
				break;
			}
		}
	}	
	return (converted_date[0]+"/"+converted_date[1]+"/"+converted_date[2]);	
}function isEmpty(val)
{   
	for(var i=0;i<val.length;i++)
	{
		if(val.charAt(i) != ' ')
		{
			return false;
		}
	}
	return true;
}

function isChecked(field) 
	{
		var boxes = document.getElementsByName(field);		
	
		for( var i=0; i < boxes.length; i++ ) 
		{
			if( boxes[i].checked == true) 
			{
				return true;
				
			}
				
			
		}
		
		return (false);
	}

/***********************************************
* Cool DHTML tooltip script II- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
***********************************************/

var offsetfromcursorX=12 //Customize x offset of tooltip
var offsetfromcursorY=10 //Customize y offset of tooltip

var offsetdivfrompointerX=10 //Customize x offset of tooltip DIV relative to pointer image
var offsetdivfrompointerY=14 //Customize y offset of tooltip DIV relative to pointer image. Tip: Set it to (height_of_pointer_image-1).

document.write('<div id="dhtmltooltip"></div>') //write out tooltip DIV
document.write('') //write out pointer image

var ie=document.all
var ns6=document.getElementById && !document.all
var enabletip=false
if (ie||ns6)
var tipobj=document.all? document.all["dhtmltooltip"] : document.getElementById? document.getElementById("dhtmltooltip") : ""

var pointerobj=document.all? document.all["dhtmlpointer"] : document.getElementById? document.getElementById("dhtmlpointer") : ""

function ietruebody(){
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function ddrivetip(thetext, thewidth, thecolor){
if (ns6||ie){
if (typeof thewidth!="undefined") tipobj.style.width=thewidth+"px"
if (typeof thecolor!="undefined" && thecolor!="") tipobj.style.backgroundColor=thecolor
tipobj.innerHTML=thetext
enabletip=true
return false
}
}

function positiontip(e){
if (enabletip){
var nondefaultpos=false
var curX=(ns6)?e.pageX : event.clientX+ietruebody().scrollLeft;
var curY=(ns6)?e.pageY : event.clientY+ietruebody().scrollTop;
//Find out how close the mouse is to the corner of the window
var winwidth=ie&&!window.opera? ietruebody().clientWidth : window.innerWidth-20
var winheight=ie&&!window.opera? ietruebody().clientHeight : window.innerHeight-20

var rightedge=ie&&!window.opera? winwidth-event.clientX-offsetfromcursorX : winwidth-e.clientX-offsetfromcursorX
var bottomedge=ie&&!window.opera? winheight-event.clientY-offsetfromcursorY : winheight-e.clientY-offsetfromcursorY

var leftedge=(offsetfromcursorX<0)? offsetfromcursorX*(-1) : -1000

//if the horizontal distance isn't enough to accomodate the width of the context menu
if (rightedge<tipobj.offsetWidth){
//move the horizontal position of the menu to the left by it's width
tipobj.style.left=curX-tipobj.offsetWidth+"px"
nondefaultpos=true
}
else if (curX<leftedge)
tipobj.style.left="5px"
else{
//position the horizontal position of the menu where the mouse is positioned
tipobj.style.left=curX+offsetfromcursorX-offsetdivfrompointerX+"px"
pointerobj.style.left=curX+offsetfromcursorX+"px"
}

//same concept with the vertical position
if (bottomedge<tipobj.offsetHeight){
tipobj.style.top=curY-tipobj.offsetHeight-offsetfromcursorY+"px"
nondefaultpos=true
}
else{
tipobj.style.top=curY+offsetfromcursorY+offsetdivfrompointerY+"px"
pointerobj.style.top=curY+offsetfromcursorY+"px"
}
tipobj.style.visibility="visible"
if (!nondefaultpos)
pointerobj.style.visibility="visible"
else
pointerobj.style.visibility="hidden"
}
}

function hideddrivetip(){
if (ns6||ie){
enabletip=false
tipobj.style.visibility="hidden"
pointerobj.style.visibility="hidden"
tipobj.style.left="-1000px"
tipobj.style.backgroundColor=''
tipobj.style.width=''
}
}

document.onmousemove=positiontip

