
//This is the Miscellaneous Library (Version 1.1)

function addParam(name, value){
		
	if(navigator.appName=="Netscape"){
		var param;
		param=document.createElement("param");
		param.name=name;
		param.value=value;
		this.appendChild(param);								
	}
	else{
		this.setAttribute(name, value);
	}
}
function getParam(param) {
	urlquery=location.href.split("?");
	window.alert(urlquery[1]);
}


var ADDMsgWindow;
function message(str) {

// Displays a message in a new window, useful for debugging

	var p;

	if (typeof(ADDMsgWindow)!="object")
		ADDMsgWindow=window.open();
	p=ADDMsgWindow.document.createElement("p");
	p.innerHTML=str;
	ADDMsgWindow.document.body.appendChild(p);
}





function linkImage(imgArray){
var i, image, imageArray=new Array();
        //return image array object with the pictures,link and id
        for(i=0;i<imgArray.length;i++){
                image=new Image();
                image.src=imgArray[i].path;
                image.style.position="absolute";
                clearMargins(image);

                imageArray[i]= new Object();
                imageArray[i].pictures=image;
                imageArray[i].pictures.link=imgArray[i].link
                imageArray[i].pictures.onclick=linkImageClick;
                imageArray[i].pictures.id=imgArray[i].id
        }
        return imageArray;
}


function searchBetween(str, stringToSearch){

var returnValue;
        //this function will return a string
        //between the character of strignSearch
        //ex. you have a string like 21-4-5
        //it will return you 4
        first=str.indexOf(stringToSearch);
        last=str.lastIndexOf(stringToSearch);
        returnValue="";
        for(i=first+1;i<last;i++){
                returnValue+=str.charAt(i);
        }
        return returnValue
}


function compareDate(date1, date2) {
    // returns 0 if equal, returns positive if date1 > date 2, returns negative id date 1< date2
        var tmp1, tmp2;

        tmp1=date1.getFullYear()*10000+date1.getMonth()*100+date1.getDate();
        tmp2=date2.getFullYear()*10000+date2.getMonth()*100+date2.getDate();
        return (date1-date2);
}


function stringSearch(str, findWhat, findNext){
var pos1, pos2;
        //this function will search a string of the given string in str variable,
        //return true if the string is present otherwise false
        if(typeof(str)=="undefined" || typeof(findWhat)=="undefined" ){
                return null;
        }
        else{
                pos1=str.indexOf(findWhat);
                pos2=str.indexOf(findNext);
                if(pos1>0 || pos2>0){
                        return true;
                }
                else{
                        return false;
                }
        }
}


function rectangle() {
        // This function returns a rectangle object
        // It supports all the common elements of an HTML object
        // A DIV element does not seem to work, because of an apparent minimum height requirement
        // This means we use a trick which requires the "Empty.gif" picture
        var rect;

        rect=new Image();
        rect.src="images/empty.gif";
        rect.style.position="absolute";
        clearMargins(rect);
        return rect;
}


function copy_clip(text){

        if (window.clipboardData){
                // for IE
                window.clipboardData.setData("Text", text);
   }
   else if (window.netscape) {
                // for nestcape browser
                netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
                //creating data object
                var clip = Components.classes['@mozilla.org/widget/clipboard;1'].createInstance(Components.interfaces.nsIClipboard);
                if (!clip) return;
                // use to create transferable

                var trans = Components.classes['@mozilla.org/widget/transferable;1'].createInstance(Components.interfaces.nsITransferable);
                if (!trans) return;

                //set the dataFlavor
                trans.addDataFlavor('text/unicode');

                // ask for transfer data need to create new object
                var len = new Object();
                var str = Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString);
                var copytext=text;
                str.data=copytext;
                // object for the out parameter

                /* the length is multiplied by two because we
                        are using a Unicode string which requires two bytes per character.
                */
                trans.setTransferData("text/unicode",str,copytext.length*2);

                var clipid=Components.interfaces.nsIClipboard;
                if (!clip)
                        return false;
                clip.setData(trans,null,clipid.kGlobalClipboard);
   }
   return false;
}


function getClipboard(){
        // the getClipboard function is use to retrieve the content of the clipboard it's work on IE and Mozilla
  if(window.clipboardData){
                 return(window.clipboardData.getData("Text"))
  }
  else if (window.netscape){
                netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");

                // create the transferable
                var clip = Components.classes["@mozilla.org/widget/clipboard;1"].createInstance(Components.interfaces.nsIClipboard);
                if(!clip){
                        return ;
                }

                var trans = Components.classes['@mozilla.org/widget/transferable;1'].createInstance(Components.interfaces.nsITransferable);
                 if(!trans){
                         return ;
                }

                // register the data flavor we use the "text/unicode"
                trans.addDataFlavor("text/unicode");
                clip.getData(trans,clip.kGlobalClipboard);

                var  str =new Object();
                var len =new Object();

                /* this code is use to prevent the error i experience which is
                 "Error: uncaught exception: [Exception... "Component returned failure
                code: 0x80004005 (NS_ERROR_FAILURE) [nsITransferable.getTransferData]
                nsresult: "0x80004005 (NS_ERROR_FAILURE)"*/
                try{trans.getTransferData("text/unicode",str,len);}
                catch(error){return;}
                // get the data from transfering object
                if(str){
                        if(Components.interfaces.nsISupportsWString){
                                 str=str.value.QueryInterface(Components.interfaces.nsISupportsWString);
                        }
                        else if(Components.interfaces.nsISupportsString){
                                 str=str.value.QueryInterface(Components.interfaces.nsISupportsString);
                        }
                        else{
                                str =null;
                        }
                }
                if(str)
                        str=str.data.substring(0,len.value/2);              
        }
  return str ;
}


function openWindow(url, left, top, width, height){
        var win;
        winWidth1=width;
        winHeight1=height;
        winTop1=top;
        winLeft1=left;
        winDesign="\'toolbar=1,scrollbar=1,location=0,align=\"center\",statusbar=1,menubar=0,resizable=1,width="+winWidth1+",height="+winHeight1+",top="+winTop1+",left="+winLeft1+"\'";
        if(navigator.appName=="Microsoft Internet Explorer"){
                win=window.open(url,'window', winDesign);
        }
        else{
                win=window.open(url,'window');
        }
        win.focus();
        return win;
}


function navigate(page) {
		window.location.href=page;
}


function myUniqueId() {

        if (typeof(unIdOb)=="undefined") {
                unIdOb=new Object();
                unIdOb.id1=0;
                unIdOb.id2=0;
                unIdOb.startCharNum="A".charCodeAt(0);
        }

        if (unIdOb.startCharNum<"Z".charCodeAt(0)){
                unIdOb.startCharNum++;
        } else {
                unIdOb.startCharNum="A".charCodeAt(0);
                if (unIdOb.id1<=9999)
                        unIdOb.id2++;
                else {
                        unIdOb.id1++;
                        unIdOb.id2=0;
                }
        }
        return String.fromCharCode(unIdOb.startCharNum)+"myUnId"+unIdOb.id1+"_"+unIdOb.id2;
}

function msgNum(string, num)

        {
        message(string+num);
        }
		

function proper(s) {
        // returns a capitalized string from input string s
        // returns empty string if type of s is not string
        var retStr, l;

        if (typeof(s)!="string")
                return "";
        else {
                switch (s.length) {
                        case 0:
                                return "";
                        case 1: {
                                retStr=s;
                                return retStr.toUpperCase();
                        }
                        default: {
                                retStr=s.substr(0,1);
                                retStr=retStr.toUpperCase();
                                retStr=retStr+s.substr(1);
                                return retStr;
                        }
                }
        }
}


var scrollerObjects=new Array(), scrollerIdNum;
var debug=0;

function internalScrollerFunc(Index) {

var currentXPos, currentDiv, i, l, obj, scrollerObject, div0, div1, zIndex, div0Style, div1Style;

scrollerObject=scrollerObjects[Index];

if (scrollerObject.inInternalScroller) // First check if we are not inside the scroller. We would be in big trouble otherwise.
        return;
//else left out
scrollerObject.inInternalScroller=true; // we are in the function with this object

// First some initizalization to speed things up (we hope) and improve readability
div0=scrollerObject.div0;
div1=scrollerObject.div1;
div0Style=div0.style;
div1Style=div1.style;
style=scrollerObject.style;
zIndex=scrollerObject.style.zIndex;

// First we check if we have to resize
if ((scrollerObject.style.left!=scrollerObject.div0.style.left)||
        (scrollerObject.style.top!=scrollerObject.div0.style.top)||
        (scrollerObject.style.width!=scrollerObject.div0.style.width)||
        (scrollerObject.style.height!=scrollerObject.div0.style.height)) {
        // We have to resize
        scrollerObject.div0.style.left=scrollerObject.style.left;
        scrollerObject.div1.style.left=scrollerObject.style.left;
        scrollerObject.div0.style.top=scrollerObject.style.top;
        scrollerObject.div1.style.top=scrollerObject.style.top;
        scrollerObject.div0.style.width=scrollerObject.style.width;
        scrollerObject.div1.style.width=scrollerObject.style.width;
        scrollerObject.div0.style.height=scrollerObject.style.height;
        scrollerObject.div1.style.height=scrollerObject.style.height;
}

currentDivIndex=scrollerObject.currentDivIndex;

// We first show everything that's there. We prepare for the next cycle afterwards. At least one object should be there, otherwise it should never be called.
if (currentDivIndex==0) { // we show DIV 0, which should be below DIV 1
                div0Style.visibility="visible";
        i=0;
        l=div0.childNodes.length;
        while (i<l) {
                div0.childNodes[i].style.visibility="visible";
                i++;
        }
        // and hide DIV 1, which is supposed to be the trick to show DIV 0, because it's on top
        div1.style.visibility="hidden";
        i=0;
        l=div1.childNodes.length;
        while (i<l) {
                div1.childNodes[i].style.visibility="hidden";
                i++;
        }
        //now we increase the Z-index for DIV 0 so it is the top DIV and decrease it for DIV 1
        div0Style.zIndex=zIndex; // nothing should happen
        i=0;
        l=scrollerObject.div0.childNodes.length;
        for (i=0;i<l;i++)
                div0.childNodes[i].style.zIndex=zIndex;
        div1.style.zIndex=zIndex-1;
        i=0;
        l=div1.childNodes.length;
        for (i=0;i<l;i++)
                div1.childNodes[i].style.zIndex=zIndex-1;
} // end of showing of DIV 0
else { // we show DIV 1, which should be below DIV 0
        div1.style.visibility="visible";
        i=0;
        l=div1.childNodes.length;
        while (i<l) {
                div1.childNodes[i].style.visibility="visible";
                i++;
        }
        // now we increase the Z-index for DIV 0 (which is visible), so it's on top, and decrease it for DIV 1, so we can prepare without any problems.
        scrollerObject.div0.style.visibility="hidden";
        i=0;
        l=div0.childNodes.length;
        while (i<l) {
                div0.childNodes[i].style.visibility="hidden";
                i++;
        }
        div1.style.zIndex=zIndex; // nothing should happen
        i=0;
        l=div1.childNodes.length;
        for (i=0;i<l;i++)
                div1.childNodes[i].style.zIndex=zIndex;
        div0.style.zIndex=zIndex-1;
        i=0;
        l=scrollerObject.div0.childNodes.length;
        for (i=0;i<l;i++)
                div0.childNodes[i].style.zIndex=zIndex-1;
} // end of showing of DIV 1

// the current div is on top and shown, the other is below and hidden
// we are going to prepare for the next cycle

if (currentDivIndex==0) { // we are going to prepare for the next cycle for DIV 1
        scrollerObject.currentDivIndex=1;
        currentDiv=scrollerObject.div1;
        scrollerObject.currentXOffset1-=scrollerObject.pixelMove2; // we are decreasing the X-offset to prepare for the next cycle
        currentXPos=scrollerObject.currentXOffset1; // we want to keep track of the current x-position
        i=0;
        l=currentDiv.childNodes.length;
        //we move all childNodes to the left
        while (i<l) {
                currentDiv.childNodes[i].style.left=currentXPos+"px";
                currentXPos+=currentDiv.childNodes[i].offsetWidth; // we want to keep track of the current x-position
                i++;
        }

        // all childNodes are at the appropriate place, now we have to check whether we have to add or remove objects
        // first of course the check of adding, otherwise we might en up without any objects
        while (currentXPos<currentDiv.offsetWidth) { // we have to add objects
                if (scrollerObject.currentObjectIndex1<scrollerObject.objects.length-1) // find next object first
                        scrollerObject.currentObjectIndex1++;
                else
                        scrollerObject.currentObjectIndex1=0;
                // now at the current Object
                obj=scrollerObject.objects[scrollerObject.currentObjectIndex1].cloneNode(true);
                currentDiv.appendChild(obj);
                obj.style.position="absolute";
                obj.style.top="0px";
                obj.style.left=currentXPos+"px";
                currentXPos+=obj.offsetWidth;
        }
        // now we remove childNodes at the front, this might not be efficient, but otherwise we have to keep track of free nodes
        currentXPos=scrollerObject.currentXOffset1; // we already increased the pixels
        obj=currentDiv.firstChild;
        currentXPos+=obj.offsetWidth;
        while (currentXPos<0) {
                currentXPos+=obj.offsetWidth;
                scrollerObject.currentXOffset1+=obj.offsetWidth;
                currentDiv.removeChild(obj);
                obj=currentDiv.firstChild;
        }
} // we prepared DIV 1 for the next cycle
else { // we are going to prepare for the next cycle for DIV 0
        scrollerObject.currentDivIndex=0;
        currentDiv=scrollerObject.div0;
        scrollerObject.currentXOffset0-=scrollerObject.pixelMove2; // we are decreasing the X-offset to prepare for the next cycle
        currentXPos=scrollerObject.currentXOffset0; // we want to keep track of the next x-position
        i=0;
        l=currentDiv.childNodes.length;
        //we move all childNodes to the left
        while (i<l) {
                currentDiv.childNodes[i].style.left=currentXPos+"px";
                currentXPos+=currentDiv.childNodes[i].offsetWidth; // we want to keep track of the next x-position
                i++;
        }
        // all childNodes are at the appropriate place, now we have to check whether we have to add or remove objects
        // first of course the check of adding, otherwise we might en up without any objects
        while (currentXPos<currentDiv.offsetWidth) { // we have to add objects
                if (scrollerObject.currentObjectIndex0<scrollerObject.objects.length-1) // find next object first
                        scrollerObject.currentObjectIndex0++;
                else
                        scrollerObject.currentObjectIndex0=0;
                // now at the current Object
                obj=scrollerObject.objects[scrollerObject.currentObjectIndex0].cloneNode(true);
                currentDiv.appendChild(obj);
                obj.style.position="absolute";
                obj.style.top="0px";
                obj.style.left=currentXPos+"px";
                currentXPos+=obj.offsetWidth;
        }
        // now we remove childNodes at the front, this might not be efficient, but otherwise we have to keep track of free nodes
        currentXPos=scrollerObject.currentXOffset0; // we already increased the pixels
        obj=currentDiv.firstChild;
        currentXPos+=obj.offsetWidth;
        while (currentXPos<0) {
                currentXPos+=obj.offsetWidth;
                scrollerObject.currentXOffset0+=obj.offsetWidth;
                currentDiv.removeChild(obj);
                obj=currentDiv.firstChild;
        }
} // we prepared DIV 0 for the next cycle
scrollerObject.inInternalScroller=false;
}

function scroller(objects, direction, pixelLeft, pixelTop, pixelWidth, pixelHeight, speed, zIndex) {

        var scrollerObject, i, name1, name2, intervalTime, pixelMove, mrq, innerw, innerh, innerx, innery, currentxpos, obj, obj0, obj1;

        if (typeof(objects)=="undefined") return null;
        if (objects==null) return null;
        if (objects.length==0) return null;
        if (pixelWidth<=0) return null;
        if (pixelHeight<=0) return null;
        if (typeof(zIndex)!="number")
                zIndex=1;

        if (typeof(scrollerIdNum) == "undefined")
                scrollerIdNum=0;
        else
                scrollerIdNum++;

        scrollerObjects[scrollerIdNum]=new Object();

        if (direction!="horizontal") {
                alert("Method "+direction+" not supported");
                return;
        }

        // we create the basic div element
        scrollerObjects[scrollerIdNum].div=createBasicDiv(pixelLeft, pixelTop, pixelWidth, pixelHeight);
        scrollerObject=scrollerObjects[scrollerIdNum];
        scrollerObjects[scrollerIdNum].id=myUniqueId();
        scrollerObjects[scrollerIdNum].name=scrollerObjects[scrollerIdNum].id;

        // we create two div elements for alternate showing
        scrollerObjects[scrollerIdNum].div0=document.createElement("DIV");
        scrollerObjects[scrollerIdNum].div0.id="scrollerDiv"+scrollerIdNum+"_0";
        document.body.appendChild(scrollerObjects[scrollerIdNum].div0);

        scrollerObjects[scrollerIdNum].div1=document.createElement("DIV");
        scrollerObjects[scrollerIdNum].div1.id="scrollerDiv"+scrollerIdNum+"_1";
        document.body.appendChild(scrollerObjects[scrollerIdNum].div1);

        scrollerObjects[scrollerIdNum].div0.backgroundColor=document.body.style.backgroundColor;
        scrollerObjects[scrollerIdNum].div1.backgroundColor=document.body.style.backgroundColor;
        //scrollerObjects[scrollerIdNum].div0.style.position="absolute";
        scrollerObjects[scrollerIdNum].div0.style.position="absolute";
        scrollerObjects[scrollerIdNum].div1.style.position="absolute";
        scrollerObjects[scrollerIdNum].div0.style.overflow="hidden";
        scrollerObjects[scrollerIdNum].div1.style.overflow="hidden";
        scrollerObjects[scrollerIdNum].div0.style.zIndex=zIndex;
        scrollerObjects[scrollerIdNum].div1.style.zIndex=zIndex-1;
        scrollerObjects[scrollerIdNum].div0.style.width=pixelWidth+"px";
        scrollerObjects[scrollerIdNum].div1.style.width=pixelWidth+"px";
        scrollerObjects[scrollerIdNum].div0.style.height=pixelHeight+"px";
        scrollerObjects[scrollerIdNum].div1.style.height=pixelHeight+"px";
        scrollerObjects[scrollerIdNum].div0.style.left=(scrollerObjects[scrollerIdNum].div.offsetLeft+scrollerObjects[scrollerIdNum].div.offsetParent.offsetLeft)+"px";
        scrollerObjects[scrollerIdNum].div1.style.left=(scrollerObjects[scrollerIdNum].div.offsetLeft+scrollerObjects[scrollerIdNum].div.offsetParent.offsetLeft)+"px";
        scrollerObjects[scrollerIdNum].div0.style.top=(scrollerObjects[scrollerIdNum].div.offsetTop+scrollerObjects[scrollerIdNum].div.offsetParent.offsetTop)+"px";
        scrollerObjects[scrollerIdNum].div1.style.top=(scrollerObjects[scrollerIdNum].div.offsetTop+scrollerObjects[scrollerIdNum].div.offsetParent.offsetTop)+"px";

        scrollerObjects[scrollerIdNum].objects=objects; // make pointer to objects;

        scrollerObjects[scrollerIdNum].horizontal=true; // for now we only support horizontal
        scrollerObjects[scrollerIdNum].style=new Object();
        scrollerObjects[scrollerIdNum].style.left=pixelLeft+"px";
        scrollerObjects[scrollerIdNum].style.top=pixelTop+"px";
        scrollerObjects[scrollerIdNum].style.width=pixelWidth+"px";
        scrollerObjects[scrollerIdNum].style.height=pixelHeight+"px";
        scrollerObject.style.zIndex=zIndex;

        scrollerObjects[scrollerIdNum].currentObjectIndex0=0;
        scrollerObjects[scrollerIdNum].currentObjectIndex1=0;

        scrollerObject=scrollerObjects[scrollerIdNum];

        if (speed=="undefined") {
                pixelMove=5;
                intervalTime=100; }
        else {
                pixelMove=Math.round(speed/25);
                if (pixelMove<1)
                        pixelMove=1;
                pixelMove=2;
                intervalTime=Math.round(speed/pixelMove);
                intervalTime=20;
                scrollerObjects[scrollerIdNum].intervalTime=intervalTime;
                scrollerObjects[scrollerIdNum].pixelMove=pixelMove;
        }

        scrollerObject.currentDivIndex=0; // this is the one we're going to show first
        // we append one object to each DIV for initialization;
        obj=objects[0];
        obj0=obj.cloneNode(true);
        obj1=obj.cloneNode(true);
        scrollerObjects[scrollerIdNum].div0.appendChild(obj0);
        scrollerObjects[scrollerIdNum].div1.appendChild(obj1);
        obj0.name="object0";
        obj1.name="object1";
        obj0.style.position="absolute";
        obj1.style.position="absolute";
        obj0.style.zIndex=zIndex;
        obj1.style.zIndex=zIndex-1;
        scrollerObjects[scrollerIdNum].currentXOffset0=0;
        scrollerObjects[scrollerIdNum].currentXOffset1=pixelMove; // it is moved one pixelmove
        scrollerObjects[scrollerIdNum].pixelMove2=2*pixelMove; // each DIV moves twice the number we want to see

        scrollerObjects[scrollerIdNum].inInternalScroller=false;
        internalScrollerFunc(scrollerIdNum);
        scrollerTimer=window.setInterval("internalScrollerFunc("+scrollerIdNum+")", intervalTime);
        return scrollerObjects[scrollerIdNum];
} // end of function scroller