// *** BROWSER DETECTION VARIABLES ***
// Requires: None.

// isDOM: W3C-DOM compatible browser? (IE5+, NS6+, others like Opera, Konqueror, etc...)
// isIE: Internet Explorer (v4 and up), also Opera emulating it.
// isIE4, isNS4: Each of the 4-series browsers (not DOM compatible).
// isOp: Any Opera version (useful as Opera emulates IE above).
// isWin: True is Windows, false if Mac/Linux etc.
// isDyn: Any DHTML-capable browser.

var isDOM=document.getElementById?1:0,
 isIE=document.all?1:0,
 isNS4=navigator.appName=='Netscape'&&!isDOM?1:0,
 isIE4=isIE&&!isDOM?1:0,
 isOp=self.opera?1:0,
 isDyn=isDOM||isIE||isNS4,
 isWin=navigator.platform.indexOf('Win')!=-1?1:0;
 
 
// *** DOCUMENT OBJECT MODEL (DOM) REFERENCE FUNCTIONS ***
// Requires: Brower Detection Variables "isDOM, isIE, isNS4, isOp"

// Get a reference to an element by its ID, and optionally a parent element/frame.
// Pass a parameter 'par' as either null to find a element in the current document,
// a reference to a parent element using another getRef call or similar,
// or reference to another window (e.g. parent.content) for frames usage.
function getRef(i, p)
{
 p=!p?document:p.navigator?p.document:p;
 return isIE ? p.all[i] :
  isDOM ? (p.getElementById?p:p.ownerDocument).getElementById(i) :
  isNS4 ? p.layers[i] : null;
};
function getVal(id,p){ 
var retval = encodeURIComponent(getRef(id, p).value);
while(retval.indexOf('*')>-1)
{
 retval = retval.replace('*', '%2A');
}
while(retval.indexOf('(')>-1)
{
 retval = retval.replace('(', '%28');
}
while(retval.indexOf(')')>-1)
{
 retval = retval.replace(')', '%29');
}
return  retval;
}

// Returns a reference to the .style property of an element, same parameters.
function getSty(i, p)
{
 var r=getRef(i, p);
 return r?isNS4?r:r.style:null;
}; 

// Requires HtmlHttpRequest

function exception_info(ex) 
{
	exception_process("info", ex);
}

function exception_debug(ex) 
{
	exception_process("debug", ex);
}

function exception_error(ex) 
{
	exception_process("error", ex);
}

function exception_process(level, ex) 
{
	if (level == "error" || level == "debug" || level == "info") 
	{
		exception_post(level, ex);
	} 
	if (level == "error") 
	{
		ex = ex +"";
		ex = ex.replace("\n","; ");
		if (ex.indexOf("Permission") == -1 && ex.indexOf("denied") == -1) 
		{
			alert("Javascript Error:\n\n" + ex);
		}		
	} 	
}

function exception_post(level, ex) 
{
	smart_post("log", "addbrowser=yes&level="+level+"&error="+escape(ex));	
}

var global_smartPicCurrent = 1;
var global_smartPicCount = 9;
var global_smartPicArray = new Array();

function smart_post(action, params) 
{
	try 
	{
		elmPicName = "JSSmartPic"+global_smartPicCurrent;
		global_smartPicCurrent++;
		if (global_smartPicCurrent>global_smartPicCount) 
		{
			global_smartPicCurrent = 1;
		}
		if (!global_smartPicArray[elmPicName]) 
		{			
			elmPic = getRef(elmPicName);
			global_smartPicArray[elmPicName] = elmPic;
		} 		
		elmPic = global_smartPicArray[elmPicName];
		if (elmPic) 
		{			
			newSrc = "dot_smart.aspx?action="+action+"&"+params+"&"+Math.random()+"&.jpg";
			elmPic.src = newSrc;			
		}		
	}
	catch (exNull) 
	{
		alert(exNull);
		// do nothing
	}
}

function errorHandler(message, url, line)
{
   // message == text-based error description
   // url     == url which exhibited the script error
   // line    == the line number being executed when the error occurred 
   exception_error("Message: ["+message+"]\nUrl: ["+url+"]\nLine: ["+line+"]");   
   return true;
}

function openHelpWindow(strRole)
{
    alert('The help is under construction.');
    return;
	var id = 0;
	var subid = 0;
	if (strRole == "V") 
	{
		id = 2; // Visitor
	}
	if (strRole == "T") 
	{
		id = 3; // Teacher
		try 
		{
			if (jsContext) 
			{
				var cPage = (""+jsContext.getCurrentPage()).toLowerCase();
				if (cPage == "jsprofile.aspx") 
				{
					subid = 6;
				}
				if (cPage == "jsindex.aspx") 
				{
					subid = 7;
				}
				if (cPage == "jsstudentsexplorer.aspx") 
				{
					subid = 8;
				}
				if (cPage == "jstestexplorer.aspx") 
				{
					subid = 9;
				}
				if (cPage == "jsparentconferencer.aspx") 
				{
					subid = 10;
				}				
			}					
		}		
		catch (ex) 
		{
			//do nothing
		}	
	}
	if (strRole == "C") 
	{
		id = 4; // SchoolAdministrator
		if (jsContext) 
		{
			var cPage = (""+jsContext.getCurrentPage()).toLowerCase();
			if (cPage == "jsprofile.aspx") 
			{
				subid = 65;
			}
			if (cPage == "jsindex.aspx") 
			{
				subid = 71;
			}
			if (cPage == "jsstudentsexplorer.aspx") 
			{
				subid = 104;
			}
			if (cPage == "jstestexplorer.aspx") 
			{
				subid = 114;
			}
		}
	}
	if (strRole == "D") 
	{
		id = 5; // DistrictAdministrator
		if (jsContext) 
		{
			var cPage = (""+jsContext.getCurrentPage()).toLowerCase();
			if (cPage == "jsprofile.aspx") 
			{
				subid = 124;
			}
			if (cPage == "jsindex.aspx") 
			{
				subid = 125;
			}
			if (cPage == "jsstudentsexplorer.aspx") 
			{
				subid = 126;
			}
			if (cPage == "jstestexplorer.aspx") 
			{
				subid = 127;
			}
		}
	}
	if (strRole == "S") 
	{
		id = 62; // DistrictAdministrator
	}
	window.open("ReportFrameSet.aspx?TestID=0&reportName=helpTopics&HelpTopicID=" + id+"&SubTopicID="+subid, "_blank", "menubar=no, status=no, toolbar=no, resizable=no, location=no, directories=no, height=600, width=700");
}

function openHelpTip(topicId)
{	
	window.open("HelpTopics.aspx?TestID=0&reportName=helpTopics&SkipRoot=False&ShowSubtopics=False&HelpTopicID=" + topicId, "_blank", "menubar=no, status=no, toolbar=no, resizable=yes, scrollbars=yes, location=no, directories=no, height=220, width=350");
}

function openSchoolYears()
{	
	window.open("SwitchSchoolYears.aspx", "_blank", "menubar=no, status=no, toolbar=no, resizable=yes, scrollbars=yes, location=no, directories=no, height=270, width=600");
}

function addUrlParameter(url, par)
{
	if (url.indexOf('?')<0) return url+'?'+par;
	return url+'&'+par;
}

var loadingHtmlText = "<table width='100%' height='100%' border='0' bgcolor='white'><tr><td align='center'>loading ...</td></tr></table>";

function Wait(ar)
{
    for(a in ar)
    {
        var o = getRef(ar[a]);
        if (o)
        {   
            o.style.cursor='wait';
            setTimeout('getRef("' + ar[a] + '").disabled=true;', 10);
        }
    }
    document.body.style.cursor='wait';
    return true;
}