function get_ref(){
	var ckstring = document.cookie, ckind = ckstring.indexOf("refer="),
	ck = (ckind != -1 ? ckstring.slice(ckind+6):'');
	return ck
}

function WM_imageSwap(daImage, daSrc){
	var objStr,obj;
	if(document.images){
		if (typeof daImage == 'string') {
			objStr = 'document.' + daImage;
			obj = eval(objStr);
			obj.src = daSrc;
		} else if ((typeof daImage == 'object') && daImage && daImage.src) {
			daImage.src = daSrc;
		}
	}
}

function opw(w,h,winX,x,y){return window.open('',winX,'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,width='+w+',height='+h+',top='+y+',left='+x);}
function mrw(w,h,winX){
	var x = (screen.width) ? (screen.width-w)/2 : 0;
	var y = (screen.height) ? (screen.height-h)/2 : 0;
	var win = opw(w,h,winX,x,y);
	if (win.resizeTo) win.resizeTo(w,h);
	if (win.moveTo) win.moveTo(x,y);
	if (win.innerHeight && (win.innerHeight != h || win.innerWidth != w) ) {
		win.close();
		win = opw(w,h,winX,x,y);
	}
	return win;
}
function open_window(url,w,h,winX,isimg){		
	if(isimg){
		w-=20;h-=20;
		var win=mrw(w+10,h+49,winX);
		win.document.open();
		win.document.write(
			'<html><head><title></title><meta http-equiv="imagetoolbar" content="no"></head>'+
			'<body leftmargin="0" topmargin="0" rightmargin="0" bottommargin="0" marginwidth="0" marginheight="0">'+
			'<table width="100%" border="0" cellspacing="0" cellpadding="0" height="100%"><tr>'+
			'<td align="center" valign="middle"><img src="'+url+'" alt="" width="'+w+'" height="'+h+'" border="0"></td>'+
			'</tr></table></body></html>'
		);
		win.document.close();
	} else{
		url=url?url:'/index.html';
		winX=winX?winX:'Window';
		w=w?w+10:600;
		h=h?h+40:300;
		var win=mrw(w,h,winX);
		win.location = url;
	}
	if(win.window.focus){win.window.focus();}
}
//****************
var pp_w=500,pp_h=500;
function show_pp(a,b,ppm){
	if(ppm){
		var w=mrw(pp_w,pp_h,'Window');
		w.location=a+'/pp'+b;
		w.opnr = window.opnr?window.opnr:window;
	} else{
		if(window.opener && window.opener!=window) 
		  window.opnr = window.opener.opnr?window.opener.opnr:window.opener;
		if(window.opnr)
		  window.opnr.location.href=a+window.opnr.pgnm+b;
		else 
		  alert('Sorry, feature is not supported by your browser.');  
	}
}
/*
function print(url) {
	var w=640;
	var h=480;
	LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
	win = window.open(url,'print','toolbar=1,location=0,directories=0,status=0,menubar=1,scrollbars=1,resizable=1,width='+w+',height='+h+',top='+TopPosition+',left='+LeftPosition);
	if(win.window.focus){win.window.focus();}
}
*/

/***/
function setCookie(name, value, expires, path, domain, secure){
	document.cookie= name + "=" + escape(value) +
	((expires) ? "; expires=" + expires.toGMTString() : "") +
	((path) ? "; path=" + path : "") +
	((domain) ? "; domain=" + domain : "") +
	((secure) ? "; secure" : "");
}
function getCookie(name){
	var dc = document.cookie;
	var prefix = name + "=";
	var begin = dc.indexOf("; " + prefix);
	if (begin == -1) {
		begin = dc.indexOf(prefix);
		if (begin != 0) return null;
	} else {
		begin += 2;
	}
	var end = document.cookie.indexOf(";", begin);
	if (end == -1) {
		end = dc.length;
	}
	return unescape(dc.substring(begin + prefix.length, end));	
}
function clearCookie(name){
	setCookie(name,"");
}

function rand(num)
{
	return Math.floor(Math.random()*num)+1
}
function goml(ml,b,a){parent.location = ml+a+'@'+b}
function statusbar(sMsg){window.status = sMsg; return true;}

function sprintf()
{
	if (!arguments || arguments.length < 1 || !RegExp)
	{
		return;
	}
	var str = arguments[0];
	var re = /([^%]*)%('.|0|\x20)?(-)?(\d+)?(\.\d+)?(%|b|c|d|u|f|o|s|x|X)(.*)/;
	var a = b = [], numSubstitutions = 0, numMatches = 0;
	while (a = re.exec(str))
	{
		var leftpart = a[1], pPad = a[2], pJustify = a[3], pMinLength = a[4];
		var pPrecision = a[5], pType = a[6], rightPart = a[7];
		
		//alert(a + '\n' + [a[0], leftpart, pPad, pJustify, pMinLength, pPrecision);

		numMatches++;
		if (pType == '%')
		{
			subst = '%';
		}
		else
		{
			numSubstitutions++;
			if (numSubstitutions >= arguments.length)
			{
				alert('Error! Not enough function arguments (' + (arguments.length - 1) + ', excluding the string)\nfor the number of substitution parameters in string (' + numSubstitutions + ' so far).');
			}
			var param = arguments[numSubstitutions];
			var pad = '';
			       if (pPad && pPad.substr(0,1) == "'") pad = leftpart.substr(1,1);
			  else if (pPad) pad = pPad;
			var justifyRight = true;
			       if (pJustify && pJustify === "-") justifyRight = false;
			var minLength = -1;
			       if (pMinLength) minLength = parseInt(pMinLength);
			var precision = -1;
			       if (pPrecision && pType == 'f') precision = parseInt(pPrecision.substring(1));
			var subst = param;
			       if (pType == 'b') subst = parseInt(param).toString(2);
			  else if (pType == 'c') subst = String.fromCharCode(parseInt(param));
			  else if (pType == 'd') subst = parseInt(param) ? parseInt(param) : 0;
			  else if (pType == 'u') subst = Math.abs(param);
			  else if (pType == 'f') subst = (precision > -1) ? Math.round(parseFloat(param) * Math.pow(10, precision)) / Math.pow(10, precision): parseFloat(param);
			  else if (pType == 'o') subst = parseInt(param).toString(8);
			  else if (pType == 's') subst = param;
			  else if (pType == 'x') subst = ('' + parseInt(param).toString(16)).toLowerCase();
			  else if (pType == 'X') subst = ('' + parseInt(param).toString(16)).toUpperCase();
		}
		str = leftpart + subst + rightPart;
	}
	return str;
}

/**
 * DEBUG
 */
var debug_data = "";

function log_it(msg){
	debug_data += "\r\n<font color=blue>"+msg+"</font>";
//	debug_output_refresh();
}

function print_r(obj, lev)
{
	if(lev == null) lev = 0;
	var s = "";
	s+=typeof(obj)+":";
	s+="{";
	switch(typeof(obj)){	
		case "object":
		case "array":
			s+="\r\n";
			//for(i=0;i<(lev);i++) s+= "\t";
			lev++;
			aa = 0;
			for(a in obj){			
				for(i=0;i<(lev);i++) s+= "\t";
				s += "["+a+"] = "+print_r(obj[a], lev);
				if(aa < obj.length-1) s+=",\r\n";
				aa++;
			}
			lev--;
			s+="\r\n";
			for(i=0;i<(lev);i++) s+= "\t";	
			break;		
		default:
			s+=obj;
			break;
	}
	s += "}";
	return s;
}

function handleErr(msg,url,l){
	var txt=""
	txt="There was an error on this page.\n\n"
	txt+="Error: " + msg + "\n"
	txt+="URL: " + url + "\n"
	txt+="Line: " + l + "\n\n"
	txt+="Click OK to continue.\n\n"
	log_it("\r\n<font color=red>"+txt+"</font>");
	return true	
}

onerror=handleErr;