var agt=navigator.userAgent.toLowerCase();
var is_major = parseInt(navigator.appVersion);
var is_mozilla = (agt.indexOf('gecko') != -1);
var is_ie     = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
var m_space = 0;
var m_space_left = -250;
//if(is_mozilla) m_space = 0;
if(is_ie && $.browser.version < 8) m_space_left = -583;
var menu_on_load = '';
var timeoutPop;
function findPosXY( obj )
{
	var curleft = 0;
	var curtop = 0;

	try
	{

			if (obj.offsetParent) {

				while (obj.offsetParent) {

					if(obj.offsetParent.offsetParent==null)
						break;

					curleft += obj.offsetLeft;
					curtop  += obj.offsetTop;
					obj = obj.offsetParent;

				}
			}
			else
			{
				if (obj.x) curleft += obj.x;
				if (obj.y) curtop  += obj.y;
			}
	}catch(ex){}

	var retObj = new Object();
	retObj.left = curleft;
	retObj.top  = curtop;

	return retObj;
}

function findPosX(obj)
{
	var curleft = 0;

	try
	{
			if (obj.offsetParent) {
				while (obj.offsetParent) {
					if(obj.offsetParent.offsetParent==null)
						break;
					curleft += obj.offsetLeft;
					obj = obj.offsetParent;
				}
			} else if (obj.x) curleft += obj.x;
	}catch(ex){}

	return curleft;
}

function parseStylePX( size )
{
	if( typeof(size) == "string" )
	{
		if( size.charAt(size.length -2) + "" + size.charAt(size.length -1) == "px" )
			size = parseInt(size.substr( 0, size.length -2 ));
		else
			size = parseInt(size);
	}
	if( isNaN(size) ) size = 0;
	return 	size;
}


function findPosY(obj) {
	var curtop = 0;

	try
	{
		if (obj.offsetParent) {
			while (obj.offsetParent) {
				if(obj.offsetParent.offsetParent.offsetParent==null)
						break;
				curtop += obj.offsetTop;
				obj = obj.offsetParent;
			}
		} else if (obj.y) curtop += obj.y;
	}catch(ex){}
	return curtop;
}
function getMouseXY(e) {
  var XY={x:0, y:0};
  var tempX, tempY;
  /*if (event.clientX){
   tempX = event.clientX + (document.documentElement.scrollLeft ?
   document.documentElement.scrollLeft :
   document.body.scrollLeft);
   tempY = event.clientY + (document.documentElement.scrollTop ?
   document.documentElement.scrollTop :
   document.body.scrollTop);
  }else if (evt.pageX){
	tempX = evt.pageX;
	tempY = evt.pageY
  }*/
  
  if (document.all) { // 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
  }
  // catch possible negative values in NS4
  if (tempX < 0){tempX = 0}
  if (tempY < 0){tempY = 0}  
  XY.x = tempX;
  XY.y = tempY;
  return XY
}
function mouseMove(e){
	var cXY = getMouseXY(e);
	document.getElementById('cX').value = cXY.x;
	document.getElementById('cY').value = cXY.y;
}
function popupMenu(el, popup){
	if(menu_on_load != '' && menu_on_load != popup && timeoutPop){
		if(document.getElementById(menu_on_load)) setStyle(document.getElementById(menu_on_load), 'display:none;');
		//clearTimeout(timeoutPop);
		//menu_on_load = '';
	}
	if(document.getElementById(popup)){
		clearTimeout(timeoutPop);
		//var posXY = findPosXY(el);
		var popupDiv = document.getElementById(popup);
		if(popupDiv.style.display == 'none'){
			var left = findPosX(el) + m_space + m_space_left;
			var top = el.offsetHeight + m_space;
			var textStyle = "width:"+el.offsetWidth+"px;left:"+left+"px;top:"+top+"px;display:;";
			setStyle(popupDiv, textStyle);
			popupDiv.onmouseover = function(){
				clearTimeout(timeoutPop);
				setStyle(this, 'display:');
			}
			popupDiv.onmouseout = function(){
				setStyle(this, 'display:none');
			}
		}
	}
}
function popupMenuOut(el){
	//clearTimeout(timeoutPop);
		if(document.getElementById(el)) timeoutPop = setTimeout("setStyle(document.getElementById('"+el+"'), 'display:none;')",600);
	menu_on_load = el;
	//var t=setTimeout("alert('5 seconds!')",5000)
}

var menu_on_load2 = '';
function rightMenu(el, popup){
	if(menu_on_load2 != '' && menu_on_load2 != popup && timeoutPop){
		if(document.getElementById(menu_on_load2)) setStyle(document.getElementById(menu_on_load2), 'display:none;');
		//clearTimeout(timeoutPop);
		//menu_on_load2 = '';
	}
	if(document.getElementById(popup)){
		clearTimeout(timeoutPop);
		//var posXY = findPosXY(el);
		var popupDiv = document.getElementById(popup);
		if(popupDiv.style.display == 'none'){
			var left = findPosX(el) + el.offsetWidth + m_space;
			var top = findPosY(el) + m_space;
			var textStyle = "width:"+el.offsetWidth+"px;left:"+left+"px;top:"+top+"px;display:;";
			setStyle(popupDiv, textStyle);
			popupDiv.onmouseover = function(){
				clearTimeout(timeoutPop);
				setStyle(this, 'display:');
			}
			popupDiv.onmouseout = function(){
				setStyle(this, 'display:none');
			}
		}
	}
}
function rightMenuOut(el){
	//clearTimeout(timeoutPop);
		if(document.getElementById(el)) timeoutPop = setTimeout("setStyle(document.getElementById('"+el+"'), 'display:none;')",600);
	menu_on_load2 = el;
	//var t=setTimeout("alert('5 seconds!')",5000)
}
function setStyle(el, prop) {
	if (document.all) {
		var props = prop.split(';');
		for (var i = 0; i < props.length; i++) {
			var attrib = props[i].split(':');
			if(attrib[0] != '' && attrib[0] != 'undefined') eval("el.style."+attrib[0]+"='"+attrib[1]+"';");
		}
	}else{
			var cssText = el.style.cssText;
			var cssTexts = cssText.split(';');
			var props = prop.split(';');
			var strcssText = '';
			for (var i = 0; i < cssTexts.length; i++) {
				var cssTextattrib = cssTexts[i].split(':');
				var usecssTextattrib = 1;
				for (var j = 0; j < props.length; j++) {
					var attrib = props[j].split(':');
					if(attrib[0] == '' || attrib[0] == ' ' || attrib[0] == 'undefined'){
						continue;
					}else if(Trim(attrib[0]) == Trim(cssTextattrib[0])){
						usecssTextattrib = 0;
						break;
					}
				}
				if(usecssTextattrib == 1 && cssTextattrib[0] != '' && cssTextattrib[0] != ' ' && cssTextattrib[0] != 'undefined'){
					strcssText += cssTextattrib[0] + ':' + cssTextattrib[1] + ';';
				}
			}
			el.setAttribute("style", strcssText + prop);
	}
}
function Trim(text){
    return text.replace(/^\s*|\s*$/g,'');
}

function LTrim(text){
    return text.replace(/^\s*/g,'');
}

function RTrim(text){
    return text.replace(/\s*$/g,'');
}
function takeYear(theDate)
{
	var x = theDate.getYear();
	var y = x % 100;
	y += (y < 38) ? 2000 : 1900;
	return y;
}

// Popup

var popUp = null;

function pop(url)
{
	if (popUp && !popUp.closed)
		popUp.location.href = url;
	else
		popUp = window.open(url,'popUp','height=500,width=700,scrollbars=yes,resizable=yes,toolbar=yes,location=yes');
	popUp.focus();
	return false;
}

// Cookies

function createCookie(name,value,days)
{
	if (days)
	{
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name)
{
	var nameEQ = 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(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name)
{
	createCookie(name,"",-1);
}

function checkItLocal(string)
{
	placeOfDetect = detect.indexOf(string) + 1;
	thestring = string;
	return placeOfDetect;
}

function getElementsByTagNames(list,obj)
{
	if (!obj) var obj = document;
	var tagNames = list.split(',');
	var resultArray = new Array();
	for (var i=0;i<tagNames.length;i++)
	{
		var tags = obj.getElementsByTagName(tagNames[i]);
		for (var j=0;j<tags.length;j++)
		{
			resultArray.push(tags[j]);
		}
	}
	var testNode = resultArray[0];
	if (testNode.sourceIndex)
	{
		resultArray.sort(function (a,b) {
				return a.sourceIndex - b.sourceIndex;
		});
	}
	else if (testNode.compareDocumentPosition)
	{
		resultArray.sort(function (a,b) {
				return 3 - (a.compareDocumentPosition(b) & 6);
		});
	}
	return resultArray;
}

// push and shift for IE5

function Array_push() {
	var A_p = 0
	for (A_p = 0; A_p < arguments.length; A_p++) {
		this[this.length] = arguments[A_p]
	}
	return this.length
}

if (typeof Array.prototype.push == "undefined") {
	Array.prototype.push = Array_push
}

function Array_shift() {
	var A_s = 0
	var response = this[0]
	for (A_s = 0; A_s < this.length-1; A_s++) {
		this[A_s] = this[A_s + 1]
	}
	this.length--
	return response
}

if (typeof Array.prototype.shift == "undefined") {
	Array.prototype.shift = Array_shift
}
//document.onmousemove = popupMenu;
//document.onmousedown =  popupMenu;
//document.oncontextmenu = function(){ return false; };
