// For news frame scrolling

var scrollSpeed = 5;
var scrollTimer = null;

function scrollNs( value ) {
	scrollHeight = -1 * (document.layers["realtimeRankingLayerNS"].document.layers["mainDiv"].clip.height - 150);
	if ( value < 0 && document.layers["realtimeRankingLayerNS"].document.layers["mainDiv"].top > scrollHeight ) {
		document.layers["realtimeRankingLayerNS"].document.layers["mainDiv"].moveBy(0,value);
	}
	else if ( value > 0 && document.layers["realtimeRankingLayerNS"].document.layers["mainDiv"].top < 0 ) {
		document.layers["realtimeRankingLayerNS"].document.layers["mainDiv"].moveBy(0,value);
	}
	else clearInterval(scrollTimer);
}
if (document.layers) {
	funcScrollUp = 'scrollNs(scrollSpeed)';
	funcScrollDown = 'scrollNs(-scrollSpeed);';
}
else if (document.getElementById || document.all) {
	funcScrollUp = 'window.frames["realtimeRankingLayer"].scrollBy(0,-scrollSpeed)';
	funcScrollDown = 'window.frames["realtimeRankingLayer"].scrollBy(0,scrollSpeed)';
}

function rankingScrollUp() {
	scrollTimer = setInterval(funcScrollUp,10);
}
function rankingScrollDown() {
	scrollTimer = setInterval(funcScrollDown,10);
}
function rankingScrollStop() {
	clearInterval(scrollTimer);
}

// End - For news frame scrolling


function checkFrame(tv_path) {
	//alert (parent.name);
	
	/*if (!parent.spot) {
	//if ( (parent.name != 'Window123') || (parent.name != 'spot') ) {
		//alert ("should redirect");
		//alert(tv_path + '?URL=' + document.location.href);
		document.location.href = tv_path + '?URL=' + document.location.href;

	}*/
}

function doPoll(poll_action, total_ans) {
var i = 1;
var checkok = false;

	for (i = 0; i < total_ans; i++) {
		if (document.poll_form.answer[i].checked) {
			checkok = true;
		}
	}


	if ( (checkok) || (poll_action == 'view') ) {
		window.name = 'BaseWin';
		win = window.open('','poll','resizable=1,scrollbars=1,width=450,height=350'); win.focus();
		document.poll_form.poll_action.value = poll_action;
		document.poll_form.submit();
	} else {
		alert("Please select one");
	}

}

function doTellFriend() {
	if (checkEmail(document.tell_friend.email)) {
		document.tell_friend.submit();
		document.tell_friend.recommand.checked = false;
		document.tell_friend.newsletter.checked = false;
		document.tell_friend.email.value = '';
	}
}

function clearValue(obj) {
	//alert (obj.name);
	obj.value = '';
}

function isEmailAddress (string) {
var addressPattern = /^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/;
	return addressPattern.test(string);
}

function checkEmail (field) {
	if (!isEmailAddress(field.value)) {
		alert('請輸入正確的電郵地址');
		field.focus();
		field.select();
		return false;
	}
	return true;
}

function newin2 (url)
	{
		db123Window = window.open(url,"db123Window","toolbar=no,width=650,height=600,directories=no,status=no,resizable=no,menubar=no,scrollbars=yes");
		db123Window = db123Window.focus();
	}
