<!--
// ############################################################################
// #           A U T O . N E T [_o]  (c)  2 0 0 8 :: AdNWeb division          #
// ############################################################################
// #                  MISCELANEOUS UTILITES JAVASCRIPT MODULE                 #
// #                  ---------------------------------------                 #
// #                              FILE:  utils.js                             #
// #           CREATION (Author, Date):  Vitor Varalonga, 2005/03/16          #
// #         LAST UPDATE (Author, Date):  Vitor Varalonga, 2008/03/11         #
// ############################################################################


// ============================================================================
// ||                            GLOBAL VARIABLES                            ||
// ============================================================================

var flgIsIE = /msie/i.test(navigator.userAgent) && !/opera/i.test(navigator.userAgent);
var flgIsFirefox = /firefox/i.test(navigator.userAgent);


// /------------------------------\
// |         IMAGE METHODS        |
// \------------------------------/


// PreloadImgFromFolder - preloads one or more images from a particular folder ( based on MacroMedia fn MM_preloadImages v3.0 )

function PreloadImgFromFolder()
{
	var docObj = document;
	if (docObj.images)
	{
		if (!docObj.img_p)
			docObj.img_p = new Array();
		var i, j = docObj.img_p.length;
		var arrImg = (typeof arguments[0] == "object" ? arguments[0] : arguments);
	    if (arrImg[0].charAt(arrImg[0].length - 1) != "/") arrImg[0] = arrImg[0] + "/";
		for(i = 1; i < arrImg.length; i++)
		{
			if (arrImg[i].indexOf("#") != 0)
			{
				docObj.img_p[j] = new Image();
				docObj.img_p[j++].src = arrImg[0] + arrImg[i];
			}
		}
	}
}


// PreloadImg - preloads one or more images

function PreloadImg()
{
    var arrParam = new Array();
    for (idx = 0; idx < arguments.length; idx++)
        arrParam[idx] = "'" + arguments[idx] + "'";
	eval("PreloadImgFromFolder('', " + arrParam.join(", ") + ")");
}


// ImgMouseOver - Rollover image ( based on MacroMedia fn MM_swapImage v3.0 )

function ImgMouseOver()
{
	var i = 0, obj, arg = ImgMouseOver.arguments;
	
	if (arg.length == 3 && arg[0]) SetStatusMsg(arg[0]);
	obj = arg[arg.length - 2];
    if (typeof obj == "string") obj = FindObj(obj);
	
	document.img_sr = new Array();
	if (obj != null)
	{
		document.img_sr[i++] = obj;
		if (!obj.oSrc) obj.oSrc = obj.src;
		flgIsIE && obj.filters.blendTrans && obj.filters.blendTrans.Apply();
		obj.src = arg[arg.length - 1];
	    flgIsIE && obj.filters.blendTrans && obj.filters.blendTrans.Play();
	    obj.style.cursor = "pointer";
	}
	
	return true;
}


// ImgMouseOver - Restore original image ( based on MacroMedia fn MM_swapImgRestore v3.0 )

function ImgMouseOut()
{
	var i, obj, a = document.img_sr;
	ClearStatusMsg();
	for (i = 0; a && i < a.length && (obj = a[i]) && obj.oSrc; i++)
	{
		flgIsIE && obj.filters.blendTrans && obj.filters.blendTrans.Apply();
		obj.src = obj.oSrc;
	    flgIsIE && obj.filters.blendTrans && obj.filters.blendTrans.Play();
	}
	
	return true;
}


// /------------------------------\
// |          DOM METHODS         |
// \------------------------------/


// checkDOMSupport - checks if the browser implements DOM methos or not

function checkDOMSupport()
{
	return (document.createElementNS || document.createElement ? true : false);
}


// CreateDOMElement - creates a new HTML DOM element of a certain type;
//                    this element can obviously descend from another one.
//                    SINTAXE:   CreateDOMElement(element_type[, element_father])

function CreateDOMElement()
{
	var elemDOMType = arguments[0];
	var refElemDOM = null;
	
	refElemDOM = (document.createElementNS ?
		document.createElementNS("http://www.w3.org/1999/xhtml", elemDOMType)
		: document.createElement(elemDOMType)
	);
	
	if (arguments.length > 1 && typeof arguments[1] != "undefined") {
		arguments[1].appendChild(refElemDOM);
	}
	
	return refElemDOM;
}


// FindObj - finds a particular object ( based on MacroMedia fn MM_findObj v3.0 )

function FindObj(objId, parentObj) {
	var pos, idx, obj;
	
	(!parentObj) && (parentObj = document);
	if ((pos = objId.indexOf("?")) > 0 && parent.frames.length) {
		parentObj = parent.frames[objId.substring(pos + 1)].document;
		objId = objId.substring(0, pos);
	}
	if (!(obj = parentObj[objId]) && parentObj.all)
		obj = parentObj.all[objId];
	for (idx = 0; !obj && idx < parentObj.forms.length; idx++)
		obj = parentObj.forms[idx][objId];
	for (idx = 0; !obj && parentObj.layers && idx < parentObj.layers.length; idx++)
		obj = FindObj(objId, parentObj.layers[idx].document);
	(!obj) && (obj = parentObj.getElementById(objId));	// Mozilla/Firefox
	
	return obj;
}


// /------------------------------\
// |         EVENT METHODS        |
// \------------------------------/


// StartEventHandle - associates an event to an object

function StartEventHandle(elem, evntName, evntFn)
{
	elem = typeof(elem) == "string" ? document.getElementById(elem) : elem;
	if (elem.attachEvent) { // IE
		elem.attachEvent("on" + evntName, evntFn);
	}
	else if (elem.addEventListener) { // Gecko / W3C
		elem.addEventListener(evntName, evntFn, true);
	}
	else {
		elem["on" + evntName] = evntFn;
	}
}


// StopEventHandle - stops a specific event associated to a specific object

function StopEventHandle(elem, evntName, evntFn)
{
	elem = typeof(elem) == "string" ? document.getElementById(elem) : elem;
	if (elem.detachEvent) { // IE
		elem.detachEvent("on" + evntName, evntFn);
	}
	else if (elem.removeEventListener) { // Gecko / W3C
		elem.removeEventListener(evntName, evntFn, true);
	}
	else {
		elem["on" + evntName] = null;
	}
}


// GetEventElement - gets a reference to the object associated to an event

function GetEventElement(evnt)
{
	return (flgIsIE ? window.event.srcElement : evnt.currentTarget);
}


// /------------------------------\
// |         MATH METHODS         |
// \------------------------------/


// HexToDec - Hexadecimal to Decimal Conversion...

function HexToDec(hex1)
{
    return parseInt(hex1, 16);
}


// HexToDec - Decimal to Hexadecimal Conversion...

function DecToHex(dec1)
{
    return dec1.toString(16);
}


// DegToRad - Degrees to Radians Conversion...

function DegToRad(deg1)
{
    return deg1 * Math.PI / 180;
}


// RadToDeg - Radians to Degrees Conversion...

function RadToDeg(rad1)
{
    return rad1 * 180 / Math.PI;
}


// AddLeadingZeros - Add necessary leading zeros to a number...

function AddLeadingZeros(num, totalDigits)
{
    var numDigits = (num + "").length;
    if (numDigits < totalDigits)
        for (var idx = 0; idx < totalDigits - numDigits; idx++)
            num = "0" + num;
    return num;
}


// /------------------------------\
// |         MISC METHODS         |
// \------------------------------/


function PopUpWin(url, winW, winH)
{
	var newWin = window.open(url, '_blank', 'fullscreen=no,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=no,width=' +
		winW + ',height=' + winH); //(winH + (flgIsFirefox ? -22 : 0)));
	newWin.focus();
	return true;
}


// GetFileNameFromFilePath - retrieves the filename from the filepath

function GetFileNameFromFilePath(filePath)
{
	return filePath.substr(filePath.lastIndexOf("/") + 1);
}


function ApplyBlendTransToImg(delay, imgId)
{
	var imgObj = document.getElementById(imgId);
	if (imgObj) imgObj.style.filter = "blendTrans(duration=" + delay + ")";
}


function SetStatusMsg(msg)
{
	window.status = msg;
	return true;
}


function ClearStatusMsg()
{
	window.status = "";
	return true;
}


function $(elem)
{
	(typeof elem == "string") && (elem = document.getElementById(elem));
	return elem;
}


function SetObjCSS(obj, css)
{
	obj = $(obj);
	(!obj.oCSS) && (obj.oCSS = obj.className);
	obj.className = css;
}


function RestoreObjCSS(obj)
{
	obj = $(obj);
	obj.className = obj.oCSS;
}


function GetElemWidth(elem)
{
    return $(elem).offsetWidth;
}


function GetElemHeight(elem)
{
    return $(elem).offsetHeight;
}


function GetElemSize(elem)
{
    elem = $(elem);
    return { width: $(elem).offsetWidth, height: $(elem).offsetHeight };
}


function SetElemWidth(elem, w)
{
    $(elem).style.width = w + "px";
}


function SetElemHeight(elem, h)
{
    $(elem).style.height = h + "px";
}


function SetElemSize(elem, w, h)
{
    $(elem).style.width = w + "px";
    $(elem).style.height = h + "px";
}


function SetElemLeft(elem, l)
{
    $(elem).style.left = l + "px";
}


function SetElemTop(elem, t)
{
    $(elem).style.top = t + "px";
}


function SetElemPos(elem, l, t)
{
    $(elem).style.left = l + "px";
    $(elem).style.top = t + "px";
}


function ShowElem(elem)
{
    $(elem).style.display = "";
}


function HideElem(elem)
{
    $(elem).style.display = "none";
}


function GetPageSize()
{
	var scrollX, scrollY, windowWidth, windowHeight;
	
	if (window.innerHeight && window.scrollMaxY)
	{	
		scrollX = window.innerWidth + window.scrollMaxX;
		scrollY = window.innerHeight + window.scrollMaxY;
	}
	else if (document.body.scrollHeight > document.body.offsetHeight)  // all but Explorer Mac
	{
		scrollX = document.body.scrollWidth;
		scrollY = document.body.scrollHeight;
	}
	else   // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
	{
		scrollX = document.body.offsetWidth;
		scrollY = document.body.offsetHeight;
	}
	
	if (self.innerHeight)	// all except Explorer
	{
		if (document.documentElement.clientWidth)
			windowWidth = document.documentElement.clientWidth; 
		else
			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 width less then width of the viewport
	if (scrollX < windowWidth)
		pageWidth = scrollX;		
	else
		pageWidth = windowWidth;
    
	// for small pages with total height less then height of the viewport
	if (scrollY < windowHeight)
		pageHeight = windowHeight;
	else 
		pageHeight = scrollY;
    
	return {
	    pageWidth: pageWidth,
	    pageHeight: pageHeight,
	    windowWidth: windowWidth,
	    windowHeight: windowHeight
	};
}

function GetPageScroll()
{
	var scrollX, scrollY;

	if (self.pageYOffset)
	{
		scrollX = self.pageXOffset;
		scrollY = self.pageYOffset;
	}
	else if (document.documentElement && document.documentElement.scrollTop)   // Explorer 6 Strict
	{
		scrollX = document.documentElement.scrollLeft;
		scrollY = document.documentElement.scrollTop;
	}
	else if (document.body)   // all other Explorers
	{
		scrollX = document.body.scrollLeft;	
		scrollY = document.body.scrollTop;
	}

	return {
	    scrollX: scrollX,
	    scrollY: scrollY
	};
}


function SetElemOpacity(obj, opacityVal)    /* opacityVal = (0 .. 1) */
{
    if (typeof obj == "string") obj = $(obj);
    with (obj.style)
    {
 	    opacity = opacityVal;
        MozOpacity = opacityVal;
        KhtmlOpacity = opacityVal;
        filter = "alpha(opacity=" + (opacityVal * 100) + ")";
    }
}
-->