var xmlHttp;
var xhr = null;
var DOMAIN_SUFFIX = '.ro';
var ROOT_URL = document.location.href.substr(0, document.location.href.indexOf(DOMAIN_SUFFIX+'/'))+DOMAIN_SUFFIX+'/';
var RESOURCES_URL = ROOT_URL+'&resources/';
var PLAYLIST_URL = ROOT_URL+"play.html";
var PLAYLIST_OBJECT_URL = ROOT_URL+"play/"+"object.php?id=";
var __view_identifier__ = 'mgallery';


// This script sets OSName variable as follows:
// "Windows"    for all versions of Windows
// "MacOS"      for all versions of Macintosh OS
// "Linux"      for all versions of Linux
// "UNIX"       for all other UNIX flavors
// "Unknown OS" indicates failure to detect the OS

var OSName="Unknown OS";
if (navigator.appVersion.indexOf("Win")!=-1) OSName="Windows";
if (navigator.appVersion.indexOf("Mac")!=-1) OSName="MacOS";
if (navigator.appVersion.indexOf("X11")!=-1) OSName="UNIX";
if (navigator.appVersion.indexOf("Linux")!=-1) OSName="Linux";

function initAjax() {
	  try
		{
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
		}
	  catch (e)
		{
		// Internet Explorer
		try
		  {
		  xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		  }
		catch (e)
		  {
		  try
			{
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			}
		  catch (e)
			{
			return false;
		  }
		}
	  }
}


function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop];
}


function showAddOptions(obj) {

	obj.style.height = 'auto';
	obj.style.cursor = 'default';
	fsets = obj.getElementsByTagName('fieldset');
	fsets[0].style.border = '1px solid #000;';

}


function checkTags(obj) {

	//var tags = obj.value.split(" ");

	initAjax();

	xmlHttp.open('GET', ROOT_URL+"edit.php?action=checkTag&clean=true&param1="+obj.value,true);
	xmlHttp.send(null);

	xmlHttp.onreadystatechange = function(){
		if (xmlHttp.readyState == 4) {

			var responses = xmlHttp.responseText.split("|");

			for (i = 0; i < responses.length; i++) {

				var declare = responses[i].split(",");
				var tagUsageObj = document.getElementById('tagUsage');

				tagUsageObj.style.display = 'block';
				opts = tagUsageObj.options;
				var set = 0;
				for (j = 0; j < opts.length; j++) {
					if (opts[j].value == declare[0]+"("+declare[1]+")") {
						set++;
					}
				}

				if(declare[1] >= 0) {
					if (set == 0) {
						tagUsageObj.options[tagUsageObj.length] = new Option(declare[0]+"("+declare[1]+")",declare[0]+"("+declare[1]+")");
					}
				}
				else {
					if (set == 0) {
						tagUsageObj.options[tagUsageObj.length] = new Option("[Junk]"+declare[0]);
					}
				}
			}

		}
	}

	return false;
}


function fillReplyForm(obj) {

	var parentID = document.getElementById('parentID');
	var mg_titleInput = document.getElementById('mg_titleInput');
	var mg_descriptionInput = document.getElementById('mg_descriptionInput');

	var h3s = obj.getElementsByTagName('h3');
	var divs = obj.getElementsByTagName('div');

	for (i=0; i<h3s.length; i++) {
		mg_titleInput.value = 'Re: '+h3s[i].innerHTML;
	}

	parentID.value = obj.id.replace("comment", "");
	showContainer('addCommentForm', '1');

}


function deleteComment(commentID, objID, confirmMessage) {

	if (confirm(confirmMessage)) {

		initAjax();
		xmlHttp.open('GET', ROOT_URL+"edit.php?action=deleteComment&clean=true&param1="+commentID+"&param2="+objID,true);
		xmlHttp.send(null);

		xmlHttp.onreadystatechange = function(){
			if (xmlHttp.readyState == 4) {
				reloadWithoutTarget();
			}
		}
	}
}

function reloadWithoutTarget() {

	var loc = document.location.href.split("#");
	document.location.href = loc[0];

}

function reloadWithTarget() {
	var curUrl = document.location.href
	document.location.href = curUrl;
}


function switchToDelete() {
	document.getElementById('activeInput').value = 0;
}

function switchToApprove() {
	document.getElementById('approveInput').value = 1;
}


function binaryVote(voteValue, params, extra) {

	var voteForm = document.getElementById('voteForm'+extra);

	initAjax();

	xmlHttp.open('GET', ROOT_URL+"edit.php?action=binaryVote&clean=true&param1="+voteValue+"&param2="+params,true);
	xmlHttp.send(null);

	xmlHttp.onreadystatechange = function(){
		if (xmlHttp.readyState == 4) {
			voteForm.id = 'voteStats';
			voteForm.innerHTML = xmlHttp.responseText;
		}
	}
}
function binaryVote_Contest(voteValue, params, extra) {

	var voteForm = document.getElementById('voteForm'+extra);

	initAjax();

	xmlHttp.open('GET', ROOT_URL+"edit.php?action=binaryVote_Contest&clean=true&param1="+voteValue+"&param2="+params,true);
	xmlHttp.send(null);

	xmlHttp.onreadystatechange = function(){
		if (xmlHttp.readyState == 4) {
			voteForm.id = 'voteStats';
			voteForm.innerHTML = xmlHttp.responseText;
		}
	}
}

function goToRootPage(page) {

	if (page <= 1) return false;
	var url = document.location.href.substr(0, document.location.href.lastIndexOf('/'));;
	document.location.href = url;
	return true;

}

function refreshResults(params, includeText, admin) {

	var dataContainer = document.getElementById('dataContainer');
	var continueVar = 0;
	var includeText = includeText;

	window.params = params;
	window.includeText = includeText;

	initAjax();
	ajaxLoader("show", "");
	
	xmlHttp.open('GET', ROOT_URL+"edit.php?action=checkRequestAbuse&clean=true&param1="+includeText,true);
	xmlHttp.send(null);	
	
	xmlHttp.onreadystatechange = function() {
		if (xmlHttp.readyState == 4) {
			if (xmlHttp.responseText == -1 && admin != 1) {
				var inputs = document.getElementById('searchForm-checkboxes').getElementsByTagName('input');
				for (i=0; i< inputs.length; i++) {
					inputs[i].disabled = 'disabled';
				}
				return false;
			}
			else {
				var params = window.params;
				var includeText = window.includeText;
				var send = '';
				var params = params.split("|");
				var checkedBoxesNo = 0;

				if (includeText == 0) {

					var i = 0;

					for (i=0; i<= params.length-1; i++) {

						var curParam = document.getElementById(params[i]);
						//alert("Id: "+curParam.id+" Value: "+curParam.value+" Checked: "+curParam.checked);
						if (curParam.value == '1' || curParam.checked == true) {
							send += params[i].replace("kind_", "")+"|||";
							checkedBoxesNo++;
						}

					}

					if (checkedBoxesNo == 0 && includeText == 0) return false;
				}

				var mg_textInput = document.getElementById('mg_textInput');

				if (includeText == 1 || mg_textInput.value.length > 3) {
					send += "text"+mg_textInput.value;
				}

				send += "pagination"+document.getElementById('searchLimit').value;
				initAjax();

				var url = ROOT_URL+"edit.php?action=refreshResults&clean=true&param1="+send;
				url += "&param2="+admin;

				xmlHttp.open('GET', url,true);
				xmlHttp.send(null);

				xmlHttp.onreadystatechange = function(){
					if (xmlHttp.readyState == 4) {
						dataContainer.innerHTML = xmlHttp.responseText;
					}
				}
			}
		}
		window.setTimeout("ajaxLoader('hide')", 3000);
		//ajaxLoader("hide", "");
	}
}
/**
var secs
var timerID = null
var timerRunning = false
var delay = 1000


function InitializeTimer()
{
    secs = 2
    StopTheClock()
    StartTheTimer()
}

function StopTheClock()
{
    if(timerRunning)
        clearTimeout(timerID)
    timerRunning = false
}

function StartTheTimer()
{

    if (secs==0)
    {
        StopTheClock()
       return 1;
    }
    else
    {
        self.status = secs
        secs = secs - 1
        timerRunning = true
        timerID = self.setTimeout("StartTheTimer()", delay)
    }
}
**/
function switchInfo(obj, mode) {

	var ps = obj.getElementsByTagName('p');
	for (i = 0; i < ps.length; i++) {
		if (ps[i].className == 'icon') {

			var childs = ps[i].childNodes;
			for (j = 0; j < childs.length; j++) {
				if (childs[j].className != 'add') {

					var imgs = childs[j].getElementsByTagName('img');

					for (k = 0; k < imgs.length; k++) {
						if (mode == 'in') imgs[k].style.paddingLeft = '118px';
						if (mode == 'out') imgs[k].style.paddingLeft = '0';
					}
				}
			}
		}
	}
}


function insertComment() {

	var mg_usernameInput = document.getElementById('mg_usernameInput');
	var mg_emailInput = document.getElementById('mg_emailInput');
	var mg_titleInput = document.getElementById('mg_titleInput');
	var mg_descriptionInput = document.getElementById('mg_descriptionInput');
	var object_id = document.getElementById('object_id');
	var kind = document.getElementById('kind');
	var parent_id = document.getElementById('parent_id');

	initAjax();

	xmlHttp.open('POST', ROOT_URL+"edit.php?action=insertComment&clean=true",true);
	xmlHttp.send(null);

	xmlHttp.onreadystatechange = function() {
		if (xmlHttp.readyState == 4) {
		}
	}

}


function changeLang(lang) {
	
	initAjax();
	
	xmlHttp.open('POST', ROOT_URL+"edit.php?action=changeSessionLang&clean=true&param1="+lang,true);
	xmlHttp.send(null);

	xmlHttp.onreadystatechange = function() {
		if (xmlHttp.readyState == 4) {
			reloadWithoutTarget();
		}
	}
}


function adultFilter(obj, mode) {

	var afForm = document.getElementById('adultFilterForm');

	initAjax();
	xmlHttp.open('POST', ROOT_URL+"edit.php?action=adultFilter&clean=true&param1="+mode+"&param2=req",true);
	xmlHttp.send(null);

	xmlHttp.onreadystatechange = function() {
		if (xmlHttp.readyState == 4) {
			reloadWithoutTarget();
		}
	}

}

var itemFlag = 0

function blink() {

	var elementName;
	var aObj = document.getElementById('flashingItem');


	if (itemFlag == 0)
	{
		aObj.style.color = '#284a92';
		itemFlag = 1;
	}
	else
	{
		aObj.style.color = 'red';
		itemFlag = 0;
	}

	// 0.5 is number of seconds - use smaller if necessary
	window.setTimeout('blink()', 0.7 * 1000);

}


function checkHelpStatus() {

	var bodys = document.getElementsByTagName('body');
	if (bodys[0].className != 'help') return false;
	return true;

}


function showToolTipTimed(ssx, ssy, tipID) {

	var toolTipObject = document.getElementById(tipID);

	if (!toolTipObject) return false;

	if (toolTipObject.className == 'tooltip') {
		toolTipObject.style.display = 'inline';

		toolTipObject.style.left = (ssx+10)+'px';
		toolTipObject.style.top = (ssy+30)+'px';

		var body = document.getElementsByTagName('body')[0];
		body.onmouseover = function() {
			var toolTipObject = document.getElementById(window.tipID);
			toolTipObject.style.display = 'none';
		}
	}

	window.ttWorking = 0;
	return false;

}


function showToolTip(obj,tipID,event) {

	if (window.ttWorking == 1) return false;
	obj.style.cursor = 'help';
	var ss = findPos(obj);
	window.ttWorking = 1;
	window.tipID = tipID;
	setTimeout("showToolTipTimed("+ss[0]+", "+ss[1]+", '"+tipID+"')", 1000);
}


function hideToolTip(tipID) {

	var toolTipObject = document.getElementById(tipID);
	if (toolTipObject) toolTipObject.style.display = 'none';

}


function switchHelpMode(mode, helpTrigger) {

	var bodys = document.getElementsByTagName('body');
	if (mode == 'on') {
		bodys[0].className = 'help';
		helpTrigger.onclick = function() {
			switchHelpMode('off', this);
		}
	}
	if (mode == 'off') {
		bodys[0].className = '';
		helpTrigger.onclick = function() {
			switchHelpMode('on', this);
		}
	}
}


function updateStatus(userid, type, objid) {

	if (userid == 0) return false;

	initAjax();

	try{
      xmlHttp.open("POST", "online.php", true); // here we set the request type, the page we're requesting and whether or not we want it to be asyncronous (true is asyncronous and is the default)
      var stuff = "upd=1&who="+userid+"&type="+type+"&objid="+objid;  // here we set a string with the post vars...more on this later
      xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); // because we're using POST, we need to set some headers..
      xmlHttp.setRequestHeader("Content-Length",stuff.length); // we need to set the length of the amount of information we're sending and this is dynamic as it's based on the length of the stuff string var
      xmlHttp.send(stuff); // next we actually send the information and perform our "request"

      xmlHttp.onreadystatechange = function(){  // create a function that is called on a change (response received) from the server
         if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
		  //document.getElementById('primary').innerHTML = xmlHttp.responseText;
         /* here we're looking to make sure the page has been fully loaded (complete) and that we did not receive an error from the server.  The readyState options are as follows:
         Object status integer:
         0 = uninitialized
         1 = loading
         2 = loaded
         3 = interactive
         4 = complete

         the status is just looking for the page status of the server ie: 404=page not found 500=internal server error 200=all is good, eat gravy etc...
         */
            //document.getElementById('namez').innerHTML = xmlHttp.responseText; // finally we need to update the page with the list of online users using innerHTML
			//alert(xmlHttp.responseText);
         }
      };
   }catch(e){
      //location = "online.php";
   }
   setTimeout("updateStatus	("+userid+", "+type+", "+objid+")", 30000); // recall the function every 30 seconds
}

function switchToAnimation() {

	return true;
	var primary = document.getElementById('primary');
	initAjax();

	xmlHttp.open('POST', ROOT_URL+"edit.php?action=switchToAnimation&clean=true",true);
	xmlHttp.send(null);


	xmlHttp.onreadystatechange = function() {
		if (xmlHttp.readyState == 4) {
			primary.innerHTML = xmlHttp.responseText;
			return false;
		}
	}

	return false;

}

function showContainer(objID, state) {

	var obj = document.getElementById(objID);

	if (state == 1) obj.style.display = 'block';
	if (state == 0) obj.style.display = 'none';

	return false;

}

function selectThis(obj) {

	if (obj.className.indexOf('selected') == -1) {
		obj.className += ' selected';
		return 1;
	}
	else {
		obj.className = obj.className.replace("selected", "");
		return 0;
	}

}

function showTab(triggerObj, tabID, container) {

	var containerObj = document.getElementById(container);
	var tab = document.getElementById(tabID);
	if (containerObj.childNodes.length == 0) return false;
	for (i = 0; i < containerObj.childNodes.length; i++) {
		if (containerObj.childNodes[i].nodeName == 'UL') {
			if (containerObj.childNodes[i].className.indexOf('multimedia') != -1) {
				containerObj.childNodes[i].style.display = 'none';
			}
			var tempList = containerObj.childNodes[i];
			if (tempList.childNodes.length > 0) {
				for (j = 0; j < tempList.childNodes.length; j++) {
					if (tempList.childNodes[j].nodeName == 'LI' && tempList.childNodes[j].className == 'selected') {
						tempList.childNodes[j].className = '';
					}
				}
			}
		}
	}

	triggerObj.className = 'selected';
	tab.style.display = 'block';
}

function checkPassField(tObj) {

	var publicCkBox = document.getElementById('mg_privateInput1');
	var privateCkbox = document.getElementById('mg_privateInput2');
	var passContainer = document.getElementById('passContainer');

	//alert(publicCkBox.id);

	if (tObj.id == 'mg_privateInput1' || tObj.id == 'mg_privateInput2') {
		if (privateCkbox.checked == true) {
			passContainer.className = '';
		}
		else {
			passContainer.className = 'hidden';
		}
	}
	else if (tObj.id == 'mg_passInput') {
		if (tObj.value.length == 0) {
			passContainer.className = 'hidden';
			privateCkbox.checked = false;
			publicCkBox.checked = true;
		}
	}

}

function confirmComment(triggerObj, commentID, objid) {

	initAjax();

	xmlHttp.open('POST', ROOT_URL+"edit.php?action=confirmComment&clean=true&param1="+commentID+"&param2="+objid,true);
	xmlHttp.send(null);

	xmlHttp.onreadystatechange = function() {
		if (xmlHttp.readyState == 4) {
			//triggerObj.innerHTML = xmlHttp.responseText;
			//return false;
			triggerObj.style.display = 'none';
			return true;
		}
	}

}

function copyToClipboard(objid) {

	var inputObj = document.getElementById(objid);
	var holdtext = document.getElementById(objid);

	holdtext.innerText = inputObj.value;

	var Copied = holdtext.createTextRange();
	Copied.execCommand("Copy");

}

function switchSubCategory(mainid, categ) {

	initAjax();

	xmlHttp.open('POST', ROOT_URL+"edit.php?action=switchSubCategory&clean=true&param1="+mainid+"&param2="+categ,true);
	xmlHttp.send(null);

	xmlHttp.onreadystatechange = function() {
		if (xmlHttp.readyState == 4) {
			reloadWithoutTarget();
		}
	}
}

function isInteger (s)
   {
      var i;

      if (isEmpty(s))
      if (isInteger.arguments.length == 1) return 0;
      else return (isInteger.arguments[1] == true);

      for (i = 0; i < s.length; i++)
      {
         var c = s.charAt(i);

         if (!isDigit(c)) return false;
      }

      return true;
   }

  function isEmpty(s)
   {
      return ((s == null) || (s.length == 0))
   }

   function isDigit (c)
   {
      return ((c >= "0") && (c <= "9"))
   }

function navigatePagination(url) {
	hideElements('div', 'pagination jumper');
	document.location.href = url+"?mg_page="+document.getElementById('jumperInput').value;
}

function navigateDecisionDelayed(curVal) {

	var jumperInput = document.getElementById('jumperInput');
	var modVal = jumperInput.value;

	if (modVal == curVal) return true;
	return false;
}

function nagivateDecision() {

	var jumperInput = document.getElementById('jumperInput');
	var curVal = jumperInput.value;

	window.setTimeout('navigateDecisionDelayed(\''+curVal+'\')', 1000);

}

function hideElements(kind, class__) {

	var elems = document.getElementsByTagName(kind);
	for (i = 0; i < elems.length; i++) {
		if (elems[i].className == class__) {
			elems[i].style.display = 'none';
		}
	}

}

function jumpToPage(curPage, seek, totalPages, url) {

	var jumperInput = document.getElementById('jumperInput');
	if (!isInteger(jumperInput.value)) jumperInput.value = 1;
	//if (jumperInput.value > totalPages) jumperInput.value = totalPages;
	var new_page = 0;

	if (seek == 'previous') new_page = parseInt(jumperInput.value) - 1;
	if (seek == 'next') new_page = parseInt(jumperInput.value) + 1;
	if (seek == 'input') new_page = parseInt(jumperInput.value);

	if (new_page < 1 || new_page > totalPages) return false;
	jumperInput.value = new_page;
	jumperInput.focus();
	jumperInput.blur();

	if (seek == 'input') window.setTimeout('navigatePagination(\''+url+'\')', 2000);

}

function viewThisPage(user_id, obj, url) {
	
	if (obj != '') {
		
		var ajax_url = ROOT_URL+"edit.php";
		var pars = "action=viewThisPage&clean=true&param1="+user_id+"&param2="+obj+"&param3="+url;
		
		var myAjax = new Ajax.Request(
			ajax_url,
			{ 
				method: 'get',
				parameters: pars
			}
		);
		
		/*
		initAjax();
		xmlHttp.open('POST', ROOT_URL+"edit.php?action=viewThisPage&clean=true&param1="+user_id+"&param2="+obj+"&param3="+url,false);
		alert('deschis ajax');
		xmlHttp.send(null);
		alert('trimis ajax: '+ ROOT_URL+"edit.php?action=viewThisPage&clean=true&param1="+user_id+"&param2="+obj+"&param3="+url);
		
		xmlHttp.onreadystatechange = function() {
			if (xmlHttp.readyState == 4) {
				alert('primit ready');
				alert(xmlHttp.responseText);
			}
		}
		*/
	}

}

var timerRunning = false;
var bannerTimer = 0;

function showBanner2() {

	var object;

	if (timerRunning)
	window.clearTimeout(bannerTimer);

	object = document.getElementById('sidePromo');
	object.style.width = '335px';
	object.style.height = '305px';
	object.onclick = function() {
		redirectToECard();
	}
}

function hideBanner2() {
	var object = document.getElementById('sidePromo');
	timerRunning = false;
	object.style.width = '70px';
	object.style.height = '70px';
	object.onclick = function() {}
}

function startTimer2() {
	bannerTimer = window.setTimeout('hideBanner2()', 1000);
	timerRunning = true;
}

function redirectToECard() {
	window.location.href = 'http://felicitari.sentimente.ro/?unde=felicitari&secfel=viewfel&idfel=100000&subsecfel=upload';
}

function deleteTempFile(kind) {

	initAjax();

	xmlHttp.open('POST', ROOT_URL+"edit.php?action=deleteTempFile&clean=true&param1="+kind,true);
	xmlHttp.send(null);

	xmlHttp.onreadystatechange = function() {
		if (xmlHttp.readyState == 4) {
			reloadWithoutTarget();
		}
	}

	return false;
}

function focusArea(obj) {
	var new_height = (obj.scrollHeight)+'px';
	obj.style.height = new_height;
	obj.select();

}

function unfocusArea(obj, new_height) {
	obj.style.height = new_height+'px';
}

function record_again() {
	getMovieName("myid").record();
}

function getMovieName(movieName) {
	if (navigator.appName.indexOf("Microsoft") != -1) {
		return window[movieName];
	}
	else {
		return document[movieName];
	}
}

function onMovieRecord(mov) {

	var recordActions = document.getElementById('recordActions');
	var lis = recordActions.getElementsByTagName('li');
	var links = lis[1].getElementsByTagName('a');

	for (var i = 0; i < lis.length; i++) {
		lis[i].style.display = 'block';
	}
	
	links[0].onclick = function() {
		getRecordStatus(mov, this);
	}
	
}

function getRecordStatus(usrid, triggerObj) {
	
	var ajax_url = ROOT_URL+"ajax_curl.php";
	var pars = "mov="+usrid+"&url=http://upl.sentimente.ro/~video/save_record.php";
	new_objid = '0';
	ajaxLoader("show", "");
	
	var myAjax = new Ajax.Request(
		ajax_url,
		{ 
			method: 'get',
			parameters: pars,
			onSuccess: function(transport) {
				
				if (transport.responseText > 100) {
					triggerObj.onclick = function() {};
					document.getElementById('dataContainer').style.display = 'none';
					var uC = document.getElementById('uploadContainer');
					new_objid = parseInt(transport.responseText);
					uC.style.display = 'block';
					triggerObj.style.display = 'none';
					if (new_objid > 0) setSession('mg_record_objid', new_objid);
					ajaxLoader("hide", "");
				}
				else {
					ajaxLoader("hide", "");
					document.getElementById('dataContainer').style.display = 'none';
					var uC = document.getElementById('uploadContainer');
					uC.style.display = 'block';
					var h1s = uC.getElementsByTagName('h1');
					uC.innerHTML = '<p class="error">Oroare #'+transport.responseText+'</p>';
					triggerObj.style.display = 'none';
					
					return false;
				}
			}
		}
	);
	
}

function setSession(key, value) {
	
	ajaxLoader("hide", "");
	//alert('setSession()');
	
	var ajax_url = ROOT_URL+"edit.php";
	var pars = "action=setSession&clean=true&param1="+key+"&param2="+value;
	
	var myAjax = new Ajax.Request(
		ajax_url,
		{ 
			method: 'get',
			parameters: pars
		}
	);
	
	ajaxLoader("hide", "");
	
}


function proposeAsVcard() {
	document.getElementById('vcardProposeForm').style.display = 'block';
}

function showProfileInParentFrame(linkObj) {
	window.parent.location.href = linkObj.href;
	return false;
}

function ajaxLoader(mode, message) {
	
	var ajaxLoader = document.getElementById('ajaxLoader');
	
	if (mode == 'show') {
		var bodys = document.getElementsByTagName('body');
		ajaxLoader.style.height = bodys[0].offsetHeight+'px';
		ajaxLoader.style.paddingTop = Math.ceil(bodys[0].offsetHeight/4)+'px';
		ajaxLoader.style.display = 'block';
	}
	else if (mode == 'hide') ajaxLoader.style.display = 'none';
	
}

function keepSession(index) {
	
	initAjax();
	
	xmlHttp.open('POST', ROOT_URL+"edit.php?action=keepSession&clean=true&param1="+index,true);
	xmlHttp.send(null);
	
	window.setTimeout("keepSession("+index+")", 20*60000);
	
}

function keepSessionAuto(index) {
	window.setTimeout("keepSession("+index+")", 300000); // recall the function every 30 seconds
}

function checkWindow() {
	
	if (window == top) {
		
		var temp = window.location.href.substr(window.location.href.lastIndexOf('objid='), 20);
		var objid = parseInt(temp.substr(temp.lastIndexOf('=')+1, 20));
		
		initAjax();
		
		xmlHttp.open('POST', ROOT_URL+"edit.php?action=getUrlForObject&clean=true&param1="+objid,true);
		xmlHttp.send(null);
		
		xmlHttp.onreadystatechange = function() {
			if (xmlHttp.readyState == 4) document.location.href = xmlHttp.responseText;
		}
		
	}
	
}

function triggerUpload()
{
	var _frm = document.getElementById('frmUpload');
	
	if(_frm)
	{
		return _frm.contentWindow.linkUpload();
	}
	else
	{
		document.getElementById('uploadForm').submit();
	}
}