﻿//
// Detect OS, browser name and version
//
var detect = navigator.userAgent.toLowerCase();
var OS,browser,total,thestring;
var version = 0;

if (checkIt('konqueror'))
{
	browser = "Konqueror";
	OS = "Linux";
}
else if (checkIt('safari')) browser = "Safari"
else if (checkIt('omniweb')) browser = "OmniWeb"
else if (checkIt('opera')) browser = "Opera"
else if (checkIt('webtv')) browser = "WebTV";
else if (checkIt('icab')) browser = "iCab"
else if (checkIt('msie')) browser = "Internet Explorer"
else if (!checkIt('compatible'))
{
	browser = "Netscape Navigator"
	version = detect.charAt(8);
}
else browser = "An unknown browser";

if (!version) version = detect.charAt(place + thestring.length);

if (!OS)
{
	if (checkIt('linux')) OS = "Linux";
	else if (checkIt('x11')) OS = "Unix";
	else if (checkIt('mac')) OS = "Mac"
	else if (checkIt('win')) OS = "Windows"
	else OS = "an unknown operating system";
}

function checkIt(string)
{
	place = detect.indexOf(string) + 1;
	thestring = string;
	return place;
}


//
// Suckerfish menu script for IE < 7.0
//
sfHover = function() {
    var pageULs = document.getElementsByTagName("UL");
    for (var i =0; i < pageULs.length; ++i) {
        if (pageULs[i].className == "sfMenu") {
	        var sfEls = pageULs[i].getElementsByTagName("LI");
	        for (var j=0; j<sfEls.length; j++) {
		        sfEls[j].onmouseover=function() {
			        this.className+=" sfhover";
		        }
		        sfEls[j].onmouseout=function() {
			        this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		        }
	        }
        }
    }
}
if (version < 7 && browser == "Internet Explorer") window.attachEvent("onload", sfHover);

//
// simulate hover effect for all element in IE < 6.0
//
function EnableHover(elemntId, sourceElemType, sourceElemClass)
{
    if (version < 7 && browser == "Internet Explorer") {
        var containerElem = document.getElementById(elemntId);
        var sourceElems = containerElem.getElementsByTagName(sourceElemType);
        for (var i =0; i < sourceElems.length; ++i) 
            if (sourceElems[i].className == sourceElemClass) {
                sourceElems[i].onmouseover=function() {	                
	                this.className+=" hover";
                }
                sourceElems[i].onmouseout=function() {
	                this.className=this.className.replace(new RegExp(" hover\\b"), "");
                }
            } // end of if   
    } // end of if
}

function findPosX(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj)
{
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}

//
// opens a new window
//
function OpenDialog(path, title, width, height)
{    
    var arrayPageSize = getPageSize();
    var top = ((arrayPageSize[3] - 20 - height) / 2); 
    var left = ((arrayPageSize[2] - 20 - width) / 2); 
    var params = "width=" + width + ",height=" + height + ",left=" + left + ",top=" + top + ",dependent=1";
    window.open(path,title,params);
}

function OpenDialog(path, title, width, height, scrollbars, menubar )
{    
    var arrayPageSize = getPageSize();
    var top = ((arrayPageSize[3] - 20 - height) / 2); 
    var left = ((arrayPageSize[2] - 20 - width) / 2); 
    var params = "width=" + width + ",height=" + height + ",left=" + left + ",top=" + top + ",scrollbars=" + scrollbars + ",menubar=" + menubar + ",dependent=1";
    window.open(path,title,params);
}

//
// methods that are related to client postbacks
//
function CallServer(control, arg) {
    WebForm_DoCallback(control, arg, ReciveServerData, "", null, true);
}

function ReciveServerData(rValue) {
    var ss = rValue.split("::=");
    var ctrl = document.getElementById(ss[0]);
    ctrl.innerHTML = ss[1];
    CancelLoadingMode(ctrl);
}

function ActivateLoadingMode(control) {
    control.style.height = control.offsetHeight + 'px';
    control.innerHTML = '';
    control.className = 'loading';
}

function CancelLoadingMode(control) {
    control.style.height = 'auto';    
    control.className = '';
}

function CastVote(control, radioListName, resultPanel) {
    var radioList = document.getElementsByName(radioListName);    
    for(var i =0; i < radioList.length; ++i) {
        if(radioList[i].checked) {
            var pnlResults = document.getElementById(resultPanel);            
            CallServer(control, radioList[i].value);
            ActivateLoadingMode(pnlResults);
            return false;
        }
    }
    return false;
}

function ShowResults(control, arg, resultPanel) {
    var pnlResults = document.getElementById(resultPanel);            
    CallServer(control, arg);
    ActivateLoadingMode(pnlResults);   
    return false; 
}

function InitPauseScroller(control, arg, scrollerDiv, dellay)
{
    WebForm_DoCallback(control, arg, LoadPauseScroller, "", null, true);
}

function LoadPauseScroller(rValue) {
    var ss = rValue.split("::=");
    var divId = ss[0];
    var delay = ss[1];
    var scrollerId = divId + "Scroller";
    var contentArray = new Array();    
    
    for(var i = 2; i < ss.length; ++i)
        contentArray[i - 2] = ss[i];
    
    if(contentArray.length > 1)
    {
        var pScroller;
        if(pScroller == undefined)
            pScroller = new pausescroller(contentArray, divId, delay)
    }
}

//
// Disable Selection
//
function DisableSelection(controlId) {
    document.getElementById(controlId).onselectstart = function() { return false; }
    document.getElementById(controlId).onmousedown = function() { return false; }
}


//
// getPageSize()
// Returns array with page width, height and window width, height
// Core code from - quirksmode.org
// Edit for Firefox by pHaez
//
function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}


	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}

//
// getPageScroll()
// Returns array with x,y page scroll values.
// Core code from - quirksmode.org
//
function getPageScroll(){

	var yScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
	}

	arrayPageScroll = new Array('',yScroll) 
	return arrayPageScroll;
}