String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}
String.prototype.ltrim = function() {
	return this.replace(/^\s+/,"");
}
String.prototype.rtrim = function() {
	return this.replace(/\s+$/,"");
}

function trimC(str, chars) {
    return ltrimC(rtrimC(str, chars), chars);
}

function ltrimC(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}

function rtrimC(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}


//var clickmessage="Copyright. Please use HTML code under the photo.";
//......

function popImgLarge(){
	var imgURL = $("imgURLLarge" + _activeImgRow).value;
	var width = 1020;
	var height = 780;
	var left = parseInt((screen.availWidth/2) - (width/2));
	var top = parseInt((screen.availHeight/2) - (height/2));
	var windowParams = "width=" + width + ",height=" + height + ",toolbar=no, location=no,directories=no,status=no,menubar=no,scrollbars=no,copyhistory=no, resizable=yes, " +
					   "left=" + left + ",top=" + top + "screenX=" + left + ",screenY=" + top;
	window.open(imgURL,'mywindow',windowParams)
}

function tmpCashe(){
   var now = new Date()
   var hours = now.getHours()
   var minutes = now.getMinutes()
   var seconds = now.getSeconds()
   return hours + "_" + minutes + "_" + seconds;
}

function show_hideCats(contentId, linkId, lang){
	if ( $(contentId).style.display == 'none' ){
		$(contentId).style.display = '';
		$(linkId).src = '/images/seeless_' + lang + '.gif';
	}else{
		$(contentId).style.display = 'none';
		$(linkId).src = '/images/seemore_' + lang + '.gif';
	}
}

function selectActiveCat(cat_id){
	if (cat_id == 0 || cat_id=='') return;
	if ( $('cat' + cat_id) !=null){
		$('cat' + cat_id).className = "activeCat";
	}
}

var _SITE_VIEW = null;
var _SITE_ID = null;
var _LANG = "en";
var _CAT = null;
var _IMG = null;
var _CURRENT_PATH_CAT = null;
var _DOMAIN_NAME = "http://" + document.domain;
function setVars(lang,cat,img,current_path_cat, siteId,siteView){
	_SITE_ID = siteId;
	_SITE_VIEW = siteView;
	setLang(lang);
	setCat(cat);
	setIMG(img);
	_CURRENT_PATH_CAT = current_path_cat;
	if(window.location.hash!=''){
		 window.location.replace(_CURRENT_PATH_CAT + "/" + window.location.hash.substr(1) + ".html");
	}
}

function  getCurrentPageURL(){
	var retVal = window.location.href;
	if(window.location.hash!=''){
	 	retVal =  document.domain + "/" + _CURRENT_PATH_CAT + "/" + window.location.hash.substr(1) + ".html";
		retVal = retVal.replace("//","/");
		retVal = "http://" + retVal;
	}
	return retVal;
}
function getCurrentPageTitle(){
	//alert(document.title);
	return $("imgTitle").innerHTML;
	//return document.title;
}

function setLang(lang){
	_LANG = lang;
}
function setCat(cat){
	_CAT = cat;
}
function setIMG(img){
	_IMG = img;
}
function SlideShow(){
	//window.open("/slideshow.php?cat_id=" + _CAT + "&l=" + _LANG, "", "fullscreen=yes, toolbar=no, resizable=1, scrollbars=1, menubar=no");
	window.open("/slideshow.php?cat_id=" + _CAT + "&l=" + _LANG, "", "width=1000, height=750, toolbar=no, resizable=1, scrollbars=1, menubar=no");
}

function SendCard(){
	window.location = "/send_card.php?img=" + _IMG + "&lang=" + _LANG;
}
function Puzzle(){
	window.location = "/puzzle.php?i=" + _IMG + "&lang=" + _LANG;
}

function Comment(postId){
	var url = "/popComment.php?lang=" + _LANG + "&imgId=" + _IMG + "&postId=" + postId + "&tmpCashe=" + tmpCashe();
	if(window.showModalDialog!=null){
		var oResponse = window.showModalDialog(url, '', 'dialogHeight:440px; dialogWidth:520px)');
		if(oResponse!=null){
			populatePost(oResponse);
		}
	}else{
		window.open(url, '', 'height=420, width=520)');
	}
}

function populatePost(oResponse){
	if ( $("post" + oResponse.postId) == null){
		$("comments").innerHTML =  "<LABEL id='post" + oResponse.postId + "'>" + oResponse.content + "</LABEL>" + $("comments").innerHTML;
	}else{
		$("post" + oResponse.postId).innerHTML = oResponse.content;
	}
}


//-------------------- TOP MENU --------------------------------
var _TM_ActiveDiv = 1;
var _TM_loadedMenu = new Array();
var _TM_menuTimer;
var __isJsTopMenuLoaded = false; //set in "/cached/" + _SITE_VIEW + "/TopMenu_" + _LANG + ".js"
function TM_isLoadedTopMenuJS(){
	if(__isJsTopMenuLoaded) return true;
	if( $("jsTopMenu") == null){
		//$("jsTopMenu") == object -> in process now
		var jsURL = "/cached/" + _SITE_VIEW + "/TopMenu_" + _LANG + ".js";
		loadScript(jsURL, "jsTopMenu", "TM_setLoadedTopMenuFlag");
		return false;
	}
}

function TM_setLoadedTopMenuFlag(){
	_TM_isLoadedTopMenuJS = true;
}

function TM_showMenu(divNum){
	if (!TM_isLoadedTopMenuJS()){
		setTimeout("TM_showMenu(" + divNum + ")",1);
		return;
	}
	
	var divName = "TM_DDNav_" + divNum;
	clearTimeout(_TM_menuTimer);
	TM_doHideAll();
	
	activeMenu = $(divName);
	if(_TM_loadedMenu[divNum]!=null){
		_TM_ActiveDiv = divNum;
	}else{
		if( $("subTM_DDNav_" + divNum).innerHTML =="") $("subTM_DDNav_" + divNum).innerHTML = TM_getMenuContent(divNum);
		_TM_loadedMenu[divNum] = 1;
	}
	activeMenu.style.visibility = 'visible';

}

function TM_hideMenu(divNum){
	_TM_menuTimer = setTimeout("TM_doHide('TM_DDNav_" + divNum + "')",50);
}
function TM_doHideAll(){
	for (var x = 1; x <= 2; x++){
		$("TM_DDNav_" + x).style.visibility = 'hidden';
	}
}
function TM_doHide(divName){
	activeMenu = eval('document.getElementById("' + divName + '")');
	activeMenu.style.visibility = 'hidden';
}

function TM_getMenuContent(divNum){
	var retVal = "";
	if(divNum==1){
		retVal = Cached_TopMenuGEO();
	}else{
		retVal = Cached_TopMenuTopical();
	}
	return retVal;
}

function loadScript(sScriptSrc, jsID, oCallback) {
	var oHead = document.getElementsByTagName('head')[0];
	var oScript = document.createElement('script');
	oScript.type = 'text/javascript';
	oScript.src = sScriptSrc;
	oScript.id = jsID;
	// most browsers
	//oScript.onload = oCallback;
	// IE 6 & 7
	/*
	oScript.onreadystatechange = function() {
		if (this.readyState == 'loaded' || this.readyState == 'complete'){
			//oCallback();
			_TM_isLoadedTopMenuJS = true;
		}
	}
	*/
	oHead.appendChild(oScript);
}
//------------------ END TOP MENU ------------------------------