window.addEvent('domready', function() {
	
	//create our Accordion instance
	myAccordion = new Accordion($('accordion'), 'h3.toggler', 'div.element', {
		onActive: function(toggler, element){
			toggler.setStyle('color', '#fff');
		},
		onBackground: function(toggler, element){
			toggler.setStyle('color', '');
		}
	});
});

function initTabs() {
	$ES('a','tabMenu').each(function(el) {
		el.addEvent('click',function(e) {
			var ev = new Event(e).stop();
			tabState(el);
		});
	});
}

function tabState(ael) {
	$ES('a','tabMenu').each(function(el) {
		if(el.hasClass('tab_active')) {
			el.removeClass('tab_active');
		}
	});
	ael.addClass('tab_active');
	$$('#tabContent div.tab_content').each(function(el) {
		if(el.hasClass('tab_active')) {
			el.removeClass('tab_active');
		}
	});
	var acu = ael.getProperty('href');
	var ac = acu.replace(/#/, '');
	$(ac).addClass('tab_active');
}
function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}


	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}



function revealModal(divID)
{
window.scrollTo(0,0);
var objOverlay = document.getElementById(divID);
var arrayPageSize = getPageSize();
	objOverlay.style.height = (arrayPageSize[1] + 'px');
	objOverlay.style.display = 'block';
	
}
function browseServer(field, type) {
	window.SetUrl=function(value){
		document.getElementById(field).value=value;
		}
		URL = window.location.href;
		var urldir = unescape(URL.substring(0,(URL.lastIndexOf("/")) + 1))
		var filemanager='js/fckeditor/editor/filemanager/browser/default/browser.html';
		var connector=urldir+'js/fckeditor/editor/filemanager/browser/default/connectors/php/connector.php';
		window.open(filemanager+'?Type='+type+'&Connector='+connector+'','fileupload','modal,width=700,height=500');
}
function validateForm(msg, fields, fields_names)
    {

	var fields = fields.split("|");
	var fields_names = fields_names.split("|");
	for(i = 0; i < fields.length; i++){
		var x=fields[i];
	document.getElementById(x).style.background = ''; 
	if (document.getElementById(x).value == "") {
		document.getElementById(x).style.background = 'azure'; 
		document.getElementById(x).focus()
	    alert("" + msg + " ('" + fields_names[i] + "')");
		 return false;
		}
	}

	revealModal('loading');
}

function unCheckRadio(oRadio) {
      var or = document.getElementsByName(oRadio);
      for (var i = 0; i < or.length; i++) {
         or[i].checked = false;
     }
}

function checkUncheckAll(theElement) {
     var theForm = theElement.form, z = 0;
	 for(z=0; z<theForm.length;z++){
      if(theForm[z].type == 'checkbox' && theForm[z].name != 'scb0' && theForm[z].name.substr(0,3) == 'scb'){
	  theForm[z].checked = theElement.checked;
	  //theForm[z].disabled = theElement.checked;

	  }
     }
}


function selectcheckbox(checkboxId,divID) {
	el = document.getElementById(checkboxId);
	el2 = document.getElementById(divID);
		if (!el.checked) {
		el.checked=true;
		if (el2)
		{
		el2.style.backgroundColor='paleturquoise';
		}

	}
	else {
		el.checked=false;
		if (divID)
		{
		el2.style.backgroundColor='';
		}
	}

}

function copytoclipboard(text2copy) {
  if (window.clipboardData) {
    window.clipboardData.setData("Text",text2copy);
  } else {
    var flashcopier = 'flashcopier';
    if(!document.getElementById(flashcopier)) {
      var divholder = document.createElement('div');
      divholder.id = flashcopier;
      document.body.appendChild(divholder);
    }
    document.getElementById(flashcopier).innerHTML = '';
    var divinfo = '<embed src="js/_clipboard.swf" FlashVars="clipboard='+escape(text2copy)+'" width="0" height="0" type="application/x-shockwave-flash"></embed>';
    document.getElementById(flashcopier).innerHTML = divinfo;
  }
}

function confirmSubmit(Url,Msg) {
  if (confirm(Msg)) {
    document.location = Url;
	  revealModal('loading');
  }
}

function show(itemID,srcID) {
	el = document.getElementById(itemID);
	el2 = document.getElementById(srcID);
	if (el) {
		el.style.visibility = 'visible';
		el.style.display = 'block';
	}
		if (srcID)
		{
			el2.src='images/hide.gif';
		}
}

function hide(itemID,srcID) {
	el = document.getElementById(itemID);
	el2 = document.getElementById(srcID);
	if (el) {	

		el.style.visibility = 'hidden';
		el.style.display = 'none';
	}
			if (srcID)
		{
		el2.src='images/show.gif';
		}
}

function hideall() {
	var num = document.getElementById('num').value;
	for(i=0;i<=num;i++)
		hide('d'+i);
}


function shide(itemID) {
	hideall();
	show(itemID);
}

function showhide(itemID,srcID) {
	el = document.getElementById(itemID);
	el2 = document.getElementById(srcID);
		if ((el) && (el.style.visibility == 'hidden')) {
		el.style.visibility = 'visible';
		el.style.display = 'block';
		if (srcID)
		{
			el2.src='images/hide.gif';
		}

	}
	else {

		el.style.visibility = 'hidden';
		el.style.display = 'none';
			if (srcID)
		{
		el2.src='images/show.gif';
		}
	}

}


function land(ref, target)
{
	lowtarget=target.toLowerCase();
	if (lowtarget=="_self") {window.location=loc;}
	else {if (lowtarget=="_top") {top.location=loc;}
	else {if (lowtarget=="_blank") {window.open(loc);}
	else {if (lowtarget=="_parent") {parent.location=loc;}
	else {parent.frames[target].location=loc;};
	}}}
	}
	function jump(menu)
	{
	ref=menu.choice.options[menu.choice.selectedIndex].value;
	splitc=ref.lastIndexOf("*");
	target="";
	if (splitc!=-1)
	{loc=ref.substring(0,splitc);
	target=ref.substring(splitc+1,1000);}
	else {loc=ref; target="_self";};
	if (ref != "") {land(loc,target);}
}



//CENTERED WINDOW
		function openCenteredWindow(url, width, height) {
			var screenWidth  = screen.availWidth;
			var screenHeight = screen.availHeight;
			var left = (screenWidth - width)/2;
			var top = (screenHeight - height)/2;
			si_window=window.open('', "_blank", "toolbar=no, location=no, menubar=no, resizable=no, status=no, width="+width+", height="+height+",left="+left+",top="+top);
			si_window.document.open();
			si_window.document.writeln('<html><head>');
			si_window.document.writeln('<style type="text/css" media="screen">');
			si_window.document.writeln('<!--');
			si_window.document.writeln('  body { margin: 0px; padding: 0px; }');
			si_window.document.writeln('-->');
			si_window.document.writeln('</style>');
			si_window.document.writeln('</head><body">');
			si_window.document.writeln('<img src="' + url + '">');
			si_window.document.writeln('</body></html>');
			si_window.document.close();
	}
