


function getElementStyle(elemID, IEStyleProp, CSSStyleProp)
{
    var elem = document.getElementById(elemID);
    return getElementStyleByEl(elem, IEStyleProp, CSSStyleProp) ;
}
function getElementStyleByEl(elem, IEStyleProp, CSSStyleProp)
{
    if(!elem)
    {
        return ;
    }
    
    if (elem.currentStyle) {
        return elem.currentStyle[IEStyleProp];
    } else if (window.getComputedStyle) {
        var compStyle = window.getComputedStyle(elem, "");
        return compStyle.getPropertyValue(CSSStyleProp);
    }
    return "";
}



function getElementsByClass(elem, classname) 
{
    classes = new Array();
    alltags = document.getElementsByTagName(elem);
    for (i=0; i<alltags.length; i++)
        if (alltags[i].className == classname)
            classes[classes.length] = alltags[i];
    return classes;
}

function openwinj(url, widthj, heightj)
{
    widthj = parseInt(widthj) + 50 ;
    
    if(widthj < 350)
    {
        widthj += (350 - widthj) ;
    }
    
    heightj = parseInt(heightj) + 80 ;

    var screenw = screen.width ;
    if(widthj > (screenw - 100))
    {
        widthj = screenw - 100 ;
    }

    var screenh = screen.height ;
    if(heightj > (screenh - 100))
    {
        heightj = screenh - 100 ;
    }

	posX=(screen.width-widthj)/2;
	posY=(screen.height-heightj)/2;
    var features = "'screenX=" + posX + ",left=" + posX + ",posY=" + posY + ",top=" + posY + ",location=no, menubar=no, status=no, toolbar=no, scrollbars=yes, resizable=yes,width=" + widthj + ", height=" + heightj + "'" ;

    t = window.open(url, 'newwinj', features);
    
    /*
	t.moveTo(posX,posY); 
    */
  
}



function setScroll()
{
    if(!document.getElementById)
    {
        return true ;
    }

    inputPosX = document.getElementById('kp_positionX') ;
    inputPosY = document.getElementById('kp_positionY') ;
    
    if(!inputPosX || !inputPosY)
    {
        return ;
    }

	var X ;
	var Y ;
	
	X = parseInt(inputPosX.value) ;
	Y = parseInt(inputPosY.value) ;
    
    //alert(Y) ;


	if((X > 0)||(Y > 0))
	{
		if((top.opera)&&(typeof window.pageYOffset != 'undefined'))
		{
			window.scrollTo(X,Y) ;
			//window.pageYOffset = Y;
			//window.pageXOffset = X;
		}
		else if((window.document.compatMode)&& (window.document.compatMode != 'BackCompat'))
		{
			window.document.documentElement.scrollLeft = X;
			window.document.documentElement.scrollTop = Y;
		}
		else if((window.document.body)&& (typeof window.document.body.scrollTop != 'undefined'))
		{
			window.document.body.scrollLeft = X;
			window.document.body.scrollTop = Y;
		}
		else
		{
			window.scrollTo(X, Y);
		}
	}
}


function keepPosition()
{
    if(!document.getElementById)
    {
        return true ;
    }
    
    inputPosX = document.getElementById('kp_positionX') ;
    inputPosY = document.getElementById('kp_positionY') ;
    
    if(!inputPosX || !inputPosY)
    {
        return ;
    }


	var X, Y;
	if(typeof window.pageXOffset != 'undefined')
	{
		X = window.pageXOffset;
		Y = window.pageYOffset;
	}
	else
	{
		if((!window.document.compatMode)|| (window.document.compatMode == 'BackCompat'))
		{
			X = window.document.body.scrollLeft;
			Y = window.document.body.scrollTop;
		}
		else
		{
			X = window.document.documentElement.scrollLeft;
			Y = window.document.documentElement.scrollTop;
		}
	}

	inputPosX.value = X ;
	inputPosY.value = Y ;
    

    return true ;
}

function emptyPagePosition()
{
    if(!document.getElementById)
    {
        return true ;
    }
    
    inputPosX = document.getElementById('kp_positionX') ;
    inputPosY = document.getElementById('kp_positionY') ;
    
    if(!inputPosX || !inputPosY)
    {
        return ;
    }
    
	inputPosX.value = 0 ;
	inputPosY.value = 0 ;
    
    return true ;
}



function endsWith(str, needle)
{
    pos = str.lastIndexOf(needle) ;

    if(pos != -1 && str.length - needle.length == pos)
    {
        return true ;
    }
    
    return false ;
}

function moveSubMenu()
{
    var el = document.getElementById("subMenuWrapper") ;

    var el_left = findPosX(el) ;
    var el_top = findPosY(el) ;
    
    if(el_top == 0)
    {
        return ;
    }
    
    var el2 = document.getElementById("Menu1") ;

    if(el2)
    {
        el2.style.left = (el_left - 135) + "px" ;
        el2.style.top = (el_top - 235) + "px" ;
    }  
    
    el2.style.display = "block" ;
    el2.style.visibility = "visible" ; 
}


//================================================
// Images rollover
//
// Image names must be:
// myImage.ext // normal
// myImage_hi.ext // highlighted
//================================================

// To overwrite on each page
var imagesToRoll = Array() ;

// To overwrite on each page
var imagesToPreload = Array() ;
var loadedPic = Array() ;

// Preload Images
function preloadImages()
{
    // image to preload
    for(i = 0 ; i < imagesToPreload.length ; i++)
    {
        var imgData = imagesToPreload[i] ;
        var pic = new Image();
        pic.src = imgData ; 
        
        if(loadedPic.push)
        {
            loadedPic.push() ;
        }
        
    }
    
    // images to preload and roll
    for(i = 0 ; i < imagesToRoll.length ; i++)
    {
        var imgData = imagesToRoll[i] ;
        var pic = new Image();
        pic.src = imgData[1] ; 
        
        if(loadedPic.push)
        {
            loadedPic.push() ;
        }
    } 
}

function imagesRollOver()
{
    for(i = 0 ; i < imagesToRoll.length ; i++)
    {
        var imgData = imagesToRoll[i] ;
        
        var img = document.getElementById(imgData[0]) ;
        
        if(!img)
        {
            return ;
        }
        
        newmouseover=function()
        {
            var posDot = this.src.lastIndexOf('.') ;
            var name = this.src.substring(0, posDot) ;
            var extension = this.src.substring(posDot) ;
            this.src = name + "_hi" + extension ;
        }     
        img.onmouseover = newmouseover ;
        
        newmouseout=function()
        {
            var posDot = this.src.lastIndexOf('.') ;
            var name = this.src.substring(0, posDot) ;
            var extension = this.src.substring(posDot) ;
            this.src = name.substring(0, name.length - 3) + extension ;
        }
        img.onmouseout = newmouseout ;
    } 
}  





function Trim(TRIM_VALUE){
if(TRIM_VALUE.length < 1){
return"";
}
TRIM_VALUE = RTrim(TRIM_VALUE);
TRIM_VALUE = LTrim(TRIM_VALUE);
if(TRIM_VALUE==""){
return "";
}
else{
return TRIM_VALUE;
}
} //End Function

function RTrim(VALUE){
var w_space = String.fromCharCode(32);
var w_lf = String.fromCharCode(10);
var w_cr = String.fromCharCode(13);

var v_length = VALUE.length;
var strTemp = "";
if(v_length < 0){
return"";
}
var iTemp = v_length -1;

while(iTemp > -1){
if(VALUE.charAt(iTemp) == w_space || VALUE.charAt(iTemp) == w_lf || VALUE.charAt(iTemp) == w_cr){
}
else{
strTemp = VALUE.substring(0,iTemp +1);
break;
}
iTemp = iTemp-1;

} //End While
return strTemp;

} //End Function

function LTrim(VALUE){
var w_space = String.fromCharCode(32);
var w_lf = String.fromCharCode(10);
var w_cr = String.fromCharCode(13);

if(v_length < 1){
return"";
}
var v_length = VALUE.length;
var strTemp = "";

var iTemp = 0;

while(iTemp < v_length){
if(VALUE.charAt(iTemp) == w_space || VALUE.charAt(iTemp) == w_lf || VALUE.charAt(iTemp) == w_cr){
}
else{
strTemp = VALUE.substring(iTemp,v_length);
break;
}
iTemp = iTemp + 1;
} //End While
return strTemp;
} //End Function



function findPosX(obj)
{
    if(!obj)
    {
        return 0;
    }
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj)
{
    if(!obj)
    {
        return 0;
    }
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}



function _addbr(unDiv, nbrBR)
{
    var divLength = unDiv.offsetWidth ;
    
    var divChild= unDiv.childNodes ;
    for(var i = 0 ; i < divChild.length; i++)
    {
        var innerEl= divChild[i] ;
        
        var innerElWidth = innerEl.offsetWidth ;
    
        //alert(innerElWidth + " - " + divLength) ;
        
        
        if(innerElWidth > divLength)
        {
            for(var j = 0 ; j < nbrBR; j++)
            {
                var newBr = document.createElement("br") ;

                unDiv.appendChild(newBr) ;
            }

            unDiv.style.overflowX = "auto" ;
            unDiv.style.overflowY = "hidden" ; 
            
            break ;
        }
    }
}


function addBreakLineIfOverflow(elementClass, elementId)
{
    // needed for IE only
    if(BrowserDetect.browser != "Explorer")
    {
        return ;
    }

    for(var classPos = 0 ; classPos < elementClass.length; classPos++)
    {
        var className = elementClass[classPos][0] ;
        var allClassEl = getElementsByClass("div", className) ;
        
        var nbr = allClassEl.length ;
        for(var i = 0 ; i < nbr; i++)
        {
            _addbr(allClassEl[i], elementClass[classPos][1]) ; 
        }  
    }

    for(var idPos = 0 ; idPos < elementId.length; idPos++)
    {
        var elId = elementId[idPos][0] ;
        var oneEl = document.getElementById(elId) ;

        if(oneEl)
        {
            _addbr(oneEl, elementId[idPos][1]) ;
        } 
    }
}









function querystring(newParams)
{
    if(newParams == "")
    {
        return window.location.search ;
    }

    if(window.location.search.length >= 1)
    {
        queryTemp = window.location.search.substring(1, window.location.search.length);
    }
    else
    {
        queryTemp = "" ;
    }
    
    oldPairs = queryTemp.split('&') ;
    
    queryFinal = "?" ;
    for(var i=0; i < newParams.length; i++) 
    {
        var newKey = newParams[i].split('=')[0] ;
        var foundInOld = false ;
        for(var j=0; j < oldPairs.length; j++) 
        {
            var oneOldVar =  oldPairs[j].split('=') ;

            if(oneOldVar[0] == newKey)
            {
                oldPairs[j] = newParams[i] ;
                foundInOld = true ;
                break ;
            }
        }  
        
        if(!foundInOld)
        {
            oldPairs[oldPairs.length] = newParams[i] ;
        } 
    }
    
    for(var i=0; i < oldPairs.length; i++) 
    {
        if(oldPairs[i] != "")
        {
            queryFinal += oldPairs[i] + "&" ;
        }
    }

    queryFinal = queryFinal.substring(0, queryFinal.length - 1);

    return queryFinal ;
}


function safeHTML(msg, nl2br)
{
    if(nl2br)
    {
        return msg.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/\n/g,"<br />") ;
    }
    else
    {
        return msg.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;") ;
    }         
}

function BBCodeToHTML(msg)
{

    // [i]
    msg = msg.replace(/\[i\](.*?)\[\/i\]/gi,'<i>$1</i>'); 
    
    // [b]
    msg = msg.replace(/\[b\](.*?)\[\/b\]/gi,'<b>$1</b>'); 
    
    // [url]
    msg = msg.replace(/\[url\]((http)+(s)?:(\/\/)|(www\.))(.*?)\[\/url\]/gi,'<a href=\"http$3://$5$6\" rel=\"nofollow\">$1$6</a>'); 
    
    // [url=XXX]
    msg = msg.replace(/\[url=((http)+(s)?:(\/\/)|(www\.))(.*?)\](.*?)\[\/url\]/gi,'<a href=\"http$3://$5$6\" rel=\"nofollow\">$7</a>'); 
    
    // [mailto]
    msg = msg.replace(/\[mailto\]([_a-z0-9-]+)(\.[_a-z0-9-]+)*@([a-z0-9-]+)(\.[a-z0-9-]+)*(\.[a-z]{2,4})\[\/mailto\]/gi,'<a href=\"mailto:$1$2@$3$4$5\">$1$2@$3$4$5</a>'); 
    
    // [img]
    msg = msg.replace(/\[img\](.*?)\[\/img\]/gi,'<span class=\"imgdiv\"><img src=\"$1\" /></span>'); 
    
    // [url=XXX][img]
    msg = msg.replace(/\[url=(.*?)\]\[img\](.*?)\[\/img\]\[\/url\]/gi,'<a href=\"$1\" rel=\"nofollow\"><span class=\"imgdiv\"><img src=\"$2\" /></span></a>'); 

    return msg ;
}



function setCookie(cookieName, cookieValue, nDays) 
{
    var today = new Date();
    var expire = new Date();
    if (nDays==null || nDays==0) nDays=1;
    expire.setTime(today.getTime() + 3600000*24*nDays);
    document.cookie = cookieName+"="+escape(cookieValue) + ";expires="+expire.toGMTString() + "; path=/";
}

function loginClick()
{
    setCookie("toplogin", true, 1) ;
    return true ;
}

function swapDiv(divToHide, divToShow)
{
    var div1 = document.getElementById(divToHide) ;
    var div2 = document.getElementById(divToShow) ;
    if(div1 && div2)
    {
        div1.style.display = 'none' ;
        div2.style.display = 'block' ;
    }
}

if(typeof Array.prototype.push === 'undefined') 
{
 Array.prototype.push = function() {
  for( var i = 0, b = this.length, a = arguments, l = a.length; i<l; i++ ) {
   this[b+i] = a[i];
  }
  return this.length;
 };
}

if(typeof Array.prototype.splice === 'undefined') 
{
    Array.prototype.splice = function(index, delTotal) 
    {
        var temp = new Array()
        var response = new Array()
        var A_s = 0
        for (A_s = 0; A_s < index; A_s++) {
        temp[temp.length] = this[A_s]
        }
        for (A_s = 2; A_s < arguments.length; A_s++) {
        temp[temp.length] = arguments[A_s]
        }
        for (A_s = index + delTotal; A_s < this.length; A_s++) {
        temp[temp.length] = this[A_s]
        }
        for (A_s = 0; A_s < delTotal; A_s++) {
        response[A_s] = this[index + A_s]
        }
        this.length = 0
        for (A_s = 0; A_s < temp.length; A_s++) {
        this[this.length] = temp[A_s]
        }
        return response
    } ;
}




// http://www.quirksmode.org/js/detect.html
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.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"
		},
		{		// 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() ;
