﻿var IE = document.all?true:false;
if (!IE) 
	document.captureEvents(Event.CLICK);
document.onmouseclick = getMouseXY;
var tempX = 0;
var tempY = 0;

function getMouseXY(e) 
{
	if (IE) 
	{ // grab the x-y pos.s if browser is IE
		tempX = event.clientX + document.body.scrollLeft;
		tempY = event.clientY + document.body.scrollTop;
	}
	else 
	{  // grab the x-y pos.s if browser is NS
		tempX = e.pageX;
		tempY = e.pageY;
	}  
	if (tempX < 0)
		tempX = 0;
	if (tempY < 0)
		tempY = 0;
	alert(tempX+","+tempY);
	return true;
}function trim( szJS ){	var i;
	var c;
	var szReturn = '';
	for( i = 0; i < szJS.length; i ++  )	{
		c = szJS.substring( i, i + 1 );
		if( c != ' ' )
			szReturn += c;
	}
	return szReturn;
}
function ltrim( szJS ){
	var i;
	var c;
	
	for( i = 0; i < szJS.length; i ++  ){
		c = szJS.substring( i, i + 1 );
		if( c != ' ' )
			break;
	}
	return szJS.substr( i );
}
function rtrim( szJS ){
	var i;
	var c;
	
	for( i = szJS.length; i > 0 ; i --  )
	{
		c = szJS.substring( i, i - 1 );
		if( c != ' ' )
			break;
	}
	return szJS.substring( 0, i );
}

function EscapeXML( szXML ){	var szReturn = '';	if (typeof(szXML) == 'undefined' || String(szXML) == '')		return szReturn ;
	if (typeof(szXML) != 'string')
	    return szXML ; 			

	var startIndex = 0;	var endIndex = 0;	while( szXML.indexOf( '&', startIndex ) != -1 )	{		endIndex = szXML.indexOf( '&', startIndex ) + 1;		szReturn += szXML.substring( startIndex, endIndex ).replace( '&', '&amp;' );		startIndex = endIndex;	}
	szReturn += szXML.substr( startIndex );	while( szReturn.indexOf( '<' ) != -1 )		szReturn = szReturn.replace( '<', '&lt;' );	while( szReturn.indexOf( '>' ) != -1 )		szReturn = szReturn.replace( '>', '&gt;' );	while( szReturn.indexOf( '"' ) != -1 )		szReturn = szReturn.replace( '"', '&quot;' );	while( szReturn.indexOf( "\'" ) != -1 )		szReturn = szReturn.replace( "'", "&apos;&apos;" );
	return szReturn;
}	
function popup(url,WinName) 
{
var width  = 600;
 var height = 400;
 var left   = (screen.width  - width)/2;
 var top    = (screen.height - height)/2;
 var params = 'width='+width+',height='+height;
 params += ',top='+top+', left='+left;
 params += ',directories=no';
 params += ',location=no';
 params += ',menubar=no';
 params += ',resizable=no';
 params += ',scrollbars=no';
 params += ',status=no';
 params += ',toolbar=no';
 var newwin=null;
	newwin=window.open(url,WinName, params);
 if (window.focus) 
		{newwin.focus()}
 return false;
}


function goToPage( page, target, alertForModifications ,HaveSkills)
{
	checkIfRematch( page )
	if( typeof( alertForModifications ) != 'undefined' )
		if( alertForModifications )
		{
			if (!confirm( 'Save button was not clicked. Would you like to exit without saving?' ))
				return;
			else
				pageTouched = false;
		}

	if(parent.name=='redmatchWindow') target = 'window.name'

	document.forms['hiddenForm'].action = "c.asp?action=" + page + "";
	if( target != "" ) eval( "document.forms['hiddenForm'].target = " + target + ";" );
	document.forms['hiddenForm'].submit();}
function GetElementPosition(element, relativeElement)
{
	/// <summary>
	/// Calculates position of the specified html element relative another html element.
	/// </summary>
	/// <returns>
	/// Returns object with 'x' and 'y' properties which represent a position of the element.
	/// </returns>

	var offsetX = 0;
	var offsetY = 0;

	if (element.parentNode)
	{
		try
		{
			// FireFox doesn't support uniqueID property, so create a temporary one
			if (relativeElement && relativeElement.uniqueID == null)
				relativeElement.uniqueID = "tempUniqueId";

			do
			{
				offsetX += element.offsetLeft;
				offsetY += element.offsetTop;

				while (element && (element = element.offsetParent) && (element && element.nodeType != 1));
			}
			while (element && (relativeElement == null || element.uniqueID == null || element.uniqueID != relativeElement.uniqueID));

			// remove temporary uniqueID
			if (relativeElement != null && relativeElement.uniqueID == "tempUniqueId")
				delete relativeElement.uniqueID;
		}
		catch (ex)
		{
			offsetX = offsetY = NaN;
		}
	}

	return { x: offsetX, y: offsetY };
}

function GetChildElementByIndex(element, index)
{
	/// <summary>
	/// Gets a node of element type (nodeType = 1) at specified index from the collection of child nodes of specified parent element.
	/// </summary>
	/// <param name="element">Parent element whose child nodes will be searched for the node at the specified index.</param>
	/// <param name="index">Index of the requested element.</param>
	/// <remarks>
	/// Use this function instead of childNodes collection to get an element node at specific index, because
	/// it searches element nodes only. It skips nodes of another types, which can be randomly differently added by different browsers.
	/// </remarks>
	/// <returns>
	/// Returns an element node at the specified index if found, otherwise null.
	/// </returns>

	for (var n = 0, node = element.firstChild; node; node = node.nextSibling)
	{
		if (node.nodeType == 1 && n++ == index)
			return node;
	}

	return null;
}

function GetParentByTagName(element, tagName)
{
	tagName = tagName.toLowerCase();

	while (element && (element.nodeType == 1) && (element.tagName.toLowerCase() != tagName) && (element = element.parentNode));

	return element.nodeType == 1 ? element : null;
}

function RegisterOnResponseCallback(callback)
{
	/// <summary>
	/// This is shortcut to call some callback function after a server response.
	/// Requres Ajax's ScriptManager on a page the method called from.
	/// </summary>

	function ___OnResponse(sender, args)
	{
		Sys.WebForms.PageRequestManager.getInstance().remove_endRequest(___OnResponse);

		callback(sender, args);
	}

	Sys.WebForms.PageRequestManager.getInstance().add_endRequest(___OnResponse);
}

function IE6CssFix(cssApplyMode, map)
{
	/// <summary>
	/// Adds mouse hover CSS functionality in IE6, where this does not work.
	/// </summary>

	Initialize();

	function Initialize()
	{
		if (Sys.Browser.agent != Sys.Browser.InternetExplorer || Sys.Browser.version != 6)
			return;

		map = new Array();
		cssApplyMode = cssApplyMode || "append"; // replace

		for (var n = 0; n < document.styleSheets.length; n++)
		{
			var style = document.styleSheets[n];
			var matches = style.cssText.match(/\..*:hover(\r\n|.)*?{(\r\n|.)*?}/g);

			if (matches == null)
				continue;

			for (var m = 0; m < matches.length; m++)
			{
				var match = matches[m];
				var styleName = match.match(/.*(?=:hover)/g)[0].substr(1);
				var styleBody = match.match(/{(\r\n|.)*?}/g)[0];
				var hoverStyleName = styleName + "_hover";

				map[styleName] = hoverStyleName;

				style.addRule("." + hoverStyleName, styleBody);
			}
		}

		document.body.attachEvent("onmouseover", OnMouseOver);
		document.body.attachEvent("onmouseout", OnMouseOut);
	}

	function ProcessMouseOver(element)
	{
		if (element == null)
			return;

		var className = element.className;

		if (className.length == 0)
			return;

		var styles = className.split(" ");
		
		for (var n = 0, length = styles.length; n < length; n++)
		{
			var style = styles[n];

			if (style.length == 0)
				continue;

			var hoverStyle = map[style];

			if (hoverStyle != null)
			{
				if (cssApplyMode == "append")
					element.className += " " + hoverStyle;
				else
					element.className = element.className.replace(style, hoverStyle);
			}
		}
	}
	
	function ProcessMouseOut(element)
	{
		if (element == null)
			return;

		var className = element.className;

		if (className.length == 0)
			return;

		var styles = className.match(/\w*(?=_hover)/g);

		if (styles == null)
			return;

		for (var n = 0, length = styles.length; n < length; n++)
		{
			var style = styles[n];

			if (style.length == 0)
				continue;

			if (cssApplyMode == "append")
				element.className = element.className.replace(new RegExp("\\s?" + style + "_hover"), "");
			else
				element.className = element.className.replace(new RegExp("\\s?" + style + "_hover"), style);
		}
	}

	function OnMouseOver()
	{
		var element = event.srcElement;

		ProcessMouseOver(element);
		ProcessMouseOver(GetParentByTagName(element, "tr"));
	}

	function OnMouseOut()
	{
		var element = event.srcElement;

		ProcessMouseOut(element);
		ProcessMouseOut(GetParentByTagName(element, "tr"));
	}
}

function IE6Fix_HideDropDownControls()
{
	if (Sys.Browser.agent == Sys.Browser.InternetExplorer && Sys.Browser.version == 6)
	{
		// hides improve matchability controls. (Because z-index bug in IE6)
		//$get("imContolsHolder").style.visibility = "hidden";
		var elements = document.getElementsByTagName("select")

		for (var n = 0; n < elements.length; n++)
		{
			elements[n].style.visibility = "hidden";
		}
	}
}

function IE6Fix_ShowDropDownControls()
{
	if (Sys.Browser.agent == Sys.Browser.InternetExplorer && Sys.Browser.version == 6)
	{
		// shows back improve matchability controls. (Because z-index bug in IE6)
		//$get("imContolsHolder").style.visibility = "visible";
		var elements = document.getElementsByTagName("select")

		for (var n = 0; n < elements.length; n++)
		{
			elements[n].style.visibility = "visible";
		}
	}
}

function setCookie(name, value, expires, path, domain, secure)
{
	/*
		name - name of the cookie
		value - value of the cookie
		[expires] - expiration date of the cookie (defaults to end of current session)
		[path] - path for which the cookie is valid (defaults to path of calling document)
		[domain] - domain for which the cookie is valid (defaults to domain of calling document)
		[secure] - Boolean value indicating if the cookie transmission requires a secure transmission
	*/
	var curCookie = name + "=" + escape(value) +
		((expires) ? "; expires=" + expires.toGMTString() : "") +
		((path) ? "; path=" + path : "") +
		((domain) ? "; domain=" + domain : "") +
		((secure) ? "; secure" : "");
	document.cookie = curCookie;
}

function getCookie(name)
{

  var dc = document.cookie;
  var prefix = name + "=";
  var begin = dc.indexOf("; " + prefix);
  if (begin == -1) {
    begin = dc.indexOf(prefix);
    if (begin != 0) return null;
  } else
    begin += 2;
  var end = document.cookie.indexOf(";", begin);
  if (end == -1)
    end = dc.length;
  return unescape(dc.substring(begin + prefix.length, end));
}
function deleteCookie(name, path, domain)
{
  if (getCookie(name)) {
    document.cookie = name + "=" +
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}

function loadWaitDiv()
{
		var imgStyle = document.getElementById("waitDivImage").style;
		imgStyle.position="absolute";
		imgStyle.top = "" + screen.height/2 - 50 + "px";
		imgStyle.left = "" + screen.width/2-300 + "px";
}

