var $_GET=Array()
$chunks=window.location.href.split("/");
for($x=0; $x<$chunks.length; $x++){
	if($chunks[$x].search("_")){
		$parts=$chunks[$x].split("_");
		$_GET[$parts[0]]=$parts[1];
	}
}
function amILocal($needle){
	$haystack=window.location.href;
	if($haystack.search($needle)>=0){
		return false;
	} else {
		return true;
	}
}
if(amILocal(LIVE_URL)){
	ROOT="http://"+LOCAL_HOST+"/"+LOCAL_FOLDER+"/management/";
	AJAXURLstop="management";
    AJAXlink="/"+LOCAL_FOLDER+"/management/ajax/ajax.php?page=";
} else {
	ROOT="http://"+LIVE_URL+"/management/";
	AJAXURLstop="management";
    AJAXlink="/management/ajax/ajax.php?page=";
}
function createCookie(name,value,days) {
	if(days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}
function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}
URLparts=window.location.href.split("/");
addParts=true;
//AJAXlink="";
for(i=URLparts.length-2; i>0; i--){
	if(URLparts[i]==AJAXURLstop){
		addParts=false;
	}
	if(addParts){
		//AJAXlink+="../";
	}
}
//AJAXlink+="ajax/ajax.php?page=";

window.addEvent("domready", function(){
	$$("div.livesearchbox a").each(function(el){
		el.fader=new Fx.Styles(el, {duration:200, wait:false});
		el.setStyle("background-color", "#FFF");
		el.onmouseover=function(){
			this.fader.start({backgroundColor:"#EEE"});
		}
		el.onmouseout=function(){
			this.fader.start({backgroundColor:"#FFF"});
		}
	});
	$$("input.livesearchbox").each(function(el, count){
		el.searchBox=$$("div.livesearchbox")[count];
		el.searchBox.setStyles({
			height:100,
			border:"solid 1px #999",
			padding:"5px",
			backgroundColor:"#FFF",
			overflow:"auto"
		});
		el.onkeyup=function(){
			children=this.searchBox.childNodes;
			for(i=0; i<children.length; i++){
				if(children[i].tagName=="DIV"){
					if(window.ie){
						string=children[i].innerText;
					} else {
						string=children[i].textContent;
					}
					if(string.test(this.value, "i") || this.value==""){
						$(children[i]).setStyle("display", "block");
					} else {
						$(children[i]).setStyle("display", "none");
					}
				}
			}
		}
	});

});


/*
*  TinyMCE editor
*/
tinyMCE.init({
	// General options
	mode : "textareas",
	editor_selector : "mceEditor",
	theme : "advanced",
	plugins : "safari,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,spellchecker",
	width : page_width,
	height : "400",

	content_css : "/management/styles/mce.css",

	// file browser
	file_browser_callback : 'myFileBrowser',
	relative_urls : false,

	// Theme options
	theme_advanced_buttons1 : "cut,copy,paste,pastetext,pasteword,|,undo,redo,|,search,replace,|,spellchecker,|,nonbreaking,charmap,|,template,visualchars,removeformat,visualaid,preview,fullscreen,cleanup,code,help",
	theme_advanced_buttons2 : "tablecontrols,|,link,unlink,anchor,media,image,|,forecolor,backcolor,|,bullist,numlist",
	theme_advanced_buttons3 : "bold,italic,underline,strikethrough,|,sub,sup,|,outdent,indent,blockquote,|,justifyleft,justifycenter,justifyright,justifyfull,|,styleprops,styleselect,formatselect",
	theme_advanced_toolbar_location : "top",
	theme_advanced_toolbar_align : "left",
	theme_advanced_statusbar_location : "bottom",
	theme_advanced_resizing : true,
	theme_advanced_resize_horizontal : false,
	theme_advanced_resizing_use_cookie : false,
	theme_advanced_resizing_min_height : 300,
	theme_advanced_resizing_max_height : 800,
	theme_advanced_blockformats : "p,h1,h2,h3,blockquote,div",
	//theme_advanced_styles : "",

	spellchecker_languages : "+English (British)=en_gb,English (American)=en_us,Welsh=cy",

	// Example content CSS (should be your site CSS)
	//content_css : editor_stylesheet,

	// Drop lists for link/image/media/template dialogs
	template_external_list_url : "lists/template_list.js",
	external_link_list_url : "lists/link_list.js",
	external_image_list_url : "lists/image_list.js",
	media_external_list_url : "lists/media_list.js"
});


/*
 *  File browser
 */
function myFileBrowser (field_name, url, type, win) {

  //alert("Field_Name: " + field_name + "\nURL: " + url + "\nType: " + type + "\nWin: " + win); // debug/testing

  var cmsURL = path_to_fileman;    // script URL - use an absolute path!
  if (cmsURL.indexOf("?") < 0)
      cmsURL = cmsURL + "?type=" + type;
  else
      cmsURL = cmsURL + "&type=" + type;

  tinyMCE.activeEditor.windowManager.open({
      file : cmsURL,
      title : 'File Browser',
      width : 720,
      height : 510,
      resizable : "no",
      inline : "yes",  // This parameter only has an effect if you use the inlinepopups plugin!
      close_previous : "no"
  }, {
      window : win,
      input : field_name
  });
  return false;
}
