var pathtocms = null;
var path = '/easydrop_beta';
var cms_msg_timer = new Array();
var cms_menu_timer = new Array();
var cms_msg_counter = 4;
var cms_msg = null;
var cms_msg_txt = null;
var cms_msg_img = null;
var cms_msg_button = null;
var cms_login = null;
var cms_loading = null;
var cms_screen_filter = null;
var cms_msg_filter = null;
var cms_load_filter = null;
var closepopup = false;
var cms_popup = null;
var xmlhttp;

function initCMS()
{	
	cms_msg = document.getElementById('cms_msg_view');
	cms_msg_txt = document.getElementById('cms_msg_text');
	cms_msg_img = document.getElementById('cms_msg_img');
	cms_msg_button = document.getElementById('cms_msg_button');
	cms_login = document.getElementById('cms_login_view');
	cms_loading = document.getElementById('cms_loading_view');
	cms_popup = document.getElementById('cms_popup_container');
	cms_screen_filter = document.getElementById('cms_screen_filter');
	cms_msg_filter = document.getElementById('cms_msg_filter');
	cms_load_filter = document.getElementById('cms_load_filter');

	initAdminCMS();
	try
	{
		afterInit();
	}
	catch (err)
	{}

	try
	{
		GMLoad();
	}
	catch (err)
	{
	}

	window.onunload = bodyUnload;
}

function bodyUnload()
{
	try
	{
		GUnload();
	}
	catch (err)
	{
	}
}

function showLoading()
{
	hideCMS_Message();
	cms_load_filter.style.width = document.body.scrollWidth + 'px';
	cms_load_filter.style.height = document.body.scrollHeight + 'px';
	cms_loading.style.display = 'block';
}

function showCMS_Message(type, text)
{
	cms_msg_filter.style.width = document.body.scrollWidth + 'px';
	cms_msg_filter.style.height = document.body.scrollHeight + 'px';	
	if (type == 'login')
	{
		cms_login.style.display = 'block';
	}
	else
	{
		clearTimeout(cms_msg_timer);
		cms_msg_counter = 4;
		var btn_txt = cms_msg_button.value;
		btn_txt = btn_txt.replace('0', cms_msg_counter+1);		
		btn_txt = btn_txt.replace('1', cms_msg_counter+1);
		btn_txt = btn_txt.replace('2', cms_msg_counter+1);
		btn_txt = btn_txt.replace('3', cms_msg_counter+1);
		cms_msg_button.value = btn_txt.replace('4', cms_msg_counter+1);
		cms_msg_txt.innerHTML = text;
		
		if (type == 'error')
		{
			cms_msg_img.src = path+'/layout/images/icon_error.gif';
		}
		else if (type == 'confirm')
		{
			cms_msg_img.src = path+'/layout/images/icon_confirm.gif';
		}
		else if (type == 'notice')
		{
			cms_msg_img.src = path+'/layout/images/icon_notice.gif';
		}
		else if (type == 'help')
		{
			cms_msg_img.src = path+'/layout/images/icon_help.gif';
		}
		
		cms_msg.style.display = 'block';
		cms_msg_timer = setTimeout('countCMS_Message()', 1000);
	}
}

function showPopupCMS_Message(type, text)
{	
	cms_msg_filter.style.width = document.body.scrollWidth + 'px';
	cms_msg_filter.style.height = document.body.scrollHeight + 'px';
	clearTimeout(cms_msg_timer);
	cms_msg_counter = 4;
	var btn_txt = cms_msg_button.value;
	btn_txt = btn_txt.replace('0', cms_msg_counter+1);		
	btn_txt = btn_txt.replace('1', cms_msg_counter+1);
	btn_txt = btn_txt.replace('2', cms_msg_counter+1);
	btn_txt = btn_txt.replace('3', cms_msg_counter+1);
	cms_msg_button.value = btn_txt.replace('4', cms_msg_counter+1);
	cms_msg_txt.innerHTML = text;
		
	if (type == 'error')
	{
		cms_msg_img.src = path+'/layout/images/icon_error.gif';
	}
	else if (type == 'confirm')
	{
		cms_msg_img.src = path+'/layout/images/icon_confirm.gif';
	}
	else if (type == 'notice')
	{
		cms_msg_img.src = path+'/layout/images/icon_notice.gif';
	}
	else if (type == 'help')
	{
		cms_msg_img.src = path+'/layout/images/icon_help.gif';
	}
		
	cms_msg.style.display = 'block';
	cms_msg_timer = setTimeout('countCMS_Message()', 1000);
}

function countCMS_Message()
{
	var btn_txt = cms_msg_button.value;
	btn_txt = btn_txt.replace('0', cms_msg_counter);
	cms_msg_button.value = btn_txt.replace(cms_msg_counter+1, cms_msg_counter);

	if (cms_msg_counter == 0)
	{
		hideCMS_Message();
	}
	else
	{
		cms_msg_counter--;
		cms_msg_timer = setTimeout('countCMS_Message()', 1000);
	}
}

function hideCMS_Message()
{
	cms_msg_filter.style.width = '0px';
	cms_msg_filter.style.height = '0px';
	
	clearTimeout(cms_msg_timer);
	cms_msg_counter = 4;
	cms_msg.style.display = 'none';	
	try
	{
		cms_login.style.display = 'none';
	}
	catch (err)
	{}
	
	if (closepopup)
	{
		closepopup = false;
		window.close();
	}
}

function popUpEnd()
{
	closepopup = true;
}

function popUp(url,title,width,height)
{
	var popup = window.open('', 'cms_photo_pop', 'width='+width+',height='+height);
	popup.moveTo(0,0);
	popup.document.open();
	popup.document.write('<body><head><title>'+title+'<\/title><\/head><body><layer left="0" top="0" id="myID"><img onclick="window.close()" style="position:absolute;left:0px;top:0px;display:block;width:'+width+'px;height:'+height+';" src="'+url+'"\/><\/layer><\/body><\/html>');
	popup.document.close();
}

function submitForm(formid, actionid, actionvalue, confirmvalue)
{
	if (actionid == null)
	{
		if (confirmvalue.length > 1)
		{
			if(confirm(confirmvalue))
			{
				showLoading();
				document.getElementById(formid).submit();
			}
		}
		else
		{
			showLoading();
			document.getElementById(formid).submit();
		}
	}
	else
	{
		if (confirmvalue.length > 1)
		{
			if(confirm(confirmvalue))
			{
				showLoading();
				document.getElementById(actionid).value = actionvalue;
				document.getElementById(formid).submit();
			}
		}
		else
		{
			showLoading();
			document.getElementById(actionid).value = actionvalue;
			document.getElementById(formid).submit();
		}
	}
}

function checkLogInput(e)
{
	if (document.getElementById('login_id').value.length > 0 && document.getElementById('pass_code').value.length > 0)
	{
		if(e && e.which)
		{
			e = e;
			var characterCode = e.which;
		}
		else
		{
			e = event;
			var characterCode = e.keyCode;
		}

		if (characterCode == '13')
		{
			showLoading();
			document.getElementById('cms_login_form').submit();
		}
	}
}

function openImagePopUp(id, num)
{
	var popUpUrl = path+'/classes/php/cms_imagepopup.php&id='+id+'&num='+num;
	window.open(popUpUrl,'cms_photo_pop','toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,width=10,height=10');
}

function showInlinePopup(url)
{
	cms_popup.style.display = 'none';
    cms_popup.innerHTML = '';
    	
	xmlhttp=null;
	if (window.XMLHttpRequest)
  	{
  		// code for all new browsers
  		xmlhttp=new XMLHttpRequest();
  	}
	else if (window.ActiveXObject)
  	{
  		// code for IE5 and IE6
  		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  	}
	if (xmlhttp!=null)
  	{
  		xmlhttp.onreadystatechange=inlinePopupLoaded;
  		xmlhttp.open("GET",url,true);
  		xmlhttp.send(null);
  	}
}

function inlinePopupLoaded()
{
	cms_screen_filter.style.width = document.body.scrollWidth + 'px';
	cms_screen_filter.style.height = document.body.scrollHeight + 'px';
	if (xmlhttp.readyState==4)
  	{
  		if (xmlhttp.status==200)
    	{
    		cms_popup.innerHTML = xmlhttp.responseText;
    		cms_popup.style.display = 'block';
    	}
  	}
}

function hideInlinePopup()
{
	cms_screen_filter.style.width = '0px';
	cms_screen_filter.style.height = '0px';
	cms_popup.style.display = 'none';
	cms_popup.innerHTML = '';
}

function checkNumber(field)
{
	if (isNaN(field.value))
	{
		field.value = '1';
		alert('Geen getal');	
	}
}

function popUpPhoto(url, width, height, caption)
{
	var pop_width = width;
	var pop_height = height;
	var check_width = 0;
	var check_height = 0;
	
 	if (typeof window.innerWidth != 'undefined')
 	{
		check_width = window.innerWidth;
    	check_height = window.innerHeight;
 	}
 	else if (typeof document.documentElement != 'undefined' && typeof document.documentElement.clientWidth != 'undefined' && document.documentElement.clientWidth != 0)
 	{
		// IE6
    	check_width = document.documentElement.clientWidth;
    	check_height = document.documentElement.clientHeight;
 	}
 	else
 	{
 		// older versions of IE
    	check_width = document.getElementsByTagName('body')[0].clientWidth;
    	check_height = document.getElementsByTagName('body')[0].clientHeight;
 	}
	document.getElementById('cms_screen_filter').style.width = check_width+'px';
	document.getElementById('cms_screen_filter').style.height = check_height+'px';
	check_width -= 50;
	check_height -= 50;
	
	if (pop_width > check_width)
	{
		pop_width = check_width;
		pop_height = parseInt(pop_height-(pop_height*((width-check_width)/width)));
	}
	if (pop_height > check_height)
	{
		pop_height = check_height;
		pop_width = parseInt(pop_width-(pop_width*((height-check_height)/height)));
	}
	
	document.getElementById('cms_photo_container').style.display = 'none';
    document.getElementById('cms_photo_container').innerHTML = '';
	document.getElementById('cms_photo_control_container').style.display = 'none';
    document.getElementById('cms_photo_control_container').innerHTML = '';
	if (pop_width < 200)
	{
		if (pop_height < 200)
		{
			var margin = parseInt((200-pop_width)/2);
			var h_margin = parseInt((200-pop_height)/2);
			document.getElementById('cms_photo_container').style.width = '200px';
			document.getElementById('cms_photo_container').style.height = '200px';
			document.getElementById('cms_photo_control_container').style.width = '200px';
			document.getElementById('cms_photo_control_container').style.height = '200px';
			document.getElementById('cms_photo_container').style.top = (((check_height/2)-100)+25) + 'px';
	    	document.getElementById('cms_photo_container').style.left = (((check_width/2)-100)+25) + 'px';
	   		document.getElementById('cms_photo_control_container').style.top = (((check_height/2)-100)+25) + 'px';
	    	document.getElementById('cms_photo_control_container').style.left = (((check_width/2)-100)+25) + 'px';
	    	document.getElementById('cms_photo_container').innerHTML = '<img id="cms_popup_img" src="'+url+'" style="width: '+pop_width+'px; height: '+pop_height+'px; margin-top: '+h_margin+'px; margin-left: '+margin+'px" alt="'+caption+'"/>';
	   	}
		else
		{
			var margin = parseInt((200-pop_width)/2);
			document.getElementById('cms_photo_container').style.width = '200px';
			document.getElementById('cms_photo_container').style.height = pop_height + 'px';
			document.getElementById('cms_photo_control_container').style.width = '200px';
			document.getElementById('cms_photo_control_container').style.height = pop_height + 'px';
	   		document.getElementById('cms_photo_container').style.top = (((check_height/2)-(pop_height/2))+25) + 'px';
	    	document.getElementById('cms_photo_container').style.left = (((check_width/2)-100)+25) + 'px';
	   		document.getElementById('cms_photo_control_container').style.top = (((check_height/2)-(pop_height/2))+25) + 'px';
	    	document.getElementById('cms_photo_control_container').style.left = (((check_width/2)-100)+25) + 'px';
	    	document.getElementById('cms_photo_container').innerHTML = '<img id="cms_popup_img" src="'+url+'" style="width: '+pop_width+'px; margin-left: '+margin+'px" alt="'+caption+'"/>';
	   	}
	}	
	else
	{
		if (pop_height < 200)
		{
			var h_margin = parseInt((200-pop_height)/2);
	    	document.getElementById('cms_photo_container').style.width = pop_width + 'px';
	    	document.getElementById('cms_photo_container').style.height = '200px';
			document.getElementById('cms_photo_control_container').style.width = pop_width + 'px';
			document.getElementById('cms_photo_control_container').style.height = '200px';
	   		document.getElementById('cms_photo_container').style.top = (((check_height/2)-100)+25) + 'px';
	    	document.getElementById('cms_photo_container').style.left = (((check_width/2)-(pop_width/2))+25) + 'px';
	   		document.getElementById('cms_photo_control_container').style.top = (((check_height/2)-100)+25) + 'px';
	    	document.getElementById('cms_photo_control_container').style.left = (((check_width/2)-(pop_width/2))+25) + 'px';
	    	document.getElementById('cms_photo_container').innerHTML = '<img id="cms_popup_img" src="'+url+'" style="height: '+pop_height+'px; margin-top: '+h_margin+'px" alt="'+caption+'"/>';
		}
		else
		{
	    	document.getElementById('cms_photo_container').style.width = pop_width + 'px';
	    	document.getElementById('cms_photo_container').style.height = pop_height + 'px';
			document.getElementById('cms_photo_control_container').style.width = pop_width + 'px';
			document.getElementById('cms_photo_control_container').style.height = pop_height + 'px';
	   		document.getElementById('cms_photo_container').style.top = (((check_height/2)-(pop_height/2))+25) + 'px';
	    	document.getElementById('cms_photo_container').style.left = (((check_width/2)-(pop_width/2))+25) + 'px';
	   		document.getElementById('cms_photo_control_container').style.top = (((check_height/2)-(pop_height/2))+25) + 'px';
	    	document.getElementById('cms_photo_control_container').style.left = (((check_width/2)-(pop_width/2))+25) + 'px';
	    	document.getElementById('cms_photo_container').innerHTML = '<img id="cms_popup_img" src="'+url+'" alt="'+caption+'"/>';
    	}
	} 	
	document.getElementById('cms_photo_control_container').innerHTML = '<div id="cms_popup_close" onclick="closePhoto();" title="Sluiten">X</div><div id="cms_popup_controls"><div id="cms_popup_prev"></div><div id="cms_popup_caption">'+caption+'</div><div id="cms_popup_next"></div></div>';
	document.getElementById('cms_photo_container').style.display = 'block';			
}

function popUpSinglePhoto(url, width, height, caption)
{
	var pop_width = width;
	var pop_height = height;
	var check_width = 0;
	var check_height = 0;
	
 	if (typeof window.innerWidth != 'undefined')
 	{
		check_width = window.innerWidth;
    	check_height = window.innerHeight;
 	}
 	else if (typeof document.documentElement != 'undefined' && typeof document.documentElement.clientWidth != 'undefined' && document.documentElement.clientWidth != 0)
 	{
		// IE6
    	check_width = document.documentElement.clientWidth;
    	check_height = document.documentElement.clientHeight;
 	}
 	else
 	{
 		// older versions of IE
    	check_width = document.getElementsByTagName('body')[0].clientWidth;
    	check_height = document.getElementsByTagName('body')[0].clientHeight;
 	}
	document.getElementById('cms_screen_filter').style.width = check_width+'px';
	document.getElementById('cms_screen_filter').style.height = check_height+'px';
	check_width -= 50;
	check_height -= 50;
	
	if (pop_width > check_width)
	{
		pop_width = check_width;
		pop_height = parseInt(pop_height-(pop_height*((width-check_width)/width)));
	}
	if (pop_height > check_height)
	{
		pop_height = check_height;
		pop_width = parseInt(pop_width-(pop_width*((height-check_height)/height)));
	}
	
	document.getElementById('cms_photo_container').style.display = 'none';
    document.getElementById('cms_photo_container').innerHTML = '';
	document.getElementById('cms_photo_control_container').style.display = 'none';
    document.getElementById('cms_photo_control_container').innerHTML = '';
	if (pop_width < 200)
	{
		if (pop_height < 200)
		{
			var margin = parseInt((200-pop_width)/2);
			var h_margin = parseInt((200-pop_height)/2);
			document.getElementById('cms_photo_container').style.width = '200px';
			document.getElementById('cms_photo_container').style.height = '200px';
			document.getElementById('cms_photo_control_container').style.width = '200px';
			document.getElementById('cms_photo_control_container').style.height = '200px';
			document.getElementById('cms_photo_container').style.top = (((check_height/2)-100)+25) + 'px';
	    	document.getElementById('cms_photo_container').style.left = (((check_width/2)-100)+25) + 'px';
	   		document.getElementById('cms_photo_control_container').style.top = (((check_height/2)-100)+25) + 'px';
	    	document.getElementById('cms_photo_control_container').style.left = (((check_width/2)-100)+25) + 'px';
	    	document.getElementById('cms_photo_container').innerHTML = '<img id="cms_popup_img" src="'+url+'" style="width: '+pop_width+'px; height: '+pop_height+'px; margin-top: '+h_margin+'px; margin-left: '+margin+'px" alt="'+caption+'"/>';
	   	}
		else
		{
			var margin = parseInt((200-pop_width)/2);
			document.getElementById('cms_photo_container').style.width = '200px';
			document.getElementById('cms_photo_container').style.height = pop_height + 'px';
			document.getElementById('cms_photo_control_container').style.width = '200px';
			document.getElementById('cms_photo_control_container').style.height = pop_height + 'px';
	   		document.getElementById('cms_photo_container').style.top = (((check_height/2)-(pop_height/2))+25) + 'px';
	    	document.getElementById('cms_photo_container').style.left = (((check_width/2)-100)+25) + 'px';
	   		document.getElementById('cms_photo_control_container').style.top = (((check_height/2)-(pop_height/2))+25) + 'px';
	    	document.getElementById('cms_photo_control_container').style.left = (((check_width/2)-100)+25) + 'px';
	    	document.getElementById('cms_photo_container').innerHTML = '<img id="cms_popup_img" src="'+url+'" style="width: '+pop_width+'px; margin-left: '+margin+'px" alt="'+caption+'"/>';
	   	}
	}	
	else
	{
		if (pop_height < 200)
		{
			var h_margin = parseInt((200-pop_height)/2);
	    	document.getElementById('cms_photo_container').style.width = pop_width + 'px';
	    	document.getElementById('cms_photo_container').style.height = '200px';
			document.getElementById('cms_photo_control_container').style.width = pop_width + 'px';
			document.getElementById('cms_photo_control_container').style.height = '200px';
	   		document.getElementById('cms_photo_container').style.top = (((check_height/2)-100)+25) + 'px';
	    	document.getElementById('cms_photo_container').style.left = (((check_width/2)-(pop_width/2))+25) + 'px';
	   		document.getElementById('cms_photo_control_container').style.top = (((check_height/2)-100)+25) + 'px';
	    	document.getElementById('cms_photo_control_container').style.left = (((check_width/2)-(pop_width/2))+25) + 'px';
	    	document.getElementById('cms_photo_container').innerHTML = '<img id="cms_popup_img" src="'+url+'" style="height: '+pop_height+'px; margin-top: '+h_margin+'px" alt="'+caption+'"/>';
		}
		else
		{
	    	document.getElementById('cms_photo_container').style.width = pop_width + 'px';
	    	document.getElementById('cms_photo_container').style.height = pop_height + 'px';
			document.getElementById('cms_photo_control_container').style.width = pop_width + 'px';
			document.getElementById('cms_photo_control_container').style.height = pop_height + 'px';
	   		document.getElementById('cms_photo_container').style.top = (((check_height/2)-(pop_height/2))+25) + 'px';
	    	document.getElementById('cms_photo_container').style.left = (((check_width/2)-(pop_width/2))+25) + 'px';
	   		document.getElementById('cms_photo_control_container').style.top = (((check_height/2)-(pop_height/2))+25) + 'px';
	    	document.getElementById('cms_photo_control_container').style.left = (((check_width/2)-(pop_width/2))+25) + 'px';
	    	document.getElementById('cms_photo_container').innerHTML = '<img id="cms_popup_img" src="'+url+'" alt="'+caption+'"/>';
    	}
	} 	
	document.getElementById('cms_photo_control_container').innerHTML = '<div id="cms_popup_close" onclick="closePhoto();" title="Sluiten">X</div>';
	document.getElementById('cms_photo_container').style.display = 'block';			
}

function closePhoto()
{
	document.getElementById('cms_screen_filter').style.width = '0px';
	document.getElementById('cms_screen_filter').style.height = '0px';
	document.getElementById('cms_photo_control_container').style.display = 'none';
	document.getElementById('cms_photo_control_container').innerHTML = '';
	document.getElementById('cms_photo_container').style.display = 'none';
	document.getElementById('cms_photo_container').innerHTML = '';
}