function $(e){
    if(typeof(e)!='string') return e;
	return document.getElementById(e);
}
function $a(e,a){
    if(typeof(e)=='string'){
        e = document.getElementById(e);
    }
    return e.getAttribute(a);
}
function getElementPosition(ele){
    if(typeof(ele)!='string'){
	    var offsetTrail=ele;
	}else{
	    var offsetTrail=document.getElementById(ele);
	}
	var offsetHeight=offsetTrail.offsetHeight;
	var offsetWidth=offsetTrail.offsetWidth;
	var offsetLeft=0;
	var offsetTop=0;
	while (offsetTrail){
		offsetLeft+=offsetTrail.offsetLeft;
		offsetTop+=offsetTrail.offsetTop;
		offsetTrail=offsetTrail.offsetParent;
	}
	if(navigator.userAgent.indexOf("Mac")!=-1 && 
		typeof document.body.leftMargin!="undefined"){
		offsetLeft+=document.body.leftMargin;
		offsetTop+=document.body.topMargin;
	}
	return{left:offsetLeft,top:offsetTop,height:offsetHeight,width:offsetWidth};
}
function getCookieVal(ckname){
	var i,ck,ckval,ck1="";
	ck=document.cookie.split("; ");
	for(i=0;i<ck.length;i++){
		ckval=ck[i].split("=");
		if(ckval[0]=="vpcookie"){
			ck1=ckval[1];
			break;
		}
	}
	if(ck1=="")
		return "";
	ck=ck1.split("|");
	for(i=0;i<ck.length;i++){
		ckval=ck[i].split("^");
		if(ckval[0]==ckname)
			return ckval[1];
	}
	return "";
}
function setCookieVal(ckname,ckval){
	var i,ck,crumb,ck1="",dt=new Date(),updated=false,s="";
	ck=document.cookie.split("; ");
	for(i=0;i<ck.length;i++){
		crumb=ck[i].split("=");
		if(crumb[0]=="vpcookie"){
			ck1=crumb[1];
			break;
		}
	}
	if(ck1==""){
		dt.setDate(dt.getDate()+14);
		document.cookie="vpcookie="+ckname+"^"+ckval+"; expires="+dt.toGMTString()+";";
		return;
	}
	ck=ck1.split("|");
	for(i=0;i<ck.length;i++){
		crumb=ck[i].split("^");
		if(crumb[0]==ckname){
			crumb[1]=ckval;
			updated=true;
		}
		if(i>0)
			s+="|";
		s+=crumb[0]+"^"+crumb[1];
	}
	if(!updated){
		if(s!="")
			s+="|";
		s+=ckname+"^"+ckval;
	}
	//dt.setDate(dt.getDate()-7);
	//document.cookie="vpcookie=0; expires="+dt.toGMTString()+";";
	dt.setDate(dt.getDate()+14);
	document.cookie="vpcookie="+s+"; expires="+dt.toGMTString()+";";
}

function syncScrolls(sourceElement, targetElement, direction){
//    if(typeof targetElement.style.MozAppearance != "undefined"){
//        targetElement.style.overflow = '-moz-scrollbars-none';
//    }
    if(direction == "vertical" || direction == "both"){
        targetElement.scrollTop = sourceElement.scrollTop
    }else if(direction == "horizontal" || direction == "both"){
        targetElement.scrollLeft = sourceElement.scrollLeft
    }
}

function IsInsideContainer(con, x, y){
    var pos = getElementPosition(con);
    if(x >= pos.left && x <= (pos.left+pos.width)
        && y >= pos.top && y <= (pos.top+pos.height)){
        return true;
    }else{
        return false;
    }
}
function sw(sid,sy,sch){
	getStudentWindow(sid,sy,sch);
}
function getStudentWindow(sid,sy,sch){
	var x,y,w,h,o;
	w=screen.width-200;
	h=screen.height-200;
	x=100;
	y=100;
	if(window.frameElement){
		o=window.frameElement.ownerDocument.getElementById("cboStudent");
		if(o.options.length>1)
			o.value=sid;
	}
	window.open("Student.aspx?reportid=1000&schoolyearid=" + sy + "&studentid=" + sid + "&schoolid=" + sch,"_blank","width="+w+",height="+h+",left="+x+",top="+y+",location=no,menubar=no,resizable=yes,status=no,toolbar=no");
}
function tbclick(o){
	if(o.getAttribute("enabled")=="1")
		eval(o.getAttribute("action"));
}
function insertDataIntoDiv(divId){
    $(divId).innerHTML = xh.responseText;
}
function waitCursor(wait){
    if(wait){
        xWidth("WaitDiv", xClientWidth());
        xHeight("WaitDiv", xClientHeight());
        $("WaitDiv").style.display = "";
       
    }else{
        $("WaitDiv").style.display = "none";
    }
}
String.prototype.trim=function(){
    return this.replace(/^\s*|\s*$/g,'');
}

String.prototype.ltrim=function(){
    return this.replace(/^\s*/g,'');
}

String.prototype.rtrim=function(){
    return this.replace(/\s*$/g,'');
}