var DOM = (typeof(document.getElementById) != 'undefined');

function GetObj(objId){
	if(!DOM) return false;
	return document.getElementById(objId);
}

function Trim(str){
	if(str == undefined) return;

	str=str.replace(/ +$/, "");
	str=str.replace(/^ +/, "");
	return str;
}

function ShowImg(path, width, height){
	margin_left = GetScreenMargin(self.screen.width, width);
	margin_top = GetScreenMargin(self.screen.height, height);

	window.open(path, 'fullimg', 'left=' + margin_left + ',top=' + margin_top + ',width='+width+',height='+height+',menubar=no,scrollbars=no,status=no');
}

function GetScreenMargin(screen, popup){
	if(popup > screen) return 0;
	margin = screen - popup;
	margin = margin/2;
	margin = Math.round(margin);
	return margin;
}

function ShowPopup(path, width, height, name, scroll, add_param){
	if(scroll == 'undefined') scroll = 'no';
	margin_left = GetScreenMargin(self.screen.width, width);
	margin_top = GetScreenMargin(self.screen.height, height);
	param = 'left=' + margin_left + ',top=' + margin_top + ',width=' + width + ',height=' + height + ',menubar=no,scrollbars=' + scroll + ',status=no';
	if(add_param != 'undefined') param += add_param;
	window.open(path, name, param);
}

function GetAbsoluteTop(obj){
   var result = 0;
   while(obj.tagName != 'BODY'){
     result += obj.offsetTop;
     obj = obj.offsetParent;
   }

   return result;
}

function GetAbsoluteLeft(obj){
   var result = 0;
   while(obj.tagName != 'BODY'){
     result += obj.offsetLeft;
     obj = obj.offsetParent;
   }

   return result;
}

function CheckOrderMode(obj){
	if(obj.value != -1){
		GetObj('o_mode').disabled = false;
	}
	else{
		GetObj('o_mode').disabled = true;
	}
}

function DisplHideAF(id_name){
	obj = GetObj(id_name);

	if(!obj) return;
	if(obj.style.display == 'none'){
		obj.style.display = '';
	}
	else{
		obj.style.display = 'none';
	}

}

function GetFlash(path, width, height, link, parametr){
	if(link){
		if(parametr != ''){parametr += '&';}
		parametr += 'link='+link;
	}
	document.open();
	document.write('<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version="6,0,0,0" WIDTH="'+width+'" HEIGHT="'+height+'">');
	document.write('<PARAM NAME="wmode" VALUE="transparent">');
	document.write('<PARAM NAME="movie" VALUE="' + path + '">');
	document.write('<PARAM NAME="quality" VALUE="high">');
	document.write('<PARAM NAME="FlashVars" VALUE="' + parametr + '">');
	document.write('<EMBED src="' + path + '" wmode="transparent" quality="high" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" WIDTH="' + width + '" HEIGHT="' + height + '" FlashVars="' + parametr + '" TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash"></EMBED>');
	document.write('</OBJECT>');
	document.close();
}

function RefreshAntispam(path, objId){
	if(!DOM) return false;
	antispam = GetObj(objId);
	path = path + '?rnd='+Math.random();
	antispam.src=path;
}

function getHexRGBColor(color){
  color = color.replace(/\s/g,"");
  var aRGB = color.match(/^rgb\((\d{1,3}[%]?),(\d{1,3}[%]?),(\d{1,3}[%]?)\)$/i);

  if(aRGB)
  {
    color = '';
    for (var i=1;  i<=3; i++) color += Math.round((aRGB[i][aRGB[i].length-1]=="%"?2.55:1)*parseInt(aRGB[i])).toString(16).replace(/^(.)$/,'0$1');
  }
  else color = color.replace(/^#?([\da-f])([\da-f])([\da-f])$/i, '$1$1$2$2$3$3');

  return color;
}

function rgb2hex(r,g,b){
  return Number(r).toString(16).toUpperCase().replace(/^(.)$/,'0$1') +
         Number(g).toString(16).toUpperCase().replace(/^(.)$/,'0$1') +
         Number(b).toString(16).toUpperCase().replace(/^(.)$/,'0$1');
}
