/**
 * <b>Javascript include file with some general functions</b>
 * @author Ilia Ratchinski
 * @copyright 2005 Ratchinski IT Services
 * @version 1.0
 */

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( name ) 
{	
	var start = document.cookie.indexOf( name + "=" );
	var len = start + name.length + 1;
	if ( ( !start ) &&
	( name != document.cookie.substring( 0, name.length ) ) )
	{
	return null;
	}
	if ( start == -1 ) return null;
	var end = document.cookie.indexOf( ";", len );
	if ( end == -1 ) end = document.cookie.length;
	return unescape( document.cookie.substring( len, end ) );
}

function delete_cookie( name, path, domain ) 
{
	if ( get_cookie( name ) ) document.cookie = name + "=" +
	( ( path ) ? ";path=" + path : "") +
	( ( domain ) ? ";domain=" + domain : "" ) +
	";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}

function parse_querystring(qs)
{
	qs=trim(qs);
	var result=new Object();
	if(qs.length<3)return result;
	
	if(qs.charAt(0)=='?')qs=qs.substring(1);
	
	var ar1=qs.split('&');
	
	for(var i=0;i<ar1.length;i++)
	{
		var ar2=ar1[i].split('=');
		result[ar2[0]]=unescape(ar2[1]);
	}
	return result;
}


function open_window(href,winname,width,height,additional)
{
	var options='';
	if(width)options+='width='+width;
	if(height)options+=(options=='')?'':','+'height='+height;
	if(additional)options+=(options=='')?'':','+additional;
	return window.open(href, winname , options);
}

function trim(s) 
{
  while (s.substring(0,1) == ' '||s.substring(0,1) == "\n") {
    s = s.substring(1,s.length);
  }
  while (s.substring(s.length-1,s.length) == ' '||s.substring(s.length-1,s.length) == "\n") {
    s = s.substring(0,s.length-1);
  }
  return s;
}

function getWindowWidth(win)
{
	if(win==null)win=window;
	
	if(win.innerWidth)return win.innerWidth;
	
	if(win.document.body && win.document.body.offsetWidth)return win.document.body.offsetWidth;
	
	return 0;
}

function getWindowHeight(win)
{
	if(win==null)win=window;
	
	if(win.innerHeight)return win.innerHeight;
	
	if(win.document.body && win.document.body.offsetHeight)return win.document.body.offsetHeight;
	
	return 0;
}


function clickrplc(link,newlinkstr)
{
	link.href=newlinkstr;
}