function URLtoURI(url){
	url = url.replace(RegExp("\\\\","g"),"/");
	return encodeURI(url);
}

// AJAX Functions NEXT
var http_request = false;

function ajax(obj,url){ // Object,URL,Parameters,Method,Action,Function Name
	var args = ajax.arguments;
	var parameters = (args.length > 2)? args[2] : '';
	var method = (args.length > 3)? args[3] : "GET";
	var act = (args.length > 4)? args[4] : "html";
	var func = (args.length > 5)? args[5] : "";
	
    var http_request = false;
	if (window.XMLHttpRequest) { // Mozilla, Safari,...
		http_request = new XMLHttpRequest();
		if (http_request.overrideMimeType) {
			http_request.overrideMimeType('text/xml');
		}
	}else if (window.ActiveXObject) { // IE
		try {
			http_request = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				http_request = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {}
		}
	}
	if (!http_request) {
		alert('Cannot create XMLHTTP instance');
		return false;
	}

	http_request.onreadystatechange = function(){processStateChange(http_request,obj,act,func)};
	http_request.open(method, url, true);
	http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	http_request.setRequestHeader("Content-length", parameters.length);
	http_request.setRequestHeader("Connection", "close");
	http_request.send(parameters);
}

var ready_state = new Array("uninitialized","loading","doaded","interactive","complete")

function processStateChange(http_request,obj){
	var act = (processStateChange.arguments.length > 2)? processStateChange.arguments[2] : "html";
	var func = (processStateChange.arguments.length > 3)? processStateChange.arguments[3] : "";

	window.status = 'Ajax: '+ready_state[http_request.readyState];
	if(http_request.readyState == 4){ // Complete
		if(http_request.status == 200 || http_request.status == 0){ // OK response
			if(act == "html"){
				obj.innerHTML = http_request.responseText;
			}else if(act == "text"){
				obj.innerText = http_request.responseText;
			}else if(act == "function"){
				eval(func)(http_request.responseText,obj)
			}else if(act == "value"){
				obj.value = http_request.responseText
			}else if(act == "link"){
				if(http_request.responseText == "OK"){
					window.location = func
				}else{
					alert(http_request.responseText)
				}
			}
			http_request = null
		}else{
			window.status = 'Ajax: problem ' + http_request.statusText + ', status: ' + http_request.status
		}
	}
}
// END AJAX

//COOKIE FUNCTION
function GetCookie(name){
	all = document.cookie.split("; ")
	var allcookies = new Array();
	for(i=0;i<all.length;i++){
		allcookies[i] = all[i].split("=")
		if(name.toLowerCase() == allcookies[i][0].toLowerCase()){
			allcookies[i][1] = unescape(allcookies[i][1])
			return allcookies[i][1]
		}
	}
	return "undefined";
}

function SetCookie(one,two){
var argv = SetCookie.arguments;
var argc = SetCookie.arguments.length;
var days = (argc > 2)? argv[2] : 365;
var expires = new Date ();
expires.setTime (expires.getTime() + (24 * 60 * 60 * 1000 * days));
var path = (argc > 3) ? argv[3] : null;
var domain = (argc > 4) ? argv[4] : DomainName();
var secure = (argc > 5) ? argv[5] : false;
document.cookie = one + "=" + escape (two) + ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) + ((path == null) ? "" : ("; path=" + path)) + ((domain == null) ? "" : ("; domain=" + domain)) + ((secure == true) ? "; secure" : "");
}

// END COOKIE

//General Functions
function DomainName(){
	var start = location.hostname.lastIndexOf(".",location.hostname.length-5);
	if(start >= 0){
		dname = location.hostname.substr(start,location.hostname.length-start)
	}else{
		dname = "."+location.hostname
	}
	return dname.toString();
}

//String functions
function InString(ex,str){ //ex = expression looked for, str = string looked in
		var start = 0;
		var res = 0;
		for(i=0;i<str.length;i++){
			if(str.indexOf(ex,i) >= 0){
				res++
				i = str.indexOf(ex,i) + 1
			}else{
				i = str.length
			}
		}
		return res;
}

function preload_image(){
	var args = preload_image.arguments;
	document.imageArray = new Array(args.length);
	for(var i=0; i<args.length; i++){
		document.imageArray[i] = new Image;
		document.imageArray[i].src = args[i];
	}
}

document.write("<div id=\"pophelp\" style=\"z-index:100;padding:2px;font-family:arial;font-size:10pt;display:none;color:orange;border:1px solid orange;background:#FFFFFF;position:absolute;\"><table cellpadding=0 cellspacing=0><tr><td id=\"pophelp_text\" nowrap></td></tr></table></div>");
function PopHelp(e,mess){ // Event,Message, [show (true/false)],[color (Ex:#00FFFF)]
	var obj = (e.target)? e.target : e.srcElement;
	var args = PopHelp.arguments
	var pophelp = document.getElementById('pophelp')
	var pophelp_text = document.getElementById('pophelp_text')
	if(args.length > 3){
		pophelp.style.color =  args[3]
		pophelp.style.border =  "2px solid "+args[3]
	}
	pophelp_text.innerHTML = (args.length > 1)? args[1] : "";
	pophelp.style.display = (args.length > 2 && args[2] == true)? "" : "none";
	//pophelp.style.top=getOffsetTop(obj)-getOffsetTop(pophelp.offsetParent)+document.body.scrollTop+obj.clientHeight
	//pophelp.style.left=getOffsetLeft(obj)-getOffsetLeft(pophelp.offsetParent)+document.body.scrollLeft
	en = obj
	cleft = 0
	ctop = 0
	
	while (obj.offsetParent){
		cleft += obj.offsetLeft;
		ctop += obj.offsetTop;
		obj = obj.offsetParent;
	}
	
	pophelp.style.top=ctop+en.offsetHeight+'px'
	pophelp.style.left=cleft+'px'
	pophelp.style.left=((cleft + pophelp.offsetWidth) > body_table.offsetWidth)? cleft-(pophelp.offsetWidth - en.offsetWidth)+'px' : cleft+'px'
}

function logout(){
	var domain = ('.'+window.location.hostname).replace('www.','')
	SetCookie('gresid','',0,'/',domain)
	SetCookie('greuid','',0,'/',domain)
	window.location = '../magazine';
}

// Select Element Functions
function addElement(objSelCtrl, strText, strValue, selected){
	var objOptions = objSelCtrl.options;
	var intOptionLength;
	if (objOptions.length < 0){ //IE for Mac 4.5 sets length to -1 if list is empty
		intOptionLength = 0;
	}else{
		intOptionLength = objOptions.length;        
	}
	objOptions[intOptionLength] = new Option(strText, strValue);

	var argv = addElement.arguments;
	var argc = addElement.arguments.length;
	if(argc > 3 && argv[3] == true){
		objOptions[intOptionLength].selected = argv[3]
		//objOptions[intOptionLength].style.background = "#C0DDFA"
	}
}

function ClearElements(what){var walength = what.options.length;for (i = walength; i >= 0; i--){what.options[i] = null}}
// End Select Element options

function open_window(url,id,width,height){ // Additional args: 5) left, 6) top.
	var args = open_window.arguments
	
	var left = (args.length > 4)? args[4] : (screen.availWidth/2)-(width/2)
	var top = (args.length > 5)? args[5] : (screen.availHeight/2)-(width/2)
	setup = 'toolbar=no,location=no,directories=no,status=no,left='+left+',top='+top+',menubar=no,width='+width+',height='+height
	setup += 'scrollbars=no,resizable=no'
	window.open(url,id,setup)
}

var opened_photo = 0;
function showphoto(num,url){
	el = document.getElementById("div_"+num)
	el.style.display = ""
	el.innerHTML = "<a align=\"center\" href=\'\' onclick=\"hide_photo("+num+");return false;\"><< Back</a><br><br><p align=\"center\"><img src=\'"+url+"\'></p>"
	
	el = document.getElementById("part_"+num)
	el.style.display = "none"
	
	
	if(opened_photo != 0){
		hide_photo(opened_photo)
	}
	
	opened_photo = num
}

function hide_photo(num){
	el = document.getElementById("div_"+num)
	el.style.display = "none"
	
	el = document.getElementById("part_"+num)
	el.style.display = ""
	opened_photo = 0
}