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 = '';
}