/**********************************************************************************
* phpComasy, Open Source Web Content Management System                            *
* http://www.phpcomasy.org                                                        *
*                                                                                 *
* Copyright (c) 2005 - 2006 neflexis gmbh (http://www.neflexis.ch)                *
*                                                                                 *
* phpComasy is released under his own licence (http://www.phpcomasy.com/licence)  *
**********************************************************************************/

// some javascript functions

function ask(question, href) {
	if(confirm(question) == true) {
		window.location.href = href;
	}
}



function hide_varname_row(anz) {
	for(i = 0; i < anz; i++)
	{
		if(document.getElementById( 'varname_row_'+i ).style.display != 'none') {
			document.getElementById('varname_row_'+i).style.display = "none";
		}
		else {
			document.getElementById('varname_row_'+i).style.display = "block";
		}
	}
}

function enlarge_target_input( anz,size ) {
	for(i = 1; i < anz; i++)
	{
		document.getElementById('target_input_'+i).size =  document.getElementById('target_input_'+i).size + size;
	}
}

function enable_own_language_field() {
	if(document.getElementById('lang_name').value == 'own_language')
	{
		document.getElementById('own_language_input').style.display = 'block';
	}
	else
	{
		document.getElementById('own_language_input').style.display = 'none';
	}
}




function LockCountDown() {
	--countDownTime;
	if (countDownTime < 0 || countDownTime == 'NaN' ||  countDownTime == _COUNT_DOWN_OVER)
	{
		document.getElementById('lock_count_down').innerHTML = _COUNT_DOWN_OVER;
	}
	else
	{
		document.getElementById('lock_count_down').innerHTML = Math.round(countDownTime/60)+' '+_MINUTES;
	}
	setTimeout("LockCountDown()", 1000);
}

function extend_lock(page_id) {
	var error_message = 'Error while sending data to server';
	
	var xmlHttp = getXmlHttp();

	xmlHttp.open("GET",'ajax_handler.php?action=extend_lock&page_id='+page_id);
	xmlHttp.send(null);

	xmlHttp.onreadystatechange = function () {
		if (xmlHttp.readyState == 4)
		{
			if(xmlHttp.responseText == "ok")
			{
				refresh_remain_lock_time(page_id);
			}
			else
			{
				alert(error_message+'responseText was:'+xmlHttp.responseText);
			}
		}
	};
}

function refresh_remain_lock_time(page_id) {
	var xmlHttp = getXmlHttp();
	
	xmlHttp.open("GET",'ajax_handler.php?action=remain_lock_time&page_id='+page_id);
	xmlHttp.send(null);

	xmlHttp.onreadystatechange = function () {
		if (xmlHttp.readyState == 4)
		{
			countDownTime = xmlHttp.responseText;
		}
	};
}




function getXmlHttp() {
	var xmlHttp = false;
	// Mozilla, Opera, Safari, Internet Explorer 7
	if (typeof XMLHttpRequest != 'undefined') {
		xmlHttp = new XMLHttpRequest();
	}
	if (!xmlHttp) {
		// Internet Explorer 6<
		try {
			xmlHttp  = new ActiveXObject("Msxml2.XMLHTTP");
		} catch(e) {
			try {
				xmlHttp  = new ActiveXObject("Microsoft.XMLHTTP");
			} catch(e) {
				xmlHttp  = false;
			}
		}
	}
	return xmlHttp;
}





// decrypt string
function decryptString(enc,offset) {
	var dec = "";
	var len = enc.length;
	for(var i=0; i < len; i++)	{
		var n = enc.charCodeAt(i);
		if (n >= 0x2B && n <= 0x3A)	{
			dec += decryptCharcode(n,0x2B,0x3A,offset);	// 0-9 . , - + / :
		} else if (n >= 0x40 && n <= 0x5A)	{
			dec += decryptCharcode(n,0x40,0x5A,offset);	// A-Z @
		} else if (n >= 0x61 && n <= 0x7A)	{
			dec += decryptCharcode(n,0x61,0x7A,offset);	// a-z
		} else {
			dec += enc.charAt(i);
		}
	}
	return dec;
}

// decrypt helper function
function decryptCharcode(n,start,end,offset) {
	n = n + offset;
	if (offset > 0 && n > end)	{
		n = start + (n - end - 1);
	} else if (offset < 0 && n < start)	{
		n = end - (start - n - 1);
	}
	return String.fromCharCode(n);
}

// decrypt spam-protected emails
function linkTo_UnCryptMailto(s)	{
	location.href = decryptString(s,-3);
}


