﻿
/*-------------------------------------------------------------------------------------------------

    A S P . N E T   F O R M   G L O B A L   R E F E R E N C E

-------------------------------------------------------------------------------------------------*/
function getAspNetForm(){
    var f = document.forms['aspnetForm'];
    if (!f) {
        f = document.aspnetForm;
    }
    return f;
}
/*-------------------------------------------------------------------------------------------------

    O B J E C T    O B J E C T    A D D    O N S

-------------------------------------------------------------------------------------------------*/
Object.duplicate=function(obj){
    var newObj={};
    for(var i in obj) newObj[i]=obj[i];
    return newObj;
}
/*-------------------------------------------------------------------------------------------------

    S T R I N G    O B J E C T    A D D    O N S

-------------------------------------------------------------------------------------------------*/
String.prototype.toLower=function() { return Convert.toString(this).toLowerCase(); }
String.prototype.toUpper=function() { return Convert.toString(this).toLowerCase(); }
String.prototype.lTrim=function(){return this.replace(/^\s+/g,'')};
String.prototype.rTrim=function(){return this.replace(/\s+$/g,'')};
String.format=function(){
    var vals=arguments.length-1,str=arguments[0];
    if(!str) return str;
    for(var i=0; i<vals; i++){
        var val=new String(arguments[i+1]);
        if(!val) continue;
        str = str.split("{"+i+"}").join(val);
    }
    return str;
};
/*-------------------------------------------------------------------------------------------------

    W I N D O W . L O C A T I O N   O B J E C T    A D D    O N S

-------------------------------------------------------------------------------------------------*/
window.location.getQueryHashTable=function(){
    if(!window.location.__queryHashTable){
        window.location.__queryHashTable={};
        var sArr=window.location.search.slice(1).split("=");
        if(sArr.length>1){
            for(var i=0;i<sArr.length;i+=2) window.location.__queryHashTable[decodeURI(sArr[i])]=decodeURI(sArr[i+1]);
        }
    } 
    return Object.duplicate(window.location.__queryHashTable); 
}
/*-------------------------------------------------------------------------------------------------

    C O O K I E S

-------------------------------------------------------------------------------------------------*/
__DOCUMENTCOOKIEDOMAIN=null;
function setCookie(name,value,days) {
	var ex = "";
	if (days) {
		var d = new Date();
		d.setTime(d.getTime()+(days*24*60*60*1000));
		ex = "; expires="+ d.toGMTString();
	}
	document.cookie = name+"="+value+ex+ ((b.isSafari)?";":"; path=/;") + ((!b.opera)?((__DOCUMENTCOOKIEDOMAIN)?" domain=" + __DOCUMENTCOOKIEDOMAIN:""):"");
}

function getCookie(name) {
	var eq = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i<ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(eq) == 0) return c.substring(eq.length,c.length);
		else if(c==name) return "";
	}
	return null;
}

function eraseCookie(name) {
	setCookie(name,"",-1);
}
function setCookieDomain(val){
    __DOCUMENTCOOKIEDOMAIN=val;
}


/*-------------------------------------------------------------------------------------------------

    A N I M A T I O N       P A T T E R N S

-------------------------------------------------------------------------------------------------*/

animation= function(){};
animation.prototype={
    stepsArgumentsArray:[],     //is an array of arrays where each array is a set of arguments to be passed to the stepFunction function
    stepFunction:function(){},  //a function that is called at each step of the animation
    frequency:0,                //in milliseconds the duration of a single step
    start:function(){           //starts the animation
        var l=this.stepsArgumentsArray.length;
        for(var i=0; i<l; i++){
            var a="var anim=window.animations._animations["+ this.id +"];anim.stepFunction.apply(null,anim.stepsArgumentsArray["+ i +"])";
            setTimeout(a,this.frequency*i)
        }
    },
    id:0 //unique ID for the animation
}
window.animations={
    _animations:[],
    addAnimation:function(){ //use this function to create an animation
        var a=new animation();
        var l=this._animations.length;
        this._animations[l]=a;
        a.id=l;
        return a;
    }
}

//---------------------------------------------------------------------------------------------
//
//      A N I M A T I O N   I M P L E M E N T A T I O N S
//
//---------------------------------------------------------------------------------------------

AlphaAnimation=function(obj,steps,frequency,startAlphaPercent,endAplhaPercent){
    this.animation=window.animations.addAnimation();
    this.animation.frequency=frequency;
    this.animation.stepFunction=function(){
        setAlpha(arguments[0],arguments[1]);
    }
    var singleStep=(endAplhaPercent-startAlphaPercent)/(steps-1);
    for(var i=0;i<steps;i++){
        this.animation.stepsArgumentsArray[i]=[obj,startAlphaPercent+singleStep*i]
    }
    setAlpha(obj,0);
}
AlphaAnimation.prototype.start=function(){this.animation.start();}

ScrollDownAnimation=function(obj,steps,frequency){
    this.animation=window.animations.addAnimation();
    this.animation.frequency=frequency;
    this.animation.stepFunction=function(){
        if(arguments[2])  obj.style.overflow=arguments[2];
        setH(arguments[0],arguments[1]);
    }
    var display=obj.style.display;
    obj.style.display="block";
    var h=getH(obj);
    obj.style.display=display;
    var singleStep=(h)/(steps-1);
    for(var i=0;i<steps;i++){
        this.animation.stepsArgumentsArray[i]=[obj,singleStep*i]
    }
    this.animation.stepsArgumentsArray[i]=[obj,obj.style.heigth,obj.style.overflow]
    setH(obj,0);
    obj.style.overflow="hidden";
}
ScrollDownAnimation.prototype.start=function(){this.animation.start();}

//---------------------------------------------------------------------------------------------

function get$(s){return document.getElementById(s);}
b={ns4:(document.layers),opera:(navigator.userAgent.indexOf("Opera")!=-1),dom:(document.getElementById)}
b.ie=document.all && !b.opera;
b.ns=(b.ns4 ||(b.dom&&!b.ie)),b.ieDom=(b.ie&&b.dom),b.nsDom=(b.ns&&b.dom);
b.isMac=(navigator.appVersion.indexOf("Mac")!=-1);
b.isSafari = ( navigator.userAgent.indexOf( 'Safari' ) != -1 )
b.ie6Standard=(b.ie&&b.dom&&document.compatMode&&document.compatMode!="BackCompat");





//---------------------------------------------------------------------------------------------
//
//      D R O P   D O W N   M A N A G E R
//
//---------------------------------------------------------------------------------------------

//Used to hide DropDowns.
//Example:
//<div onmouseover="this.style.display='block'; DropDownManager.Add(this);" onmouseout="this.style.display='none'; DropDownManager.Remove(this);"
var glbLock=false;
DropDownManager={
    __queue:{},
    Add:function(obj){
        this.__queue[obj]=true;
        this.hideShowDropDowns();
    },
    Remove:function(obj){
        this.__queue[obj]=false;
        this.hideShowDropDowns();
    },
    hideShowDropDowns:function(bStatus){ 
    //alert("lock="+glbLock);
        if(glbLock) return;
        if(!b.ie) return;
        var bFinal=false;
        for(var i in this.__queue) {
            bFinal=this.__queue[i];
            if(bFinal) break;
        }
        var aDropdowns=document.getElementsByTagName("select");
        for(var i=0;i<aDropdowns.length;i++){
            aDropdowns[i].style.visibility=(!bFinal)?'visible':'hidden';
        }
    }
}
//---------------------------------------------------------------------------------------------
//
//      P O S I T I O N I N G
//
//---------------------------------------------------------------------------------------------

var mouseX=0,mouseY=0;
function getMouseXY(e) {
    if (b.ieDom) { // grab the x-y pos.s if browser is IE
        mouseX = event.clientX + document.body.scrollLeft
        mouseY = event.clientY + document.body.scrollTop
    } else {  // grab the x-y pos.s if browser is NS
        mouseX = e.pageX
        mouseY = e.pageY
    }  
    if (mouseX < 0){mouseX = 0}
    if (mouseY < 0){mouseY = 0}
    return [mouseX,mouseY]
}

setXY=function(o,nX,nY){setX(o,nX),setY(o,nY)};
//Never show a popup outside the screen!!!
setXYScreenAdjusted=function(o,nX,nY,nPadding){
    if(!nPadding) nPadding=0;
    setXY(o,nX,nY);
    if(nX+getW(o) > bodySCL()+ bodyCOW()) {
        nX=bodySCL()+bodyCOW()-getW(o)-nPadding;
        setX(o,nX);
    }
    if(nX < bodySCL()) setX(o, bodySCL()+nPadding);
    if(nY+getH(o) > bodySCT() +bodyCOH()) {
        nY=bodySCT()+bodyCOH()-getH(o)-nPadding;
        setY(o,nY);
    }
	if(nY < bodySCT()) setY(o, bodySCT()+nPadding);
};
if (b.ie && !b.dom) { //ie 5
    getX=getAbsX=function(o){return(o)?o.offsetLeft:0};
    getY=getAbsY=function(o){return(o)?o.offsetTop:0};
    getW=function(o){return(o)?o.offsetWidth:0};
    getH=function(o){return(o)?o.offsetHeight:0};
    getCW=function(o){return(o)?o.scrollWidth:0};
    getCH=function(o){return(o)?o.scrollHeight:0};
    getV=function(o){return(o.style)?o.style.visibility!='hidden':false};
    setX=function(o,n){o.style.pixelLeft=(typeof(n)=='number')?n:null};
    setY=function(o,n){o.style.pixelTop=(typeof(n)=='number')?n:null};
    setW=function(o,n){o.style.pixelWidth=(typeof(n)=='number')?n:null};
    setH=function(o,n){o.style.pixelHeight=(typeof(n)=='number')?n:null};
    setV=function(o,b){o.style.visibility=(b)?'inherit':'hidden'};
	bodyH=function(){return document.body.offsetHeight};
	bodyW=function(){return document.body.offsetWidth};
	bodyCOH=function(){return document.body.clientHeight};
	bodyCOW=function(){return document.body.clientWidth};
	bodySCL=function(){return document.body.scrollLeft};
	bodySCT=function(){return document.body.scrollTop};
	bodySCH=function(){return document.body.scrollHeight};
	bodySCW=function(){return document.body.scrollWidth};
	setAlpha=function(o,b){}
} else if (b.ieDom) {	//ie 5.5 & 6
    getX=function(o){return(o)?o.offsetLeft:0};
    getY=function(o){return(o)?o.offsetTop:0};
    getAbsX=function(o){
        var oOrig=o,oX=o.offsetLeft,o=o.offsetParent;
        if(!o) return(oOrig.style.position!='absolute')?oX:oX + bodySCL();
        while(true){
	        oX+=o.offsetLeft-o.scrollLeft
	        if (o.offsetParent) o=o.offsetParent;
	        else break;
        }
        return(oOrig.style.position!='absolute')?oX:oX + bodySCL();
    }
    getAbsY=function(o){
        var oOrig=o,oX=o.offsetTop,o=o.offsetParent;
        if(!o) return(oOrig.style.position!='absolute')?oX:oX + bodySCT();
        while(true){
	        oX+=o.offsetTop-o.scrollTop
	        if (o.offsetParent) o=o.offsetParent;
	        else break;
        }
        return(oOrig.style.position!='absolute')?oX:oX + bodySCT();
    }
    getW=getCW=function(o){return(o)?o.offsetWidth:0};
    getH=getCH=function(o){return(o)?o.offsetHeight:0};
    getV=function(o){return(o.style)?(o.style.visibility!='hidden'):false};
    getBackgroundColor=function(o){return o.style.backgroundColor};
    setClass=function(o,sC){if(sC&&o)o.className=sC};
    setX=function(o,n){o.style.left=(typeof(n)=='number')?n+'px':''};
    setY=function(o,n){o.style.top=(typeof(n)=='number')?n+'px':''};
    setW=function(o,n){o.style.width=(typeof(n)=='number')?n+'px':''};
    setH=function(o,n){o.style.height=(typeof(n)=='number')?n+'px':''};
    setV=function(o,b){o.style.visibility=(b)?'inherit':'hidden'};
    setAlpha=function(o,b){o.style.filter="alpha(style=0, opacity="+ ((b<100)?b:null) +")";}

	if(!b.ie6Standard){
		bodyH=function(){return document.body.offsetHeight};
		bodyW=function(){return document.body.offsetWidth};
		bodyCOH=function(){return document.body.clientHeight};
		bodyCOW=function(){return document.body.clientWidth};
		bodySCL=function(){return document.body.scrollLeft};
		bodySCT=function(){return document.body.scrollTop};
		bodySCH=function(){return document.body.scrollHeight};
		bodySCW=function(){return document.body.scrollWidth};
	} else {
		bodyH=function(){return document.documentElement.offsetHeight};
		bodyW=function(){return document.documentElement.offsetWidth};
		bodyCOH=function(){return document.documentElement.clientHeight};
		bodyCOW=function(){return document.documentElement.clientWidth};
		bodySCL=function(){return document.documentElement.scrollLeft};
		bodySCT=function(){return document.documentElement.scrollTop};
		bodySCH=function(){return document.documentElement.scrollHeight};
		bodySCW=function(){return document.documentElement.scrollWidth};
	}
    //-------------------------------------------------------------------------------
    //          Event Manipulation
    //-------------------------------------------------------------------------------
    IsEventCapturing=function(e){
        return false;
    }
    IsEventTargeting=function(item,e,stopBubbling){
        e=window.event;
        var ret=(item===e.srcElement);
        if(ret && stopBubbling) e.cancelBubble=true;
        return ret;
    }
    IsEventBubbling=function(item,e){
        e=window.event;
        return(e.srcElement!==item);
    }
    StopEventBubbling=function(e){
        e=window.event;
        e.cancelBubble=true;
    }
	//-------------------------------------------------------------------------------
	//          I s M o u s e O v e r O u t (object,event)
	//-------------------------------------------------------------------------------
	//Tells if the mouseover and mouseout events was real or bubbling from the childs
	//Use it onmouseout and onmouseover to kill unwanted events
	//example:
	//onmouseover="if(IsMouseOverOut(this,arguments[0])) alert('YO!')"
	
    IsMouseOverOut=function(thisel,e){
        e=(window.event)?window.event:e;
        if(!e) return false;
        if(e.type=='mouseout'){
            if(e.srcElement==thisel){
                var toel=e.toElement;
                while(toel && toel!=thisel && toel.nodeName.toLowerCase()!='body' && toel.nodeName.toLowerCase()!='html' && toel.parentNode) toel=toel.parentNode;
                if(toel!=thisel) return true;
            } else {
                var srcel=e.srcElement;
                var toel=e.toElement;
                while(toel && toel!=thisel && toel.nodeName.toLowerCase()!='body' && toel.nodeName.toLowerCase()!='html' && toel.parentNode) toel=toel.parentNode;
                while(srcel && srcel!=thisel && srcel.nodeName.toLowerCase()!='body' && srcel.nodeName.toLowerCase()!='html' && srcel.parentNode) srcel=srcel.parentNode;
                if(srcel==thisel && toel!=srcel) return true;
            }
        } else {
        if(e.srcElement==thisel) return true;
            else {
                var srcel=e.srcElement;
                var fromel=e.fromElement;
                while(fromel && fromel!=thisel && fromel.nodeName.toLowerCase()!='body' && fromel.nodeName.toLowerCase()!='html' && fromel.parentNode) fromel=fromel.parentNode;
                while(srcel && srcel!=thisel && srcel.nodeName.toLowerCase()!='body' && srcel.nodeName.toLowerCase()!='html' && srcel.parentNode) srcel=srcel.parentNode; 
                if(srcel==thisel && fromel!=thisel) return true;
            }
        }
        return false;
    }

}else if(b.ns4){
    getX=function(o){return(o)?o.left:0};
    getY=function(o){return(o)?o.top:0};
    getAbsX=function(o){return(o)?o.pageX:0};
    getAbsY=function(o){return(o)?o.pageY:0};
    getW=function(o){var e=o,n=0;if(e){n=e.clip.width;if(!typeof(n)=='number')n=e.document.width||0}return n};
    getCW=function(o){var e=o,n=0;if(e){n=e.document.width||0}return n};
    getH=function(o){var e=o,n=0;if(e){n=e.clip.height;if(!typeof(n)=='number')n=e.document.height||0}return n};
    getCH=function(o){var e=o,n=0;if(e){n=e.document.height||0}return n};
    getC=function(o){var oE=o,a=[];if(oE){a[0]=oE.clipTop,a[1]=oE.clipRight,a[2]=oE.clipBottom,a[3]=oE.clipLeft}return a};
    getV=function(o){return(o)?(o.visibility!='hide'):false};
    setX=function(o,n){if(o)o.left=(typeof(n)=='number')?n:null};
    setY=function(o,n){if(o)o.top=(typeof(n)=='number')?n:null};setW=function(o,n){if(o)o.clip.width=(typeof(n)=='number')?n:null};
    setH=function(o,n){if(o)o.clip.height=(typeof(n)=='number')?n:null};
    setC=function(nT,nR,nB,nL){var oE=o;if(oE){if(nT&&Type.isObject(nT)&&nT.length==4)nR=nT[1],nB=nT[2],nL=nT[3],nT=nT[0];oE.clip.top=nT||0,oE.clip.right=nR||0,oE.clip.bottom=nB||0,oE.clip.left=nL||0}};
    setV=function(o,b){if(o)o.visibility=(b)?'inherit':'hide'};
    bodyH=function(){return 0};
	bodyW=function(){return 0};
	bodyCOH=function(){return 0};
	bodyCOW=function(){return 0};
	bodySCL=function(){return 0};
	bodySCT=function(){return 0};
	bodySCH=function(){return 0};
	bodySCW=function(){return 0};
	setXYScreenAdjusted=function(o,nX,nY){seXY(o,nX,nY)}
	setAlpha=function(){}
} else if (b.nsDom) {   //ns6,moz1.x,ff,saf
    b.hexValues=[];
    var k = 0;
    for (var i = 0; i < 16; i ++) {
        for (var j = 0; j < 16; j ++) {
	        b.hexValues[k] = "0123456789ABCDEF".substr(i,1) + "0123456789ABCDEF".substr(j,1);
	        k ++;
        }
    }
    getX=function(o){return(o)?o.offsetLeft:0};
    getY=function(o){return(o)?o.offsetTop:0};
    getAbsX=function(o){
    var oOrig=o
        var oX=o.offsetLeft,o=o.offsetParent;
        while(o){
	        oX+=o.offsetLeft+((o.style.borderLeftWidth)?parseInt(o.style.borderLeftWidth):0)-o.scrollLeft
	        o=o.offsetParent;
        }
        if(b.isSafari) {oX-=(oOrig.style.position=='absolute')?-document.body.scrollLeft+document.body.offsetLeft:-document.body.scrollLeft;}
        return oX;
    }
    getAbsY=function(o){
        var oOrig=o;
        var oY=o.offsetTop,o=o.offsetParent;
        while(o){
	        oY+=o.offsetTop+((o.style.borderLeftWidth)?parseInt(o.style.borderTopWidth):0)-o.scrollTop
	        o=o.offsetParent;
        }
		if(b.isSafari) {oY-=(oOrig.style.position!='absolute')?-document.body.scrollTop:document.body.offsetTop-document.body.scrollTop;}
        return oY;
    }
    getW=getCW=function(o){return(o)?o.offsetWidth:0};
    getH=getCH=function(o){return(o)?o.offsetHeight:0};
    getV=function(o){return(o.style)?(o.style.visibility!='hidden'):false};
    getBackgroundColor=function(o){
        var rgb=o.style.backgroundColor;
        if(rgb.indexOf("rgb(")==0){
            var argb=rgb.split("rgb(").join("").split(")").join("").split(",");
            rgb="#";
            for(var i=0;i<3;i++){
                rgb+=b.hexValues[parseInt(argb[i])];
            }
        }
        return rgb;
    }
    setClass=function(o,sC){if(sC&&o)o.className=sC};
    setX=function(o,n){o.style.left=(typeof(n)=='number')?n+'px':''};
    setY=function(o,n){o.style.top=(typeof(n)=='number')?n+'px':''};
    setW=function(o,n){o.style.width=(typeof(n)=='number')?n+'px':''};
    setH=function(o,n){o.style.height=(typeof(n)=='number')?n+'px':''};
    setV=function(o,b){o.style.visibility=(b)?'inherit':'hidden'};
    setAlpha=function(o,b){o.style.opacity=(b<100)?b/100:0.9999;}//Avoid Flickering
	//-------------------------------------------------------------------------------
    //          Event Manipulation
    //-------------------------------------------------------------------------------
    IsEventCapturing=function(e){
        return e.eventPhase==1;
    }
    IsEventTargeting=function(item,e,stopBubbling){
        var ret=(e.eventPhase==2);
        if(stopBubbling && ret) StopEventBubbling(e);
        return ret;
    }
    IsEventBubbling=function(item,e){
        return (e.eventPhase==3);
    }
    StopEventBubbling=function(e){
        e.stopPropagation();
    }
	if(!b.isSafari){
		bodyH=function(){return document.documentElement.offsetHeight};
		bodyW=function(){return document.body.offsetWidth};
		bodyCOH=function(){return document.documentElement.clientHeight};
		bodyCOW=function(){return document.documentElement.clientWidth};
		bodySCL=function(){return document.documentElement.scrollLeft};
		bodySCT=function(){return document.documentElement.scrollTop};
		bodySCH=function(){return document.documentElement.scrollHeight};
		bodySCW=function(){return document.body.scrollWidth};
		//-------------------------------------------------------------------------------
	    //          I s M o u s e O v e r O u t (object,event)
	    //-------------------------------------------------------------------------------
		//Tells if the mouseover and mouseout events was real or bubbling from the childs
	    //Use it onmouseout and onmouseover to kill unwanted events
	    //example:
	    //onmouseover="if(IsMouseOverOut(this,arguments[0])) alert('YO!')"
	    IsMouseOverOut=function(thisel,e){ 
            tarel=e.target;
            reltarel=e.relatedTarget;
            while(tarel && tarel!=thisel && tarel.nodeName.toLowerCase()!='body' && tarel.nodeName.toLowerCase()!='html' && tarel.parentNode) tarel=tarel.parentNode;
            while(reltarel && reltarel!=thisel && reltarel.nodeName.toLowerCase()!='body' && reltarel.nodeName.toLowerCase()!='html' && reltarel.parentNode) reltarel=reltarel.parentNode;
            return (tarel== thisel && reltarel!=thisel);
        }
	} else {
		bodyH=function(){return document.documentElement.scrollHeight};
		bodyW=function(){return document.documentElement.scrollWidth};
		bodyCOH=function(){return window.innerHeight};
		bodyCOW=function(){return window.innerWidth};
		bodySCL=function(){return window.scrollX};
		bodySCT=function(){return window.scrollY};
		bodySCH=function(){return document.documentElement.scrollHeight};
		bodySCW=function(){return document.documentElement.scrollWidth};
	    //-------------------------------------------------------------------------------
	    //          I s M o u s e O v e r O u t (object,event)
	    //-------------------------------------------------------------------------------
		//Tells if the mouseover and mouseout events was real or bubbling from the childs
	    //Use it onmouseout and onmouseover to kill unwanted events
	    //example:
	    //onmouseover="if(IsMouseOverOut(this,arguments[0])) alert('YO!')"
	    IsMouseOverOut=function(o,e){
		    if (!e) var e=window.event;
		    if(!(e.type=="mouseover" || e.type=="mouseout")) return true;
            e.cancelBubble=true;
            if (e.stopPropagation) e.stopPropagation();
            
	        // Ignore all mouseover/mouseout events that have event.relatedTarget set to the same element as the element on which the event is registered.
		    if(o==e.relatedTarget) return false;
    		
		    try{ var a=event.relatedTarget.nodeName;} catch(err){ return false; }
    		
		    if(e.type=="mouseover" && e.toElement==o) {
		        var ef=e.fromElement;
		        if (ef.nodeType==3) ef=ef.parentNode;
		        while (ef != o && ef.nodeName != 'BODY'  && ef.nodeName != 'HTML') ef=ef.parentNode;
			    return (ef!=o);
		    }
		    if(e.type=="mouseout"){
		        var et=e.toElement;
		        if (et.nodeType==3) et=et.parentNode;
		        while (et != o && et.nodeName != 'BODY' && et.nodeName != 'HTML') et=et.parentNode;
			    return et!=o;
		    }
		    return true;
        }
	}
}

/*-------------------------------------------------------------------------------------------------

    P O P U P     O B J E C T S 

-------------------------------------------------------------------------------------------------*/


function setPopupMouseOver(o,e,eventName){
    //status="over"
    o.setAttribute("popupmouseover","true");
}
function setPopupMouseOut(o,e,eventName){
    //status="out"
    o.setAttribute("popupmouseover","false");
}
function isPopupMouseOver(o){
    try{
        if(o.getAttribute("popupmouseover")=="true") return true;
        o=getPopupChild(o);
        if(o) return isPopupMouseOver(o);
        return false;
    } catch(e){
        return false;
    }
}

function getPopupParent(o){
    try{return get$(o.getAttribute("parentId"));}
    catch(e){return null;}
}
function getPopupChild(o){
    try{return get$(o.getAttribute("childId"));}
    catch(e){return null;}
}   
function bindPopupParentChild(p,c){
    p.setAttribute("childId",c.id);
    c.setAttribute("parentId",p.id);
}
function setPopupParentMouseOut(p,e,timeout){
    if(!timeout) timeout=0;
    //if(b.ns && !isNSMouseOverOutValid(p,e)) return;
    if(!IsMouseOverOut(p,e)) return;
    setTimeout("var p=get$('" + p.id +"'); setPopupParentMouseOutHelper(p,"+ timeout +"); ",200);
}
function setPopupParentMouseOutHelper(p,timeout){
    if(!timeout) timeout=0;
    setPopupMouseOut(p);
    var c=getPopupChild(p);
    if(!c) return;
    if(isPopupMouseOver(c)) {
        c.closerTimeout = setTimeout("var p=get$('" + p.id +"'); var c=getPopupChild(p); if(!isPopupMouseOver(c)) {c.style.display='none'; DropDownManager.Remove(c);}",timeout);
    } else {
    c.closerTimeout = setTimeout("\
            var c=get$('" + c.id +"');\
            c.style.display='none';\
            DropDownManager.Remove(c);",timeout);
    }
}
function setPopupChildMouseOut(c,e,timeout,bubbling){
    if(!timeout) timeout=100;
    //if(b.ns && !isNSMouseOverOutValid(c,e)) return;
    if(!bubbling && !IsMouseOverOut(c,e)) return;
    setPopupMouseOut(c);
    c.closerTimeout = setTimeout("\
			var c=get$('" + c.id +"');\
            var timeout="+ timeout +";\
			var p=getPopupParent(c);\
            if(!isPopupMouseOver(c)) {\
                c.style.display='none';\
				if(getPopupParent(p)) {setPopupChildMouseOut(p,null,timeout/2,true);}\
                DropDownManager.Remove(c);\
             }\
             ",timeout);
}
//p=parent object
//e=event
//timeout=how long before to trigger the event (default=0)
//position=where the popup should appear (bottomleft,topleft,etc)
//effect=trigger alpha transictions=number of transictions (default=20)
//transictions=
function setPopupParentMouseOver(p,e,timeout,position,effect,transictions){
    if(!timeout) timeout=0;
    if(!transictions) transictions=20;
    //if(b.ns && !isNSMouseOverOutValid(p,e)) return;
    if(!IsMouseOverOut(p,e)) return;
    setPopupMouseOver(p);
	//p.onmousemove=function(){setPopupMouseOver(this);}
    var c=getPopupChild(p);
    var s="var p=get$('" + p.id +"');\
                var c=getPopupChild(p);\
                if(isPopupMouseOver(p)) {\
                setPopupParentMouseOverHelper(p,c,'" + position + "','" + effect +"'," +transictions+ ");}\
                 "
    setTimeout(s,timeout);
}
function setPopupParentMouseOverHelper(p,c,position,effect,transictions){
    var popUpPosX,popUpPosY;
    if(c.style.display=='block') return;
    var effectManager;
    if(effect){
        switch(effect){
            case "Alpha":effectManager=new AlphaAnimation(c,transictions,20,0,100); break;
            case "ScrollDown":effectManager=new ScrollDownAnimation(c,transictions,12); break;
        }
    }
    c.style.display='block';
    if(c.closerTimeout) clearTimeout(c.closerTimeout);
    DropDownManager.Add(c);
    switch(position){
        case "center":
            popUpPosX=getAbsX(p)-Math.round((getW(c)-getW(p))/2);
            popUpPosY=getAbsY(p)-Math.round((getH(c)-getH(p))/2);
        break;
        case "bottomleft":
            popUpPosX=getAbsX(p);
            popUpPosY=getAbsY(p)+getH(p);
        break;
		case "bottommenu":
            popUpPosX=getAbsX(p);
            popUpPosY=getAbsY(p)+getH(p)-5;
        break;
		case "bottom":
            popUpPosX=getAbsX(p);
            popUpPosY=getAbsY(p)+getH(p);
        break;
        case "topleft":
            popUpPosX=getAbsX(p)-2;
            popUpPosY=getAbsY(p);
        break;
        default: //Default: "x,y"
            if(position.indexOf(",")>0){
                aPosition=position.split(",");
                popUpPosX=parseInt(aPosition[0])
                popUpPosY=parseInt(aPosition[1])
            }
    }
    setXYScreenAdjusted(c,popUpPosX,popUpPosY,5)
    if(effect) effectManager.start();  
}

function setPopupChildMouseOver(c,e){
    //if(b.ns && !isNSMouseOverOutValid(c,e)) return;
    if(!IsMouseOverOut(c,e)) return;
    if(c.closerTimeout) clearTimeout(c.closerTimeout);
    setPopupMouseOver(c);
    c.style.display='block';
    DropDownManager.Add(c);
	c.onmousemove=function(){DropDownManager.Add(this);}
}




/*-------------------------------------------------------------------------------------------------

    P A L E T T E    M A N A G E R 

-------------------------------------------------------------------------------------------------*/
PaletteManager={
	getColor:function(x,colorArray) {
		var val=0; 
		var col =  parseInt(x / this.columnWidth);
		var colPercent = (x -  (col * this.columnWidth)) / this.oneColumnPercent;
		// percentage between 255
		var d = colorArray[col+1] - colorArray[col];
		if (d == 255) {
			val = parseInt(colPercent * (255/100) +'');
		} else if (d == - 255) {
			val = parseInt((100 - colPercent) * (255/100) +'');
		} else {
			val = colorArray[col];
		}
		var ret=parseInt(''+val);
		if(ret<0) ret=0 
		else if(ret>255) ret=255;
		return ret;
	},
	getBrightness:function(y,val) {
		var hpalette=getH(this.Palette);
		
		if (y < hpalette/2) {
			var maxVal = 255;
			var minVal = val;
			var onePercInterval = (maxVal - minVal)/100;
			
			if(y==0) val=maxVal
			else if(y==hpalette/2) val=0
			else {
				var curPercent = 2*(50 - (y * 100)/hpalette) ;
				val += curPercent * onePercInterval;
			}
		} else {
			var maxVal = val;
			var minVal = 0;
			var onePercInterval = (maxVal - minVal)/100;
			var curPercent = 2*( y-(hpalette/2)) * 100 / hpalette;
			val -= curPercent * onePercInterval;
		}
		var ret=parseInt(''+val);
		if(ret<0) ret=0 
		else if(ret>255) ret=255;
		return ret;
	},
	setColor:function(x,y) {
		x-=getAbsX(this.Palette),y-=getAbsY(this.Palette)
		var r = this.getBrightness(y,this.getColor(x,this.aR));
		var g = this.getBrightness(y,this.getColor(x,this.aG));
		var b = this.getBrightness(y,this.getColor(x,this.aB));
		var color=this.Display.style.backgroundColor="#" + this.hexValues[r] + this.hexValues[g] + this.hexValues[b];;
		return color;
	},
	setGray:function(y) {
		y-=getAbsY(this.GrayPalette)
		var g = parseInt((255 - (255 * (y*100/getH(this.Palette))/100))+'');
		if(g<0) g=0;
		else if(g>255) g=255;
		var color=this.Display.style.backgroundColor="#" + this.hexValues[g] + this.hexValues[g] + this.hexValues[g];;
		return color;
	},
	//Palette is the image used as palette
	//Display is the object used to display the current color
	//Recorder is the object that will store the actual image onmousedown
	init:function(Palette, GrayPalette, Display, Recorder){
		this.Palette=Palette;
		this.GrayPalette=GrayPalette;
		this.Display=Display;
		this.Recorder=Recorder;
		//filling HEX Array of values
		this.hexValues=[];
		var k = 0;
		for (var i = 0; i < 16; i ++) {
			for (var j = 0; j < 16; j ++) {
				this.hexValues[k] = "0123456789ABCDEF".substr(i,1) + "0123456789ABCDEF".substr(j,1);
				k ++;
			}
		}
		//in our virtual columns we set the available content ov a specific color
		this.aR = new Array (255,255,0,0,0,255,255,255);//last 2 values are added just for the math
		this.aG = new Array (0,255,255,255,0,0,0,0);
		this.aB = new Array (0,0,0,255,255,255,0,0);
		//Contsnt, can't be changed unless we change the whole mat
		this.numberOfColums = 6;
		this.columnWidth = getW(this.Palette) / this.numberOfColums;
		this.oneColumnPercent = this.columnWidth/100;
		
		//Event Handling
		this.Palette.onmousemove=function(){
			var coords=getMouseXY(arguments[0]);
			var color=PaletteManager.setColor(coords[0],coords[1]);
		}
		this.Palette.onmousedown=function(){
		    if(!PaletteManager.Recorder) return;
			PaletteManager.Recorder.style.backgroundColor=PaletteManager.Display.style.backgroundColor;
		}		
		this.GrayPalette.onmousemove=function(){
			var coords=getMouseXY(arguments[0]);
			var color=PaletteManager.setGray(coords[1]);
		}
		this.GrayPalette.onmousedown=function(){
		    if(!PaletteManager.Recorder) return;
			PaletteManager.Recorder.style.backgroundColor=PaletteManager.Display.style.backgroundColor;
		}
	}
}
/*-------------------------------------------------------------------------------------------------

    Q U E R Y   S T R I N G   M A N A G E R

-------------------------------------------------------------------------------------------------*/

QueryStringManager={
    __queryString:null,
    SetQueryString:function(qs){
        if(!qs) qs="";
        if(qs.indexOf("?")!=0) qs="?"+qs;
        this.__queryString=qs;
    },
    GetQueryString:function(bWithoutQuestionMark){
        this.__queryString=this.__queryString.split("&&&&&").join("&").split("&&&&").join("&").split("&&&").join("&").split("&&").join("&").split("?&").join("?");//Lazy Bug solver
        return (bWithoutQuestionMark)?this.__queryString.substr(1):this.__queryString;
        
    },
    Remove:function(key){
        if(this.__queryString.indexOf(key+"=")==-1) return;
        var iStart=this.__queryString.indexOf(key+"=");
        var iEnd=this.__queryString.indexOf("&",iStart);
        if(iEnd==-1){
            this.__queryString=this.__queryString.substring(0,iStart);
        } else {
            this.__queryString=this.__queryString.substring(0,iStart)+this.__queryString.substr(iEnd);
        }
    },
    Add:function(key,value){
        this.Remove(key);
        if(this.__queryString.length>1) this.__queryString+="&";
        this.__queryString+=key + "=" + value;
    },
    Get:function(key){
        if(this.__queryString.indexOf(key+"=")==-1) return null;
        var iStart=this.__queryString.indexOf(key+"=");
        var iEnd=this.__queryString.indexOf("&",iStart);
        if(iEnd==-1){
            return this.__queryString.substr(iStart).split(key+"=").join("");
        } else {
            return this.__queryString.substring(iStart,iEnd).split(key+"=").join("");
        }
    },
    Set:function(key,value){
        this.Add(key,value);
    },
    Clear:function(){
        this.__queryString="?";
    },
    ToObject:function(){
        var o={};
        if(this.__queryString.length==1) return o;
        var qs=this.__queryString.substr(1);
        var qsa=qs.split("&");
        for(var i=0;i<qsa.length;i++){
            if(qsa[i]){
                var qsa2=qsa[i].split("=");
                o[qsa2[0]]=qsa2[1];
            }
        }
        return o;
    },
    ToQueryString:function(obj){
        var qs="?";
        var bFirst=true;
        for(var i in obj) {
            if(!bFirst) qs+="&";
            bFirst=false;
            qs+=i+"="+obj[i];
        }
        this.__queryString=qs;
        return qs;
    },
    //window.location.href=QueryStringManager.ReplaceOnUrl();
    ReplaceOnUrl:function(){
        var href=window.location.href;
        if(href.indexOf("?")==-1) href+=this.__queryString;
        else href=href.substring(0,href.indexOf("?"))+this.__queryString;
        return href;
    }
}
/*-------------------------------------------------------------------------------------------------

    S U B M I T   E V E N T   M A N A G E R

-------------------------------------------------------------------------------------------------*/
SubmitEventManager={
    __handlers:{},
    AddHandler:function(oFunction,oObj){
        this.__handlers[oObj.id]=oFunction;
        var form=getAspNetForm();
        if(form.onsubmit==null){
            form.onsubmit=function(){
                var ret=true;
                var partialRet=null;
                for(i in SubmitEventManager.__handlers) {
                    partialRet=SubmitEventManager.__handlers[i](get$(i));
                    if(typeof(partialRet)=='boolean') ret=partialRet;
                }
                return ret; //decides wheter to submit or not the form
            }
        }
    }
}
/*-------------------------------------------------------------------------------------------------

    P O P U P   B L O C K E R   D E T E C T I O N

-------------------------------------------------------------------------------------------------*/

function detectPopupBlocker(fnBlockerNotDetected,fnBlockerDetected) {
  var myTest = false;
  try{
    myTest=window.open("about:blank","","directories=no,height=100,width=100,menubar=no,resizable=no,scrollbars=no,status=no,titlebar=no,top=0,location=no");
  } catch(e){}
  if (!myTest) fnBlockerDetected();
  else {
    myTest.close();
    fnBlockerNotDetected();
  }
}