function gd()
{
	return location.protocol+'//'+location.host;
}

function ToggleGrp(grp, max)
{
	toggle_image(grp + "-img");
	var i=0;
	for (i=0 ; i < max ; i++)
	{
		toggle_text(grp + i);
	}
}

function puttitle(text)
{
	document.title = html_entity_decode(text);
	document.getElementById('main_title_field').innerHTML = text;
}

function html_entity_decode(str)
{
    //jd-tech.net
    var  tarea=document.createElement('textarea');
    tarea.innerHTML = str; return tarea.value;
    tarea.parentNode.removeChild(tarea);
}

function toggle_text(id,ispictoggle,isi,isret)
{
	if(ispictoggle == 1){
		toggle_image('img_'+id,isi);
	}
	
	var tr = document.getElementById(id);
	if (tr==null) { return; }
	var bExpand = tr.style.display == '';
	tr.style.display = (bExpand ? 'none' : '');
	
	if(isret)
		return (bExpand ? 0 : 1);
}

function toggle_navi(id,serv)
{
	var tr = document.getElementById(id);
	if (tr==null) { return; }
	var bExpand = tr.style.display == '';
	tr.style.display = (bExpand ? 'none' : '');
	
	var val = (bExpand ? 'none' : '1');
	
	putcontent('http://'+serv+'.coldline.hu/cl_options.php?otype=dnavi&set='+val,-1);	
}

function toggle_image(id,isi)
{
	

	var sMinus = 'http://services.coldline.hu/pics/minus9' + (isi == 1 ? 'i' : '') + '.png';
	var sPlus  = 'http://services.coldline.hu/pics/plus9' + (isi == 1 ? 'i' : '') + '.png';

	var img = document.getElementById(id);
	if (img!=null)
	{
	    var bExpand = img.src.indexOf(sPlus) >= 0;
		if (!bExpand)
			img.src = sPlus;
		else
			img.src = sMinus;
	}
}

function switch_texts(id1,id2)
{
	var tr1 = document.getElementById(id1);
	var tr2 = document.getElementById(id2);
	if (tr1==null) { return; }
	if (tr2==null) { return; }
	
	var bExpand = tr1.style.display == '';
	tr1.style.display = (bExpand ? 'none' : '');	
	tr2.style.display = (bExpand ? '' : 'none');
}


function putcontent(url,itemid)
{
	var xmlHttpObj=null;
	try { 
		xmlHttpObj=new XMLHttpRequest();
	} catch (e) { 
		try { 
			xmlHttpObj=new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e){
			try {
				xmlHttpObj=new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {
				alert("Your browser does not support AJAX!");
				return false;
			}
		}
	}
	if (xmlHttpObj==null) return;
	

	xmlHttpObj.onreadystatechange=function() {
		if(xmlHttpObj.readyState == 4) {
			var tr = document.getElementById(itemid);			
			tr.innerHTML = xmlHttpObj.responseText;
			tr.display = '';
	
			
		}
		
	}


	xmlHttpObj.open("GET",url,true);
	xmlHttpObj.setRequestHeader('Content-Type','text/html');
	xmlHttpObj.send(null);

}

function putpostcontent(url,itemid,postfields,newstyle)
{
	var xmlHttpObj=null;
	try { 
		xmlHttpObj=new XMLHttpRequest();
	} catch (e) { 
		try { 
			xmlHttpObj=new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e){
			try {
				xmlHttpObj=new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {
				alert("Your browser does not support AJAX!");
				return false;
			}
		}
	}
	if (xmlHttpObj==null) return;
	

	xmlHttpObj.onreadystatechange=function() {
		if(xmlHttpObj.readyState == 4) {
			var tr = document.getElementById(itemid);			
			if( newstyle == undefined ) {
				tr.innerHTML = xmlHttpObj.responseText;
				tr.style.display = '';
			} else {
				tr.className = newstyle;
			}
		}
		
	}

	xmlHttpObj.open("POST",url,true);

	xmlHttpObj.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); // a charset mindig utf8 !!
	xmlHttpObj.setRequestHeader("Content-length", postfields.length);
	xmlHttpObj.setRequestHeader("Connection", "close");
	
	xmlHttpObj.send(postfields);
}

function AddBugReport(servfield,datafield,uri,formid,serv)
{
	var url = 'http://'+serv+'.coldline.hu/cl_options.php?data=bugreport&isenc=1';
	
	var tr1 = document.getElementById(servfield);
	var tr2 = document.getElementById(datafield);
	
	var pf = 'serv='+tr1.value+'&text='+tr2.value+'&uri='+uri;
	
	putpostcontent(url,formid,pf);	
}

function ModTodo(serv,cmd,id,listid,site)
{
	if( site == undefined ) site = 'http://'+serv+'.coldline.hu';
	var url = site+'/cl_options.php?data=todos&isenc=1&serv='+serv+'&cmd='+cmd+'&id='+id;	
	putcontent(url,listid);
	if(listid == '_noparent_')
		location.reload(true);
}

function AddTodo(serv,textid,listid,formid)
{
	var url = 'http://'+serv+'.coldline.hu/cl_options.php?data=todos&isenc=1';
	
	var tr = document.getElementById(textid);
	var pf = 'serv='+serv+'&text='+tr.value;
		
	putpostcontent(url,listid,pf);
	
	tr.value = '';
	var tr2 = document.getElementById(formid);
	tr2.style.display = 'none';	
}

function Set_Cookie( name, value, expires, path, domain, secure )
{
	// set time, it's in milliseconds
	var today = new Date();
	today.setTime( today.getTime() );

	/*
	if the expires variable is set, make the correct
	expires time, the current script below will set
	it for x number of days, to make it for hours,
	delete * 24, for minutes, delete * 60 * 24
	*/
	if ( expires )
	{
		expires = expires * 1000 * 60 * 60 * 24;
	}
	
	var expires_date = new Date( today.getTime() + (expires) );

	document.cookie = name + "=" +escape( value ) +
	( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
	( ( path ) ? ";path=" + path : "" ) +
	( ( domain ) ? ";domain=" + domain : "" ) +
	( ( secure ) ? ";secure" : "" );
}

function Get_Cookie(c_name)
{
	if (document.cookie.length>0)
	{
		c_start=document.cookie.indexOf(c_name + "=");
		if (c_start!=-1)
		{
			c_start=c_start + c_name.length+1;
			c_end=document.cookie.indexOf(";",c_start);
		if (c_end==-1) c_end=document.cookie.length;
			return unescape(document.cookie.substring(c_start,c_end));
		}
	}
	return "";
}

function getClientWidth() {
  return document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientWidth:document.body.clientWidth;
}

function getClientHeight() {
  return document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientHeight:document.body.clientHeight;
}
