﻿
var PixelPress_MousePosition = {x:0, y:0};
var PixelPress_ScrollPosition = {x:0, y:0};
var PixelPress_WindowDimensions = {x:0, y:0};
var PixelPress_DocumentDimensions = {x:0, y:0};




var ApplicationPath = "";
var ApplicationUrl  = "";

function UrlDecode(str)
{
    str = unescape(str);
    str = StringReplace(str, "\\+"," ");

    return str;
}

// Our browser detect is pretty swav, just call BrowserDetect.browser for browser type and so on 
var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
BrowserDetect.init();
	


function PixelPress_Init()
{   
    window.onload = PixelPress_SetWindow;
    window.onresize = PixelPress_SetWindow;
    window.onscroll = PixelPress_SetWindow;
	document.onmousemove = PixelPress_MouseMove;
}

function PixelPress_SetWindow(e)
{
    if (BrowserDetect.browser.toLowerCase() == "explorer" || BrowserDetect.browser.toLowerCase() == "firefox")
        {
            PixelPress_DocumentDimensions.x = document.body.parentNode.scrollWidth;
            PixelPress_DocumentDimensions.y = document.body.parentNode.scrollHeight;
            
		    PixelPress_ScrollPosition.x =  document.documentElement.scrollLeft;
		    PixelPress_ScrollPosition.y = document.documentElement.scrollTop;
		    
		    PixelPress_WindowDimensions.x =  document.documentElement.clientWidth;
		    PixelPress_WindowDimensions.y = document.documentElement.clientHeight;
        }
        else if(BrowserDetect.browser.toLowerCase()=="safari" || BrowserDetect.browser.toLowerCase()=="mozilla")
        {
            PixelPress_DocumentDimensions.x = document.body.parentNode.scrollWidth;
            PixelPress_DocumentDimensions.y = document.body.parentNode.scrollHeight;
        
	        PixelPress_ScrollPosition.x =  document.body.scrollLeft;
	        PixelPress_ScrollPosition.y = document.body.scrollTop;
	        
		    PixelPress_WindowDimensions.x =  document.body.clientWidth;
		    PixelPress_WindowDimensions.y = document.body.clientHeight;
	   }
}

function PixelPress_MouseMove(e) 
{

	var tX = 0;
	var tY = 0;
	
	
	if(navigator.appName.indexOf("Netscape")>=0)
	{ 
		tX = e.pageX;
		tY = e.pageY;		
	}										  
	else									  
	{
	    if (document.documentElement && document.documentElement.scrollTop)
        {
        
		    tX = event.clientX + PixelPress_ScrollPosition.x;
		    tY = event.clientY + PixelPress_ScrollPosition.y;
        }
        else
        {
        // IE
            if(event!=null)
            {    		    
		        tX = event.clientX + PixelPress_ScrollPosition.x;
		        tY = event.clientY + PixelPress_ScrollPosition.y + 20;
		    }
		}
	
	} 
	// your code goes here
	
	PixelPress_MousePosition.x = tX;
	PixelPress_MousePosition.y = tY;

}


function GetCenterLeft(sender)
{
    if(sender!=null)
    {
        return (PixelPress_WindowDimensions.x/2) - (GetWidth(sender)/2);
    }
    else
    {
        return PixelPress_WindowDimensions.x/2;
    }
}

function GetCenterTop(sender)
{  
    var retVal = new Number();
    
    if(sender!=null)
    {
        retVal = (PixelPress_WindowDimensions.y/2) - (GetHeight(sender)/2);
    }
    else
    {
        retVal = PixelPress_WindowDimensions.y/2;
    }
    
    retVal += PixelPress_ScrollPosition.y;
    
    return retVal;
}

function GetLeft(elt) 
{ 

    return parseInt(elt.x) ? elt.x : GetAbsPos(elt,"Left"); 
}

function GetTop(elt) 
{ 
    return parseInt(elt.y) ? elt.y : GetAbsPos(elt,"Top"); 
}

function GetHeight(sender) 
{	
	return sender.offsetHeight;
}

function GetWidth(sender) 
{
	return sender.offsetWidth;
}


 function IsMouseOverElementCoordinates(element)
{
    // Felt this function was necessary as onmouseover is not coordinate based and depending on the use  can cause problems
    // with mouseovers on sub elements, so i use some geometry here to establish whether or not the mouse
    // is in the same cor
    
    var mouseCoordinates = PixelPress_MousePosition;
    var elementCoordinates = GetElementCoordinates(element);
    
    var insideX = false;
    if(mouseCoordinates.x >elementCoordinates.topLeft.x && (mouseCoordinates.x <=elementCoordinates.topRight.x))
    {
        insideX = true;
    }
    
    var insideY = false;
    if(mouseCoordinates.y >elementCoordinates.topLeft.y && (mouseCoordinates.y <=elementCoordinates.bottomLeft.y))
    {
        insideY = true;
    }
    
    return insideX && insideY;
}

function GetElementCoordinates(element)
{
    var retVal = new Array();
    
    retVal.topLeft = new Array();
    retVal.topRight = new Array();
    retVal.bottomLeft = new Array();
    retVal.bottomRight = new Array();
    
    retVal.topLeft.x =  GetLeft(element);
    retVal.topLeft.y = GetTop(element);
    
    retVal.topRight.x =  retVal.topLeft.x + GetWidth(element);
    retVal.topRight.y =    retVal.topLeft.y;
    
    retVal.bottomLeft.x =  retVal.topLeft.x ;
    retVal.bottomLeft.y =    retVal.topLeft.y + GetHeight(element);
    
    retVal.bottomRight.x =  retVal.topRight.x;
    retVal.bottomRight.y =     retVal.bottomLeft.y ;
    
    return retVal;
}

function GetAbsPos(elt,which) 
{
     iPos = 0;
     while (elt != null) 
     {
      iPos += elt["offset" + which];
      elt = elt.offsetParent;
     }
     return iPos;
}



function StringReplace(inputString, regExpression, replaceString)
{
    var expression = new RegExp(regExpression);
    
    while(inputString.match(regExpression))
    {
        inputString = inputString.replace(expression, replaceString);
    }
    
    return inputString;
}

function DefaultPostBack()
{
	if(document.forms[0].length>0)
	{
		document.forms[0].submit();
	}
}


function DoNothing()
{
}

var FormDisabled = false;

function DisableEnter()
{
	return !(window.event && window.event.keyCode == 13); 
}


function GetKeyPress(e)
{
	var kC  = (window.event) ?   event.keyCode : e.keyCode; // MSIE or Firefox?
	
	return kC;
}


function GetForm(clearValue)
{
	var retVal = "";
	var seperator = "";
	var elements = document.forms[0].elements;
			
	for (var i=0; i < elements.length; i++) 
	{
		var element = elements[i];
		
		var str = new String();
		
		if(element.name!=null)
		{
		    if(element.name.toUpperCase().indexOf("VIEWSTATE")==-1)
		    {
    			
			    // if its a checkbox
			    if(element.type=="checkbox")
			    {
				    if(element.checked)
				    {
					    retVal += seperator;
					    retVal += element.name ;  
					    retVal += "=" + element.checked;   
				    }
			    }
			    else
			    {
				    retVal += seperator;
				    retVal += element.name ;  
				    retVal += "=" + element.value;   
			    }
    			
    			
			    if(clearValue!=null)
			    {
				    element.value = clearValue;
			    }
    			
			    seperator = "&"; 
    		
		    }
		}
	}
	
	return retVal;
}


function AjaxFetchElement(input, elementType,  elementId)
{
	var responseText = new String(input);

    	
	
	var exp = new RegExp("<" + elementType + "[^�]*?id=[\"]?" + elementId + "[\"]?[^�]*</" + elementType + ">", "i");
	
	responseText = exp.exec(responseText);
	
	
	
	return responseText;
}



function AjaxPost(url, mode, params)
{			
	if (window.XMLHttpRequest) 
	{ // Mozilla, Safari,... 
        http_request = new XMLHttpRequest(); 
    } 
    else if (window.ActiveXObject) 
    { // IE 
        http_request = new ActiveXObject("Microsoft.XMLHTTP"); 
    }
    
    var tDate = new Date(); 
    http_request.open(mode, url , false); 
    
    
    
    if(mode.toUpperCase()=="POST")
    {
		http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		
		if(params!=null)
		{
			http_request.setRequestHeader("Content-length", params.length);
		}
		http_request.setRequestHeader("Connection", "close");
	}
    
	http_request.send(params); 

	
	return http_request.responseText;
	
}



function AjaxPostDelegate(url, mode, params, delegate)
{			
	
	if (window.XMLHttpRequest) 
	{ // Mozilla, Safari,... 
        http_request = new XMLHttpRequest(); 
    } 
    else if (window.ActiveXObject) 
    { // IE 
        http_request = new ActiveXObject("Microsoft.XMLHTTP"); 
    }
    
    var tDate = new Date(); 
    http_request.open(mode, url , false); 
    
    
    
    if(mode.toUpperCase()=="POST")
    {
		http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		
		if(params!=null)
		{
			http_request.setRequestHeader("Content-length", params.length);
		}
		http_request.setRequestHeader("Connection", "close");
	}
	
	
	http_request.onreadystatechange = function() 
	{
		if (http_request.readyState == 4) 
		{ 
			if(http_request.responseText!=null)
			{
				delegate(http_request.responseText);
			}
			else
			{
				delegate;
			}
			
		}
	}
    
	http_request.send(params); 
	
}

function IsDefined(variable)
{
    return (typeof(variable) == "undefined")?  false: true;
}



function NameValueRetrieve(input, key)
{
    var re = new RegExp( "[&]?" + key + "=([^&]*)", "i" );
    
    var offset = input.match(re);
    
    if ( offset == -1 ) 
    {
        return null;
    }
    return RegExp.$1;

}
