loadLayout = function() {
//	alert('hash = '+a);
var	a = 'layout';
var	b = '';
var	c = function(data,url) { document.getElementById('t').innerHTML = data; C_loc = '';}
HashOpen(a,b,c);
}

loadLink = function() {
var	a = HashPage(window.location.hash);
var	b = '';
var	c = function(data,url) { document.getElementById('content').innerHTML = data; }
var d = new HashOpen(HashPage(window.location.hash),HashVars(window.location.hash),function(data,url) { try {document.getElementById('content').innerHTML = data} catch (e) {loadLink()} });
}

loadForm = function(a) {
if (typeof a[1] == 'object') { a[1] = HashObj(a[1]); }
if (typeof a[1] == 'string') { a[1] = HashObj(document.getElementById(a[1])); }
saveForm(a);

}

var saveForm = function(a) {
	a[0] = HashPage(a[0]);
	a[1] = HashVars(a[0]+':'+a[1]);
	//	alert(a[1]);
	
	window.location.hash=a[0]+':'+a[1];
}

function HashOpen(url,values,action)
{
// var url = HashPage(url2);
var xmlRequest;
try
  {  // Firefox, Opera 8.0+, Safari  
  xmlRequest=new XMLHttpRequest();
	if (xmlRequest.overrideMimeType) {
    	// set type accordingly to anticipated content type
        xmlRequest.overrideMimeType('text/xml');
	 	//http_request.overrideMimeType('text/html');
	}
  }
catch (e)
  {  // Internet Explorer
  try
    {    xmlRequest=new ActiveXObject("Msxml2.XMLHTTP");    }
  catch (e)
    {    try
      {      xmlRequest=new ActiveXObject("Microsoft.XMLHTTP");      }
    catch (e)
      {      alert("Your browser does not support AJAX!");      return false;
      }
    }
  }
  xmlRequest.onreadystatechange=function()
    {
    if(xmlRequest.readyState==4)
      {
      
      data = xmlRequest.responseText;
      action(data,url);
      }
    }
  xmlRequest.open("POST",'/mod/'+url,true);
  xmlRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  xmlRequest.setRequestHeader("Content-length", values.length);
  xmlRequest.setRequestHeader("Connection", "close");
  xmlRequest.send(values);
 }
 
 function HashPage (s) {
 
s += ';'; 

var key = '';
var page = '';


pieces = s.split('');

for (x in pieces) {
	if (x.match("array") != null) {
	} else if (x == 'toJSONString') {
	} else if (pieces[x] == '#') {
	} else if (pieces[x] == ':') {
		var page_q = true;
	} else if (pieces[x] == ';') {
		var page_q = true;
	} else {
		if (!page_q) {
			page += pieces[x];
		}
	}
}
return page;
}
 
 
 function HashVars (s) {
if (s.length-1 != s.lastIndexOf('&')){
s += ';';
} else { var cut = s.lastIndexOf('&') }
if (s.length-1 != s.lastIndexOf('|')){
s += ';';
} else { var cut = s.lastIndexOf('|') }
var key1;
var key = '';
var value = '';
var V = [];
pieces = s.split('');

for (x in pieces) {
	if (stop) {
	} else if (x.match("array") != null) {
	} else if (x == 'toJSONString') {
	} else if (pieces[x] == '#') {
	} else if (pieces[x] == ':') {
		var page_q = true;
	} else if (pieces[x] == '=') {
		var key1 = true;
		var value1 = false;
		var value = '';
	} else if (pieces[x] == '|') {
		if (x==cut){
			var value1 = true;
			var key1 = true;
			V[key] = value;
		} else {
			var value1 = true;
			var key1 = false;
			V[key] = value;
			var key = '';
		}
	} else if (pieces[x] == '&') {
		if (x==cut){
			var value1 = true;
			var key1 = true;
			V[key] = value;
		} else {
			var value1 = true;
			var key1 = false;
			V[key] = value;
			var key = '';
		}
	} else if (pieces[x] == ';') {
		var value1 = true;
		var key1 = true;
		V[key] = value;
		var stop = true;
	} else {
		if (!page_q) {
		} else if (!key1) {
			key += pieces[x];
		} else if (!value1) {
			value += pieces[x];
		} else {
		}
	}
}
var V2='';
		for (i in V) {
		if (i != 'toJSONString'){
		if (i.match("array") != null) {
//		alert(i);
		} else if (V2 != "") {
			   V2 += "&" + i + "=" + encodeURIComponent( V[i] );
		   } else {
			   V2 = i + "=" + encodeURIComponent( V[i] );
		   }
		}
	//	alert(V2);
		}
return V2;
}
/*
window.dhtmlHistory.create({
	toJSON: function(o) {
		return JSON.stringify(o);
	}
	, fromJSON: function(s) {
		return JSON.parse(s);
	}
});

*/

   function HashObj(obj) {
// 	   var poststr = null;
// 	   for (i=0;i<obj.length;i++) {
// 		   if (obj[i].name != "")
// 		   {
// 			   if (poststr != "") {
// 				   poststr = poststr + "&" + obj[i].name + '=' + encodeURIComponent( obj[i].value );
// 			   } else {
// 				   poststr = obj[i].name + '=' + encodeURIComponent( obj[i].value );
// 			   }
// 		   }
// 	   }
// 	   makePOSTRequest(srcfile, poststr,dest);
// 	   
      var getstr = "";
      for (i=0; i<obj.length; i++) {
         if (obj[i].tagName == "INPUT") {
         
            if (obj[i].type == "text") {
               getstr += obj[i].name + "=" + obj[i].value;
			if (i != obj.length) {
				getstr += "&";
			}
            } else
            if (obj[i].type == "hidden") {
               getstr += obj[i].name + "=" + encodeURIComponent(obj[i].value);
			if (i != obj.length) {
				getstr += "&";
			}
            } else
            if (obj[i].type == "checkbox") {
               if (obj[i].checked) {
                  getstr += obj[i].name + "=" + encodeURIComponent(obj[i].value);
               } else {
                  getstr += obj[i].name + "=null";
               }
			if (i != obj.length) {
				getstr += "&";
			}
            } else
            if (obj[i].type == "radio") {
               if (obj[i].checked) {
                  getstr += obj[i].name + "=" + encodeURIComponent(obj[i].value);
			if (i != obj.length) {
				getstr += "&";
			}
		}
            } else { /* alert(obj[i].type);*/ }
         }
         if (obj[i].tagName == "SELECT") {
            var sel = obj[i];
            getstr += sel.name + "=" + encodeURIComponent(sel.options[sel.selectedIndex].value);
		if (i != obj.length) {
			getstr += "&";
		}
         }
	if (obj[i].tagName == "TEXTAREA") {
               getstr += obj[i].name + "=" + encodeURIComponent(obj[i].value);
			if (i != obj.length) {
				getstr += "&";
			}
	}
	//      alert('string = '+getstr);
	
//	if (i == 6) { alert(getstr); }
      }
//	document.getElementById['sideform'].innerHTML = getstr;
      return getstr;
   }
   
   var historyChange = function(newLocation, historyData) {
	//do something;
	loadLink();
	layoverstop();
}

	function layoverstart(url) {
	document.getElementById('layover').style.zIndex = 20;
	document.getElementById('layover').style.visibility = 'visible';

// 	center = (document.body.clientHeight - 325) / 2;
// 	document.getElementById('layover_box2').style.top = center;
// 	document.getElementById('layover_box2').style.height = 325;
// 	document.getElementById('layover_box2').style.width = 700;
	loadXMLDoc(url,'layover_box2');
	layoverjump(1);
	}
	
	function layover_submit(id,url) {
		document.getElementById('layover').style.zIndex = 20;
		submitform(id,url,'layover_box2')
		layoverjump(1);
	}

	function layoverjump_b(cnt) {
	cnt+=1;
		if (cnt > 20) {
				hx = 0;
				eval(document.getElementById('layover_script').innerHTML);
				document.getElementById('layover_script').innerHTML = '';
				if (hx==0) { hx = 325;wx = 700; }
				center = (document.getElementById('layover').offsetHeight - hx) / 2;
				document.getElementById('layover_box2').style.top = center+'px';
				document.getElementById('layover_box2').style.height = hx;
				document.getElementById('layover_box2').style.width = wx;
			/* document.getElementById('debug').innerHTML = hx; */
				document.getElementById('layover').style.visibility = 'visible';
				} else {
				setTimeout("layoverjump_b("+cnt+")",5);
				}
	}

	function layoverjump(cnt) {
	cnt+=1;
		if (document.getElementById('layover_box2').innerHTML != '') {
			if (document.getElementById('layover_script').innerHTML != '') {
				layoverjump_b(1);
			} else {
				setTimeout("layoverjump("+cnt+1+")",5);
			}
		} else if (cnt>2000000) {
//			alert('Your connection was Interrupted.');
		} else {
			setTimeout("layoverjump("+cnt+")",5);
		}
	}
	
	function layoverstop() {
		document.getElementById('layover').style.zIndex = -1;
//		document.getElementById('layover_box').innerHTML = '';
		if (document.getElementById('minivid') != undefined) {
		sendEvent('minivid','stop');
		}

		document.getElementById('layover').style.visibility = 'hidden';
		document.getElementById('layover_box2').innerHTML = '';
//		delete document.getElementById('minivid');
	}

	function startvid(url,loc,id) {
		var so = new SWFObject('\mediaplayer.swf','minivid','358','240','8');
		so.addParam('allowscriptaccess','always');
		so.addParam('allowfullscreen','true');
		so.addVariable('width','360');
		so.addVariable('shownavigation','true');
		
		so.addVariable('height','240');
		so.addVariable('file',loc+url+'.flv');
		so.addVariable('javascriptid','minivid');
		so.addVariable('enablejs','true');
		so.addVariable('backcolor','0x000000');
		so.addVariable('autostart','true');
		if (id == undefined) {
			so.write('layover_box');
		} else {
			so.write(id);
		}
	}
	
function sendEvent(swf,typ,prm) { 
  thisMovie(swf).sendEvent(typ,prm); 
};
function getUpdate(typ,pr1,pr2,swf) {};
function thisMovie(swf) {
  if(navigator.appName.indexOf("Microsoft") != -1) {
    return window[swf];
  } else {
    return document[swf];
  }
};