function IsNumeric(sText)
{
	var ValidChars = "0123456789";
	var IsNumber=true;
	var Char;
	for (i = 0; i < sText.length && IsNumber == true; i++)
	{
		Char = sText.charAt(i);
		if (ValidChars.indexOf(Char) == -1)
		{
			IsNumber = false;
		}
	}
	return IsNumber;
}
function checkEmail(email)
{
	email
	if(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email))
	{
		return true;
	}	
	alert( email + " E-mail Address in not valid.")
	return false;
}
function changeopacity(div, opacity)
{
	if (navigator.appName.indexOf("Netscape")!=-1 && parseInt(navigator.appVersion)>=5)
		document.getElementById(div).style.MozOpacity=opacity/100
	else if (navigator.appName.indexOf("Microsoft")!= -1 && parseInt(navigator.appVersion)>=4)
		document.getElementById(div).filters.alpha.opacity=opacity
}

function colorchange(div)
{
	var fadepost = new Fx.Tween($(div),{ duration: 1200 });
	fadepost.start('background-color', '#FFF');
}

function colorchangeprof(div,color){
	var fadepost = new Fx.Tween($(div),{ duration: 1200 });
	fadepost.start('background-color', color);	
}
function fadediv(div)
{
	var slide = new Fx.Slide($(div),{ duration: 1200 });
	slide.slideOut();
}
function fadeout(div)
{
	$(div).fade(1,0);
}
function showErrMsg(divId,rtrn_msg)
{
	$(divId).fade(0,1);
	$(divId).set('text',rtrn_msg);
	setTimeout("fadeout('"+divId+"');",3000);	
}
function showDivMsg(obj_nam,rtrn_msg,divId)
{
	document.getElementById(obj_nam).focus();
	showErrMsg(divId,rtrn_msg);
}
function getPageSizeWithScroll()
{
	if (window.innerHeight && window.scrollMaxY) 
	{// Firefox
		yWithScroll = window.innerHeight + window.scrollMaxY;
		xWithScroll = window.innerWidth + window.scrollMaxX;
	}
	else if (document.body.scrollHeight > document.body.offsetHeight)
	{ // all but Explorer Mac
		yWithScroll = document.body.scrollHeight;
		xWithScroll = document.body.scrollWidth;
	} 
	else 
	{ // works in Explorer 6 Strict, Mozilla (not FF) and Safari
		yWithScroll = document.body.offsetHeight;
		xWithScroll = document.body.offsetWidth;
	}	
	if(xWithScroll<document.documentElement.clientWidth)
		xWithScroll=document.documentElement.clientWidth
	if(yWithScroll<document.documentElement.clientHeight)	
		yWithScroll = document.documentElement.clientHeight;
	
	arrayPageSizeWithScroll = new Array(xWithScroll,yWithScroll);
	return arrayPageSizeWithScroll;
}

function showPopup(curobj,div,grey,x,y)
{
	var el1 = $('greybg');
	var el2 = $(div);
	var obj =  document.getElementById(div);		

	if(grey=='1')
		el1.hide;
		
	el2.hide;
	
	if(grey=='1')
		el1.fade(0,0.8);
	
	el2.fade(0,1);
	
	var pagesize=getPageSizeWithScroll();
	document.getElementById('greybg').style.height=pagesize[1]+'px';

	var xpos=getposOffset(curobj,"left",x,"add")+((typeof opt_position!="undefined" && opt_position.indexOf("right")!=-1)? -(subobj.offsetWidth-curobj.offsetWidth):0);
	var ypos=getposOffset(curobj, "top",y,"add")+((typeof opt_position!="undefined" && opt_position.indexOf("bottom")!=-1)? curobj.offsetHeight : 0);

	obj.style.left=xpos+"px";
	obj.style.top=ypos+"px";	
	
	return false;
}
function hidePopup(div,grey)
{
	var el1 = $('greybg');
	var el2 = $(div);
	
	if(grey=='1')
		el1.fade(0);
				
	el2.fade(0);
}
function getposOffset(overlay, offsettype,adjustoffset,sign)
{
	var totaloffset=(offsettype=="left")? overlay.offsetLeft : overlay.offsetTop;
	var parentEl=overlay.offsetParent;
	while (parentEl!=null)
	{
		totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
		parentEl=parentEl.offsetParent;
	}
	if(sign=="minus")
	{	  
		totaloffset = totaloffset - adjustoffset;
	}
	else
	{
		totaloffset = totaloffset + adjustoffset;
	}
	return totaloffset;
}
function stripslashes(str) 
{
	str=str.replace(/\\'/g,'\'');
	str=str.replace(/\\"/g,'"');
	str=str.replace(/\\\\/g,'\\');
	str=str.replace(/\\0/g,'\0');
	return str;
}
function URLEncode (clearString) 
{
	var output = '';
	var x = 0;
	clearString = clearString.toString();
	var regex = /(^[a-zA-Z0-9_.]*)/;
	while (x < clearString.length) 
	{
		var match = regex.exec(clearString.substr(x));
		if (match != null && match.length > 1 && match[1] != '')
		{
			output += match[1];
			x += match[1].length;
		} 
		else 
		{
			if (clearString[x] == ' ')
				output += '+';
			else 
			{
				var charCode = clearString.charCodeAt(x);
				var hexVal = charCode.toString(16);
				output += '%' + hexVal.toUpperCase();
			}
			x++;
		}
	}
	return output;
}
function convertCharsToEntities(s)
{
	for(var i=0;i<s.length;i++)
	{
		c = s.charCodeAt(i);
		if(c>255)
		{
			var re = new RegExp(s.charAt(i));
			s = s.replace(re, "&#"+c+";");
		}
	}
	return(s);
}
	
function strcount(div1,div2)
{
	document.getElementById(div1).innerHTML=document.getElementById(div2).value.length;
}

function Trim(str)
{	
	if(str == 'undefined')
	{
		return "";
	}
	else
	{
		while(str.charAt(0) == (" "))
		{
			str = str.substring(1);
		}
		while(str.charAt(str.length-1) == " ")
		{
			str = str.substring(0,str.length-1);
		}
		if(str == "")
			return "";
	}
	return str;
}
function Chk_Empty(obj_nam,rtrn_msg,divId)
{
	var x=Trim(document.getElementById(obj_nam).value);    
	if(!x)	    
		showDivMsg(obj_nam,rtrn_msg,divId);
	else
		return true;
}
function Chk_Select(obj_nam,rtrn_msg,divId)
{
	var x=Trim(document.getElementById(obj_nam).value);   
	if(x == '' || x == 0 || x == -1)
		showDivMsg(obj_nam,rtrn_msg,divId);
	else
		return true;		
	
}
function Chk_EmailValid(obj_nam,rtrn_msg,divId)
{
	var str = document.getElementById(obj_nam).value;	
	var filter=/^.+@.+\..{2,3}$/;
	
	if (filter.test(str))
		return true;
	else 
	{
		showDivMsg(obj_nam,rtrn_msg,divId);
		return false;	
	}
}
function Chk_EmailIdsValid(obj_num,rtrn_msg,divId)
{	
	
	var email_addresses = document.getElementById(obj_num).value;
	email_addresses = email_addresses.replace(/^\s+/g, '').replace(/\s+$/g, '');

	if (email_addresses.indexOf(",")!=-1)
	{
		var emails = email_addresses.split(',');
		for (var i = 0; i < emails.length; i++)
		{
			var email = emails[i].replace(/^\s+/g, '').replace(/\s+$/g, '');			
			
			if(!Chk_EmailValid(obj_num,rtrn_msg,divId))
			{				
				return false;
			}
		}
	}
	else
	{
		if(!Chk_EmailValid(obj_num,rtrn_msg,divId))
		{			
			return false;
		}
	}
	return true;
}
function Chk_Numeric(obj_nam,rtrn_msg,divId)
{  
  var x=document.getElementById(obj_nam).value;  
  var anum=/(^\d+$)|(^\d+\.\d+$)/;
  
  if (anum.test(x))
       return true;
  else{
      showDivMsg(obj_nam,rtrn_msg,divId);
  }     
}
function Chk_AlphaNumeric(obj_nam,rtrn_msg,stat,divId)
{	
    var x = document.getElementById(obj_nam).value;
    var invalids = "";
	
	if(stat==0)
      invalids = "`~@#$%^&*()_-+=\|{}[]:;'\"<>,.?/1234567890";
	else
	  invalids = "`~@#$%^&*()_-+=\|{}[]:;'\"<>,.?/";
	  
    for(i=0; i<invalids.length; i++) 
	{       
	    if(x.indexOf(invalids.charAt(i)) >= 0 || x==false) 
		{
               showDivMsg(obj_nam,rtrn_msg,divId);
               return false;
		}
    }
    return true;
}
function textLength(obj_nam,rtrn_msg,len,divId)
{
	var x = document.getElementById(obj_nam).value;	
	if(x.length > len)
	{
		 showDivMsg(obj_nam,rtrn_msg,divId);
         return false;	
	}	
	return true;
}
/*
 * this is to compare two dates
 * if date2 > date1 returns 1
 * if date2 < date1 returns -1
 * if date2 = date1 returns 0
 * date1 and date2 must be in the format of yyyy-mm-dd 
*/
function compareTwoDate(date1,date2)
{
	var fn_date=new Date();
	var fnewdate = date1.split("-");
	
	fn_date.setFullYear(fnewdate[0]);
	fn_date.setMonth(fnewdate[1]-1);
	fn_date.setDate(fnewdate[2]);
	
	var tn_date=new Date();
	var tnewdate = date2.split("-");
	
	tn_date.setFullYear(tnewdate[0]);
	tn_date.setMonth(tnewdate[1]-1);
	tn_date.setDate(tnewdate[2]);
	
	if(tn_date < fn_date)	
		return -1;
	else if(tn_date > fn_date)
		return 1;
	else if(tn_date == fn_date)
		return 0;	
	else
		return false;
}
/********* end function ***********/
