//<![CDATA[
/*
	// Toolip htmlTooltip
	var myTips = new Tips($$('.htmlTooltip'), {
		timeOut: 700,
		maxTitleChars: 50,
		maxOpacity: .9
	});
*/
	var sitemanager = $('sitemanager');
	var contentcontainer = 'contentcontainer';
	var boldaction;
	var billboardValue;

	window.addEvent('domready', function() {
		if($('support-menu')){
			var myMenu = new MenuMatic({id: 'support-menu'});
		}
	});

	//setCNETAssetBaseHref(baseurl+'sitemanager/includes/clientside');

	// navigation and POST data;
 	function doAction(command,fieldname,fieldvalue,actiontype,idfield)
 	{
		if(!idfield){
			var idfield = contentcontainer;
		}
		if($('sortby')){
			$('sortby').setProperty('value',null);
		}
		var myFx = new Fx.Tween($('sitemanager'));
 		myFx.start('opacity', 0.5);
		$('progressbar').setStyle('display', 'block');

		// set style of command and command to execute
		if(command && command != ''){
			$('sitemanagerevent').setProperty('value',command);
			newaction	= $('sitemanagerevent').getProperty('value');

			if($(newaction+'_'+fieldvalue)){
				newaction	= newaction+'_'+fieldvalue;
			}

			if($(newaction)){
				if($(boldaction)) $(boldaction).setStyle('font-weight','normal');

				$(newaction).setStyle('font-weight','bold');
				boldaction	= newaction;
			}
		}

		// set extra fieldname + value
		if($(fieldname) && typeof(fieldvalue) != 'undefined')	{ $(fieldname).setProperty('value',fieldvalue);}

		//get rich text edit to save content
		$$('textarea.tinymce').each( function(el){
			tinyMCE.triggerSave();
			tinyMCE.execCommand('mceFocus', false, el.id);
		   	tinyMCE.execCommand( 'mceRemoveControl', false, el.id );
		});

		//get date popups to close
		$$('.datepopup').each( function(el){
			eval('datepopup'+el.id ).hide();
		});


		// set response format
		if(!actiontype || actiontype == '')	{var actiontype = 'body';}
		$('actiontype').setProperty('value',actiontype);

		// do a 'normal' Post call if we want the full HTML
		if(actiontype=='html'){
			doNormalPost();
		}else{
            doAjaxCall(idfield,null,actiontype,true);
        }
		return;
	}

	function doNormalPost(){
		$('actiontype').setProperty('value', 'html');
		var myFx = new Fx.Tween($('sitemanager'));
 		myFx.start('opacity', 0.5);
		$('progressbar').setStyle('display', 'block');
		$('sitemanagerform').submit();
		return false;
	}

	// navigation and POST data;
 	function doAXAction(idfield,action, fieldname, fieldvalue, actiontype,postfunction)
	{
		if(!actiontype)
			actiontype	= 'body';

		// set extra fieldname + value
		if (fieldvalue && fieldvalue != '') {
			$(fieldname).setProperty('value', fieldvalue);
		}
		doAjaxCall(idfield,action,actiontype,postfunction);
	}

	// htmlModal
	function doAjaxCall(idfield,action,actiontype,postfunction)
	{
		if(action)
			$('sitemanagerevent').setProperty('value',action);


		if(!actiontype || actiontype == true)
			$('actiontype').setProperty('value','body');

		$('sitemanagerform').toQueryString();

		var actionUrl = 'index.php';
		// does not work in MSIE
		//	var actionUrl = $('miniopslagform').getProperty('action');

		// hide submenu's
		$$('.smOW').setStyle('display','none');


		new Request.HTML({
			url: actionUrl,
			update: $(idfield),
			method: 'post',
			async: false,
			evalScripts: true,
			evalResponse: true,
			onComplete: function(){
				var myFx = new Fx.Tween($('sitemanager'));
				myFx.start('opacity', 1);
				$('progressbar').setStyle('display','none');
				if(postfunction)
					loadModuleFunctions();
				this.fireEvent('load');
			},
			onCancel: function(){
				var myFx = new Fx.Tween($('sitemanager'));
				myFx.start('opacity', 1);
				$('progressbar').setStyle('display','none');
			}
		}).send($('sitemanagerform').toQueryString());

		return;
	}

	// htmlModal
	function showPopup(popupid,title,content){
		if (window.popup[popupid]){
     			window.popup[popupid].destroy();
   		}
	//	var ypos=xpos;
	 	window.popup[popupid] = 	new StickyWinFx({
		  draggable: true,
		  resizable: true,
		  position: 'center',
//		  offset: {x: parseInt(xpos),y: parseInt(ypos)},
			fadeDuration: 250,
			content: stickyWinHTML(title, "<div id='stickyWinContent"+popupid+"' ></div>" , {
//		   		baseHref: baseurl+'sitemanager/css/stickyWinHTML/',
				width: '620px'
			  })
		});
	}


	function addMetaData(fieldname,metadatafield){
		var fieldname = $(fieldname).getProperty('value');
		var metadata = $(metadatafield).getProperty('value');
		fieldname.split(" ").each(function(item){
				if(!metadata.contains(item.toLowerCase())){ metadata	= metadata+' '+item.toLowerCase(); }
		});
		$(metadatafield).setProperty('value',metadata.trim());
		return;
	}


	function removeMetaData(fieldname,metadatafield){

		var fieldname 	= $(fieldname).getProperty('value');
		var metadata 	= $(metadatafield).getProperty('value');
		var startdata	= '';

		fieldname		= fieldname.toLowerCase();

		metadata.split(" ").each(function(item){
				if(!fieldname.contains(item.toLowerCase()))
					startdata	= startdata+' '+item.toLowerCase();
		});
		$(metadatafield).setProperty('value',startdata.trim());

		return;
	}

	function loadModuleFunctions(){
	// add an event that performs update after releasing the mouse

		//authentication
		if($('authenticationLogin')){	$('username').focus();	}

		// give title field focus AND parse Metadata based on title
		var metadata	=  new Array('content');
		metadata.each(function(item){
			if($(item+'Title')){
				$(item+'Title').focus();
		    	$(item+'Title').addEvent('focus', function() { removeMetaData(item+'Title',item+'MetaData')  });
				$(item+'Title').addEvent('blur', function() { addMetaData(item+'Title',item+'MetaData')  });
			}
		});

		// search field from navigation
		if($('searchField')){	$('searchField').focus();	}

		// catch onEnter

//		$('sitemanagerform').addEvent('submit', function(e) {
//			new Event(e).stop();
//      if (document.getElementById('submit') != null) {
//        if($('submit').getProperty('name')){
//          doAction($('submit').getProperty('name'));
//        }
//      }
//		});

		// media list search functionality
		if($('mediaFilter')){$('mediaFilter').addEvent('click', function(){ myTable.filter('sitemanagerform');	});}
	}

	function getProductHighlights(){


	}


	function doConfirmAction(tekst,command,fieldname,fieldvalue,actiontype)
	{
		var command;
		var fieldname;
	    var fieldvalue;
	    var actiontype;

		if(tekst == '1' || tekst == '' )
			tekst = "Are you sure you want to delete this item?";

	    var agree=confirm(tekst);
		if (agree)
		{
			doAction(command,fieldname,fieldvalue,actiontype)
			return true ;
		}
		else
		{
			return false ;
		}
	}

	var state;
	function showhide(id)
	{
		var obj = document.getElementById(id);
		state = obj.style.display;
		if( state == 'none')
		{
			state = 'block';
			var obj = document.getElementById(id);
			document.images.showimg.src = 'images/minus.png'
		}else{
			state = 'none';
			document.images.showimg.src = 'images/plus.png'
		}
		obj.style.display = state;
	}



	function highlight_on()
	{
		window.event.srcElement.style.color='#DCE1E4';
		window.event.srcElement.style.background='#ffffff';
		return true;
	}


	function highlight_off()
	{
		window.event.srcElement.style.color='#ffffff';
		window.event.srcElement.style.background='#DCE1E4';
		return true;
	}



	function doPopupAction(command,fieldname,fieldvalue)
	{
	    if(fieldname)
	        extrafield   = '&'+fieldname+'='+fieldvalue;
	    else
	        extrafield   = '';

	    window.open('popup.php?event='+command+extrafield, 'popup', 'toolbar=no,menubar=no,location=no,resizable=yes,scrollbars=no,width=400,height=400');
	    return true;

	}




	function escapeHTML (str)
	{
	   var div = document.createElement('div');
	   var text = document.createTextNode(str);
	   div.appendChild(text);
	   return div.innerHTML;
	}



	function checkContractFields(selection)
	{
		var selection;
		var cValue = document.sitemanagerform.catalogusID.options[selection].text;
		var domeinreg = new RegExp("Domeinregistratie");
		var hostingreg = new RegExp("Hosting");

		if( cValue.match(domeinreg) || cValue.match(hostingreg) )
			document.getElementById('selectDomain').style.display		= 'block';
		else
			document.getElementById('selectDomain').style.display		= 'none';

	  	if (cValue.match(domeinreg)) {
			document.getElementById('selectServer').style.display		= 'none';
			document.getElementById('selectUsername').style.display		= 'none';
			document.getElementById('selectPassword').style.display		= 'none';
			document.getElementById('selectContract').style.display		= 'block';
		}else if(cValue.match(hostingreg)) {
			document.getElementById('selectContract').style.display		= 'none';
			document.getElementById('selectServer').style.display		= 'block';
			document.getElementById('selectUsername').style.display		= 'block';
			document.getElementById('selectPassword').style.display		= 'block';

		} else {
			document.getElementById('selectContract').style.display		= 'none';
			document.getElementById('selectServer').style.display		= 'none';
			document.getElementById('selectUsername').style.display		= 'none';
			document.getElementById('selectPassword').style.display		= 'none';

		}
		return;
	}


	function checkTicketField(selection)
	{
		var selection;
		var cValue = document.sitemanagerform.catalogusID.options[selection].text;
		var fixedprice = new RegExp("Fixed");


		if( cValue.match(fixedprice))
			document.getElementById('fixedPrice').style.display		= 'block';
		else
			document.getElementById('fixedPrice').style.display		= 'none';

		return;
	}


	function setTicketField()
	{
		if (document.sitemanagerform.catalogusID) {
			selected = new Array();
			for (var i = 0; i < document.sitemanagerform.catalogusID.options.length; i++)
				if (document.sitemanagerform.catalogusID.options[i].selected)
					return checkTicketField(i);
		}
	}

	function setContractFields()
	{
		if (document.sitemanagerform.catalogusID) {
			selected = new Array();
			for (var i = 0; i < document.sitemanagerform.catalogusID.options.length; i++)
				if (document.sitemanagerform.catalogusID.options[i].selected)
					return checkContractFields(i);
		}
	}

	function resetValue(selectBoxID){
		var selectBox	= document.getElementById(selectBoxID);
  		selectedItem = selectBox[selectBox.selectedIndex];
  		selectedItem.value = '';
	}

var checkflag = "true";
	function check(field)
	{
		if (checkflag == "false")
		{
			for (i = 0; i < field.length; i++)
			{
				if(field[i])
					field[i].checked = true;
			}
			checkflag = "true";

			return "selecteer niks";
		}
		else
		{
			for (i = 0; i < field.length; i++)
  			{
				if(field[i])
					field[i].checked = false;
			}
			checkflag = "false";
			return "selecteer alles";
		}
	}
//]>

