var timerID = 0;

function showHideTimeElm(elm)
{
	//alert("Hide update = " + elm);
	document.getElementById(elm).style.display = 'none';
	//document.getElementById(elm).style.background='transparent';
	//alert('Class' + document.getElementById(elm).className);
	//document.getElementById(elm).className = "";
}

function TimerDone(elm) {
	//alert("Timer Done = " + elm);
	showHideTimeElm(elm);
}

function startTimer(seconds, elm)
{
	//alert("Start timer for " + seconds);
	timerID = setTimeout("TimerDone('" + elm + "')", seconds * 60 * 1000);
//	timerID = setTimeout("TimerDone('" + elm + "')", 1000);
}

function timeTest(day, month, year, hour, minute, elm) {
	var today = new Date();
	var dateSet = new Date(year, month, day, hour, minute, 0);
	var dateCorrection = new Date();
	
	dateCorrection = Math.floor(today - dateSet);
		
	//alert(today);
	//alert(dateSet);
	//alert(dateCorrection);
	
	var second = dateCorrection / 1000;
	//alert(second);
	var minutes = second / 60;
	//alert(minutes);
	if(minutes > 0)
	{
		var rest_minutes = Math.floor(60 - minutes);
		//alert(rest_minutes);
		if(rest_minutes < 0)
			showHideTimeElm(elm);
		else
			startTimer(rest_minutes, elm);
	}
	else
		showHideTimeElm(elm);
}

function newWindowAttach(url, size, x, y) {		
		var properties = "";
		properties += ",location=no";		
		properties += ",menubar=0";	
		properties += ",toolbar=no";
		properties += ",directories=no";		
		if(size)
		{
			properties += ",status=no";
			properties += ",scrollbars=no";
			properties += ",resizable=no";
			properties += ",top=150";
			properties += ",left=660";
			properties += ",width=" + x;
			properties += ",height=" + y;
		}
		else
		{
			properties += ",resizable=yes";
			properties += ",status=yes";
		}
			
    	var w = window.open(url, 'Article', properties);
    	w.focus();
}

function openExtWindow(url, popup_type, size_x, size_y)
{
	//alert("Start window:" + url + "/" + popup_type);
	if(popup_type == 'popup_same')
		location.href = url;
	else if(popup_type == 'popup_size')
		newWindowAttach(url, true, size_x, size_y);
	else if(popup_type == 'popup_new')
		newWindowAttach(url, false, 0, 0);
	else
		location.href = url;
}

//timeTest(4, 9, 2006, 16, 30, 'article330_time');
//showHideTimeElm('article330_time');

function openDiashowPopup(url, type) {
	//alert('URL:' + url + ", Type:" + type);
	if(type == 'edp')
		newWindowAttach(url, true, 740, 650);
	else
		newWindowAttach(url, true, 740, 550);
}

function updatePage(path, end, all, channelIds, id) { 
		//alert('Update page...');
		
		var url = path + '/portal/services/articlelist/reloadNewsticker.jsp?count=' + end + '&channel=' + channelIds + '&id=' + id;
		//alert('Url=' + url); 
		xmlhttp = new XMLHttpRequest();
		xmlhttp.open('GET', url, false); 
		xmlhttp.onreadystatechange = function() {
		  if (xmlhttp.readyState == 4 ) {
			if (xmlhttp.status == 200) {
		   		//alert("URL Exists!");
		   		respTXT = xmlhttp.responseText;
		   		//alert('T=' + respTXT);
		   		document.getElementById('div_newsticker' + id).innerHTML = respTXT;
		   	}
			else if (xmlhttp.status == 404) {
		   		alert("URL doesn't exist!");
			} else {
				alert("Status is " + xmlhttp.status);
			}
		  }
		 }
		xmlhttp.send(null);
		
		//alert('Reload');
		//window.location.reload();
}

function loadjsfile(filename){
	var fileref=document.createElement('script')
	fileref.setAttribute("type","text/javascript")
	fileref.setAttribute("src", filename)

	if (typeof fileref != "undefined")
		document.getElementsByTagName("head")[0].appendChild(fileref)
}

function updateArticleDialog(path) { 
		//alert('Update article dialog old...');
		
		var name = document.getElementById('name').value;
		var fromEmail = document.getElementById('fromEmail').value;
		var toEmail = document.getElementById('toEmail').value;
		var info = document.getElementById('info').value;

		var url = path + '?name=' + name + '&fromEmail=' + fromEmail + '&toEmail=' + toEmail + '&info=' + info;
		
		//alert('Url:' + url);
		
		var xmlhttp = new XMLHttpRequest();
		var respTXT = '';
		xmlhttp.open('GET', url, true);
		xmlhttp.onreadystatechange = function() {
		  if (xmlhttp.readyState == 4 ) {
			if (xmlhttp.status == 200) {
		   		//alert("URL Exists!");
		   		respTXT = xmlhttp.responseText;
		   		//alert('T=' + respTXT);

		   		//js code for recalculating dialog
		   		document.getElementById('js_recommend').innerHTML = respTXT;
		   		document.getElementById('jm_closeDialog').onclick = closeRecommendDialog;
		   	}
			else if (xmlhttp.status == 404) {
		   		alert("URL doesn't exist!");
			} else {
				alert("Status is " + xmlhttp.status);
			}
		  }
		 }
		xmlhttp.send(null);		 
		 
		//alert('Update done');
		return false;
}

function updateArticleDialogInt(path, contPath, id, artPath, memberId) { 
		//alert('Update article dialog...' + contPath + ',' + id + ',' + artPath + ',' + memberId);
		
		var name = document.getElementById('name').value;
		var fromEmail = document.getElementById('fromEmail').value;
		var toEmail = document.getElementById('toEmail').value;
		var info = document.getElementById('info').value;

		var url = path + '?name=' + name + '&fromEmail=' + fromEmail + '&toEmail=' + toEmail + '&info=' + info;
		
		//alert('Url:' + url);
		
		var xmlhttp = new XMLHttpRequest();
		var respTXT = '';
		xmlhttp.open('GET', url, true);
		xmlhttp.onreadystatechange = function() {
		  if (xmlhttp.readyState == 4 ) {
			if (xmlhttp.status == 200) {
		   		//alert("URL Exists!");
		   		respTXT = xmlhttp.responseText;
		   		//alert('T=' + respTXT);
		   		
		   		//load dynamic JS file
		   		loadjsfile(contPath + "/js/indextools.js");
		   		
		   		//tracking code
		   		var tracking_object = createITT();
				tracking_object.DOCUMENTNAME = id;
				tracking_object.DOCUMENTGROUP = artPath;
				tracking_object.ACTION = '04';
				tracking_object.MEMBERID = memberId;
				tracking_object.submit();
		   		
		   		//js code for recalculating dialog
		   		document.getElementById('js_recommend').innerHTML = respTXT;
		   		document.getElementById('jm_closeDialog').onclick = closeRecommendDialog;
		   	}
			else if (xmlhttp.status == 404) {
		   		alert("URL doesn't exist!");
			} else {
				alert("Status is " + xmlhttp.status);
			}
		  }
		 }
		xmlhttp.send(null);		 
		 
		//alert('Update done');
		return false;
}