/* Call AJAX */
function AJAXRequest() {
	var xmlObj = false;
	var CBfunc,ObjSelf;
	ObjSelf=this;
	try { xmlObj=new XMLHttpRequest; }
	catch(e) {
		try { xmlObj=new ActiveXObject("MSXML2.XMLHTTP"); }
		catch(e2) {
			try { xmlObj=new ActiveXObject("Microsoft.XMLHTTP"); }
			catch(e3) { xmlObj=false; }
		}
	}
	if (!xmlObj) return false;
	this.method="POST";
	this.url;
	this.async=true;
	this.content="";
	this.callback=function(cbobj) {return;}
	this.send=function() {
		if(!this.method||!this.url||!this.async) return false;
		xmlObj.open (this.method, this.url, this.async);
		//xmlObj.setRequestHeader("contentType", "text/html;charset=Big5");
		if(this.method=="POST") xmlObj.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
		xmlObj.onreadystatechange=function() {
			if(xmlObj.readyState==4) {
				if(xmlObj.status==200) {// page ok
					ObjSelf.callback(xmlObj);
				}
			}
		}
		if(this.method=="POST") xmlObj.send(this.content);
		else xmlObj.send(null);
	}
	this.readXML=function(){
		this.method="GET";
		this.async=false;
		xmlObj.open (this.method, this.url, this.async);
		xmlObj.send(null);
		return xmlObj.responseXML;
	}
}

function rndTimestamp() {
	var now = new Date();
	var hours = now.getHours();
	var minutes = now.getMinutes();
	var seconds = now.getSeconds();
	var timeValue = "";
	timeValue += ((hours < 10) ? "0" : "") + hours;
	timeValue += ((minutes < 10) ? "0" : "") + minutes;
	timeValue += ((seconds < 10) ? "0" : "") + seconds;
	var randomnumber = Math.floor(Math.random()*11);
	return timeValue + randomnumber;
}

function loadDyJs(scriptSrc) {
	var dyJS = document.getElementById("dyJS");
	if (dyJS) {
		if (document.all) {
			dyJS.src = scriptSrc;
		} else {
			var pp1 = dyJS.parentNode;
			pp1.removeChild(dyJS); // remove old js
			var oHead = document.getElementsByTagName('HEAD').item(0);
			var oScript= document.createElement("script");
			oScript.id = "dyJS";
			oScript.type = "text/javascript";
			oScript.src = scriptSrc;
			oHead.appendChild(oScript);
		}
	}
}

function addClickLog() {
	loadDyJs("/js/cl.asp?t1=" + rndTimestamp());
}

function fbs_click() {
	u=location.href;
	t=document.title;
	window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'&t='+encodeURIComponent(t),'sharer','toolbar=0,status=0,width=626,height=436');
	return false;
}


function showBlogItNow(refBlogTitle, refBlogAbstract, refContentSource, refContentDate) {
	var tmpHasLogined = false;
	try {
		if (blog_f && blog_f != '') {
			tmpHasLogined = true;
			var tmp_thisPageQueryString = window.location.search.substring(1);
			if (tmp_thisPageQueryString.indexOf('backAction=blogItNow') != -1) { // auto redirect to blog
				blogItNow(refBlogTitle, refBlogAbstract, refContentSource, refContentDate);
			}
		}
	}
	catch (eee1){}
	if (tmpHasLogined) {
		document.write('<a href="javascript:void(0);" onclick="blogItNow(\''+refBlogTitle+'\', \''+refBlogAbstract+'\', \''+refContentSource+'\', \''+refContentDate+'\');"><img src="/blog/images/icon1_08.gif" border="0"></a></td>');
	} else {
		var tmp_currentURL = location.href;
		if (tmp_currentURL.indexOf('?') != -1) {
			tmp_currentURL += '&backAction=blogItNow';
		} else {
			tmp_currentURL += '?backAction=blogItNow';
		}
		var tmp_loginURL = '/membership/login.asp?back_url=' + encodeURIComponent(tmp_currentURL);
		document.write('<a href="'+tmp_loginURL+'"><img src="/blog/images/icon1_08.gif" border="0"></a></td>');
	}
}

function blogItNow(refBlogTitle, refBlogAbstract, refContentSource, refContentDate) {
	var _hiddenForm = document.createElement("form");
	_hiddenForm.id = '_blogItNowForm20090618';
	_hiddenForm.name = '_blogItNowForm20090618';
	_hiddenForm.action = 'http://blogcity.me/blog/post_blog.asp';
	_hiddenForm.method = 'POST';
	_hiddenForm.innerHTML = '<input type="hidden" name="_refBllogTitle"><input type="hidden" name="albumContent" /><input type="hidden" name="_refContentSource" />';
	try {
		var refSectionURL = '';
		var refSectionName = '';
		var _blogContent = '';
		if (refContentSource == 'ent') {
			refSectionURL = '/ent/';
			refSectionName = '娛樂版';
		}
		if (refContentSource == 'dailynews') {
			refSectionURL = '/dailynews/';
			refSectionName = '日報新聞';
		}
		if (refContentSource == 'finance') {
			refSectionURL = '/finance/';
			refSectionName = '財經版';
		}
		if (refContentSource == 'travel') {
			refSectionURL = '/travel/';
			refSectionName = '旅遊版';
		}
		if (refContentSource == 'dining') {
			refSectionURL = '/dining/';
			refSectionName = '飲食版';
		}
		if (refContentSource == 'digital') {
			refSectionURL = '/digital/';
			refSectionName = '數碼版';
		}
		if (refContentSource == 'car') {
			refSectionURL = '/car/';
			refSectionName = '汽車版';
		}
		if (refContentSource == 'living') {
			refSectionURL = '/living/';
			refSectionName = '生活版';
		}
		if (refContentSource == 'beauty') {
			refSectionURL = '/beauty/';
			refSectionName = '美容版';
		}
		if (refContentSource == 'fortune') {
			refSectionURL = '/fortune/';
			refSectionName = '星相版';
		}
		if (refContentSource == 'shopping') {
			refSectionURL = '/shopping/';
			refSectionName = '潮流時尚版';
		}
		if (refContentSource == 'home') {
			refSectionURL = '/home/';
			refSectionName = '家居版';
		}
		if (refContentSource == 'pet') {
			refSectionURL = '/pet/';
			refSectionName = '寵物版';
		}
		if (refContentSource == 'arts') {
			refSectionURL = '/arts/';
			refSectionName = '藝術版';
		}
		if (refContentSource == 'racing') {
			refSectionURL = '/racing/';
			refSectionName = '馬經版';
		}
		if (refContentSource == 'columnist') {
			refSectionURL = '/dailynews/headlinenewslist.asp';
			refSectionName = '專欄';
		}
		if (refContentSource == 'shop') {
			refSectionURL = '/shop/';
			refSectionName = '旺鋪';
		}
		if (refContentSource == 'album') {
			refSectionURL = '/album/';
			refSectionName = '相簿';
		}
		if (refContentSource == 'forum') {
			refSectionURL = '/forum/';
			refSectionName = '論壇';
		}
		if (refContentSource == 'instant') {
			refSectionURL = '/instantnews/instantnews.html';
			refSectionName = '即時新聞';
		}
		document.body.appendChild(_hiddenForm);
		if (refBlogAbstract.length > 0) {
			var _theOriginalURL = location.href;
			_theOriginalURL = _theOriginalURL.replace('#', '');
			_theOriginalURL = _theOriginalURL.replace('backAction=blogItNow', '');
			_blogContent += '<b>' + refBlogTitle + '</b><br/>';
			if (refContentDate && refContentDate != '') {
				_blogContent += '<font size="1" color="#666666">' + refContentDate + '</font><br/><br/>';
			}
			if (refBlogAbstract.length > 300) {
				refBlogAbstract = refBlogAbstract.substring(0, 300) + "...";
			}
			_blogContent += '　　' + refBlogAbstract + " <a href='"+_theOriginalURL+"'><font color='#666666' size='2'>[詳細內文]</font></a>";
			if (refSectionName != '' && refSectionURL != '') {
				_blogContent += ' <a href="'+refSectionURL+'"><font color="#666666" size="2">[' + refSectionName + ']</font></a><br/><br/>';
			}
		}
		//_hiddenForm._refBllogTitle.value = refBlogTitle;
		_hiddenForm._refBllogTitle.value = '';
		_hiddenForm.albumContent.value = _blogContent;
		_hiddenForm._refContentSource.value = refContentSource;
		_hiddenForm.submit();
	}
	catch (err){
		//window.alert(err);
	}
}

var serverDomainName = window.location.toString().split("//")[1].split("/")[0];
var imageServerDoamin = 'img.hkheadline.com';
if (serverDomainName != '') {
	//www.hkheadline.com
	if (serverDomainName == 'hkheadline.com') {
		imageServerDoamin = 'img.hkheadline.com';
	} else if (serverDomainName == 'www.hkheadline.com') {
		imageServerDoamin = 'img.hkheadline.com';
	//www.hkheadline.com
	} else if (serverDomainName == 'hkheadline.com.hk') {
		imageServerDoamin = 'img.hkheadline.com.hk';
	} else if (serverDomainName == 'www.hkheadline.com.hk') {
		imageServerDoamin = 'img.hkheadline.com.hk';
	//www.hkhl.hk
	} else if (serverDomainName == 'hkhl.hk') {
		imageServerDoamin = 'img.hkhl.hk';
	} else if (serverDomainName == 'www.hkhl.hk') {
		imageServerDoamin = 'img.hkhl.hk';
	//www.h1.hk
	} else if (serverDomainName == 'h1.hk') {
		imageServerDoamin = 'img.h1.hk';
	} else if (serverDomainName == 'www.h1.hk') {
		imageServerDoamin = 'img.h1.hk';
	//www.h1.com.hk
	} else if (serverDomainName == 'h1.com.hk') {
		imageServerDoamin = 'img.h1.com.hk';
	} else if (serverDomainName == 'www.h1.com.hk') {
		imageServerDoamin = 'img.h1.com.hk';
	} else {
	//default
		imageServerDoamin = 'img.hkheadline.com';
	}
}



function printdiv(printpage)
{
var headstr = "<html><head><title></title></head><body>";
var footstr = "</body>";

var newstr = document.getElementById(printpage).innerHTML;
var oldstr = document.body.innerHTML;
document.body.innerHTML = headstr+newstr+footstr;
window.print(); 
document.body.innerHTML = oldstr;
return false;
}
