function $(val){
	return document.getElementById(val);	
}
function findPos(obj) {
	var pos = new Array();
	if (obj.offsetParent) {
		pos[0] = obj.offsetLeft;
		pos[1] = obj.offsetTop;
		while (obj = obj.offsetParent) {
			pos[0] += obj.offsetLeft;
			pos[1] += obj.offsetTop;
		}
	}
	return pos;
}
function GetXmlHttpOBJ(){ 
	var objXMLHttp=null;
	if (window.XMLHttpRequest) objXMLHttp=new XMLHttpRequest();
	else if (window.ActiveXObject)	objXMLHttp=new ActiveXObject('Microsoft.XMLHTTP');
	return objXMLHttp;
}
function setCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}
function getCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}
function deleteCookie(name) {
	setCookie(name,"",-1);
}
function ElmWidth(obj){
	if(obj.clientWidth) return obj.clientWidth;
	else return obj.offsetWidth;
}
function ElmHeight(obj){
	if(obj.clientHeight) return obj.clientHeight;
	else return obj.offsetHeight;
}
function setOpacity(Obj,opacity) {
	Obj.style.opacity = (opacity / 100);
	Obj.style.MozOpacity = (opacity / 100);
	Obj.style.KhtmlOpacity = (opacity / 100);
	Obj.style.filter = "alpha(opacity=" + opacity + ")";
}
function getavailHeight() {
  if( typeof( window.innerHeight ) == 'number' )	var y = window.innerHeight;
  else if( document.documentElement && document.documentElement.clientHeight) var y = document.documentElement.clientHeight;
  return y;
}
function getavailWidth() {
  if( typeof( window.innerWidth ) == 'number' )	var x = window.innerWidth;
  else if( document.documentElement && document.documentElement.clientWidth) var x = document.documentElement.clientWidth;
  return x;
}
function getscrollTop(){
   var h = window.pageYOffset || document.body.scrollTop || document.documentElement.scrollTop;          
   return h ? h : 0;
}
function getscrollLeft(){
   var l = window.pageXOffset || document.body.scrollLeft || document.documentElement.scrollLeft;          
   return l ? l : 0;
}
var mposx = 0;
var mposy = 0;
function mpos(e){
	if(!e) var e = window.event;
	if(e.pageX || e.pageY){
		mposx = e.pageX;
		mposy = e.pageY;
	}else if(e.clientX || e.clientY){
		mposx = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
		mposy = e.clientY + document.body.scrollTop + document.documentElement.scrollTop;
	}
}
function toggleDisplay(val){
	if($(val).style.display == "block") $(val).style.display = "none";
	else $(val).style.display = "block";
}
function selectedText(){
	if (document.getSelection)	var str = document.getSelection();
	else if (document.selection && document.selection.createRange)	var str = document.selection.createRange().text;
	return str;
}
function trim(str){ 
	while (str.substring(0,1) == ' '){ 
		str = str.substring(1, str.length); 
	} 
	while (str.substring(str.length-1, str.length) == ' '){ 
		str = str.substring(0,str.length-1); 
	} 
	return str; 
}
var group_x = new Array();
var ar_r = new Array();
function ww(obj,val){
	group_x = new Array();
	val = trim(val);
	ar_r = val.split(" ");
	switched(obj,0);
	return group_x;		
}
function ss(val){
	group_x = new Array();
	val = trim(val);
	ar_r = val.split(" ");
	if(val.substr(0,1)!="#"){
		switched(document.body,0);	
	}else if($(ar_r[0].substr(1))){
		if(ar_r.length>1) switched($(ar_r[0].substr(1)),1);
		else group_x.push($(ar_r[0].substr(1)));
	} 
	return group_x;	
}
function switched(obj,val){
	var text = ar_r[val];
	var val_head = text.substr(0,1);
	var val_text = text.substr(1);
	if(val_head==".")	findC(obj,val);
	else if(val_head=='#'){
		if(val==(ar_r.length-1))	group_x.push($(val_text));
		else switched($(val_text),val+1);
	}else if(val_head=='>')	findE(obj,val,false);
	else if(text)	findE(obj,val,true);
	else switched(obj,++val);
}
function findC(obj,val){
	var text = ar_r[val].substr(1);
	var i=0;
	var robj = obj.childNodes;
	var ok = 0;
	while(robj[i]){
		ok = 0;
		if(robj[i].className){
			var n = robj[i].className.split(" ");	
			var j = 0;
			while(n[j]){
				if(n[j]==text) ok = 1;
				j++;	
			}
		}			
//		var re = new RegExp(" "+text);
//		var re2 = new RegExp(text+" ");
//		if(robj[i].className == text || (robj[i].className && (robj[i].className.match(re) || robj[i].className.match(re2)))){
		if(ok){
			if(val==(ar_r.length-1))	group_x.push(robj[i]);
			else switched(robj[i],val+1);
		}
		switched(robj[i],val);
		i++;
	}	
}
function findE(obj,val,val2){
	if(val2) var text = ar_r[val].toUpperCase(); 
	else var text = ar_r[val].substr(1).toUpperCase();//>initial
	if(!text) switched(obj,++val);
	var n = /([a-z]+)\[([a-z]+)\=[\'\"]{1}([a-z0-9]+)[\'\"]{1}]/i;
	var m = n.exec(text);
	var n = /([a-z]+)\[([a-z]+)]/i;
	var b = n.exec(text);
	var n = /([a-z]+)\:first-child/i;
	var a = n.exec(text);
	var i=0;
	var k=0;
	var robj = obj.childNodes;
	while(robj[i]){
		if(m){
			if(robj[i].nodeName == m[1] && eval("robj["+i+"]."+m[2].toLowerCase())==m[3].toLowerCase()){
				if(val==(ar_r.length-1))	group_x.push(robj[i]);
				else switched(robj[i],val+1);
			}			
		}else if(b){
			if(robj[i].nodeName == b[1] && eval("robj["+i+"]."+b[2].toLowerCase())){
				if(val==(ar_r.length-1))	group_x.push(robj[i]);
				else switched(robj[i],val+1);
			}
		}else if(a){
			if(robj[i].nodeName == a[1] && k==0){
				if(val==(ar_r.length-1))	group_x.push(robj[i]);
				else switched(robj[i],val+1);				
			}
		}else{
			if(robj[i].nodeName == text){
				if(val==(ar_r.length-1))	group_x.push(robj[i]);
				else switched(robj[i],val+1);
			}
		}
		if(robj[i].nodeType==1) k++;	
		if(val2) switched(robj[i],val);
		i++;
	}	
}
function popup(obj, w, h){
	var pop_win = window.open(obj.href,'pop_win','width='+w+', height='+h+', scrollbars=yes');
	pop_win.focus();
	return false;
}
function pop(url, w, h){
	var pop_win = window.open(url,'pop_win','width='+w+', height='+h+', scrollbars=yes');
	pop_win.focus();
	//return false;
}
function openflash(src,width,height){ 
    var text="<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0\" width="+width+" height="+height+"><param name=movie value="+src+"><param name=quality value=high ><param name=menu value=false><param name=\"wmode\" value=\"opaque\"><embed src="+src+" quality=high  pluginspage=\"http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash\" type=\"application/x-shockwave-flash\" width="+width+" height="+height+"  menu=false wmode=opaque></embed></object>"; 
	document.write(text); 
}
function updateplayer(){
	if(confirm("You need to update your Flash Player. Do you want to update your Flash Player?")){
		location.href = "http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash";
	}
}
//advertiesement
function phpads_deliverActiveX(content){document.write(content);}
var ads_string = '';
function accumulate(banner,client,zone,source,block,capping){
	ads_string += ","+banner+","+client+","+zone+","+source+","+block+","+capping;
}
function adsfileup(banner,zone){
	var xmlHT=GetXmlHttpOBJ();
	var url="/adsnew/countView.php?banner="+banner;
	url += "&zone="+zone;
	url += '&sid='+Math.random();
	xmlHT.open("GET",url,true);
	xmlHT.send(null);	
}
function viewCount(){
	var xmlHT=GetXmlHttpOBJ();
	ads_string = ads_string.substr(1);
	var url="/adsnew/viewCount.php?string="+ads_string;
	url += '&sid='+Math.random();
	xmlHT.open("GET",url,true);
	xmlHT.send(null);
}
//login
function Focusing(obj){
	if(obj.value=="username") obj.value = "";		
}
function Focusing2(obj){
	if(obj.value=="password") obj.value = "";
	obj.type="password";
}
function checkLogin(obj){
	obj.url.value = location.href;
}
//menu
function Menu(val){
	var n = ss("#mainNav ul li");
	if(n[val]) n[val].className = "selected";
}
//preview
var setTimes;
var Robj;
var Dcon;
var restrict;
var incon;
var xmlHT;
var Jobj;
function previewOver(obj){
	clearTimeout(setTimes);
	Robj = obj;
	restrict = 0;
	document.onmousemove = mpos;
	setTimes = setTimeout("shows();",350);
	if(Dcon) Dcon.style.display = "none";
}
function previewOut(){
	clearTimeout(setTimes);
	restrict = 1;
	document.onmousemove = null;
	if(Dcon) Dcon.style.display = "none";
}
function shows(){						
	xmlHT=GetXmlHttpOBJ();
	var href = Robj.href.replace(/http:\/\/christianpost.com/gi,'');
	href = href.replace(/http:\/\/www.christianpost.com/gi,'');
	var  m = new RegExp("previewBlog");
	if(Robj.className.match(m)) var url="/public/blogs/preview.php?url="+href+"&key=";
	else var url="/us/template/getArticle.php?url="+href+"&key=";
	Jobj = Robj;
	xmlHT.onreadystatechange=function(){
		if(xmlHT.readyState==4 || xmlHT.readyState=="complete"){			
			var content = xmlHT.responseText.split("*=*");
			if(content[2]) var contentos = "<img src='"+content[2]+"' />"+content[1];
			else var contentos = content[1];
			if(!restrict && Jobj==Robj && contentos && content[1] != 'undefined'){
				if(!Dcon){
					Dcon = document.createElement("div");
					document.body.appendChild(Dcon);
					incon = document.createElement("div");
					Dcon.appendChild(incon);
					incon.id = "innerArt";
					Dcon.id = "nextArticle";
				}
				Dcon.style.display = "block";
				incon.innerHTML = contentos;
				var sLeft = getscrollLeft();
				var sTop = getscrollTop();
				var Width = Dcon.offsetWidth;
				var Height = Dcon.offsetHeight;
				if((mposx-sLeft+Width+20+13) < getavailWidth())	Dcon.style.left = (mposx+20)+"px";
				else	Dcon.style.left = (sLeft+getavailWidth()-Width-18)+"px";//scrollbar:18		
				if((mposy-sTop+Height+14+18) < getavailHeight())	Dcon.style.top = (mposy+14)+"px";//scrollbar:18
				else if((mposy-Height-14) < sTop)	Dcon.style.top = sTop+"px"; 
				else	Dcon.style.top = (mposy-Height-14)+"px";	
				document.onmousemove = null;				
			}
		}
	}; 
	xmlHT.open("GET",url,true);
	xmlHT.send(null);																				
}
//counter
var aid;
function counter(classify){
	
	var xmlHT=GetXmlHttpOBJ();
	var url="/system/process/counter.php";
	url += "?classify="+classify;
	if(aid) url += "&artid="+aid;
	url += '&sid='+Math.random();
	xmlHT.open("GET",url,true);
	xmlHT.send(null);	
	
}
function checkSearch(f){
	if(!f.q.value) {alert("Please input the Search Keyword");f.q.focus();return false;}
	if(f.engine[0].checked==true){location.href="/search/?term="+f.q.value;return false;} 			
}
var searchTime;
function searchFocus(){
	if(searchTime) clearTimeout(searchTime);
	$("whichone").style.display = "block";
	searchTime = setTimeout(function(){$("whichone").style.display="none";},5000);
}
function closeBknews(){
	$("breakingNews").style.display = "none";	
}
function cancel(){
	$("setEdition").style.display="none";
}
function setpref(){
	if($("setEdition").style.display=="none") $("setEdition").style.display="block";	
	else $("setEdition").style.display="none";	
}
function setSave(){
	if($("edition1").checked==false && $("edition2").checked==false && $("edition3").checked==false) location.reload();
	else if($("edition1").checked==true){ 
		setCookie('edition','us',365);
		location.href = "http://www.christianpost.com/us";
	}else if($("edition2").checked==true){
		setCookie('edition','intl',365);
		location.href = "http://www.christianpost.com/intl";
	}else if($("edition3").checked==true){
		setCookie('edition','ny',365);
		location.href = "http://www.christianpost.com/ny";		
	}
}
//// iframe
var dobj;
var SRC;
	var isdrag=false;
	function movemouse(e){
		if (isdrag){
			if(!e) var e = window.event;
			if((ty + e.clientY - y)<0) var top = 0;
			else var top = ty + e.clientY - y;
			dobj.style.left = (tx + e.clientX - x)+"px";
			dobj.style.top  = top+"px";
			return false;
		}
	}
	function selectmouse(e){
		if(!e) var e = window.event;
		if(e.target) var fobj = e.target;
		else if(e.srcElement) var fobj = e.srcElement;
		isdrag = true;
		dobj = fobj.parentNode;
		
		tx = parseInt(dobj.style.left+0);
		ty = parseInt(dobj.style.top+0);
		x = e.clientX;
		y = e.clientY;
		document.onmousemove=movemouse;
		return false;
	}
	function IFselectmouse(e){
		if(!e) var e = window.event;
		if(e.target) var fobj = e.target;
		else if(e.srcElement) var fobj = e.srcElement;
		isdrag = true;
		$("cover").style.width = "100%";
		$("cover").style.height = "100%";
		$("cover").style.display = "block";
		dobj = $("iFrame");
		
		tx = parseInt(dobj.style.left+0);
		ty = parseInt(dobj.style.top+0);
		x = e.clientX;
		y = e.clientY;
		document.onmousemove=movemouse;
		return false;
	}

function comeout(val,width,height,iposX,iposY,background){
	if(SRC != val){
		if($("Oframe").contentWindow.document) $("Oframe").contentWindow.document.body.innerHTML = "";
		$("Oframe").src = val;
		$("Oframe").style.width = $("TopofFrame").style.width = width+"px";
		$("Oframe").style.height = height+"px";
	
		if(iposX && iposY){
			$("iFrame").style.left = iposX+"px";
			$("iFrame").style.top  = iposY+"px";
		}	
		SRC = val;
	}	
	$("iFrame").style.display = "block";
	if(background) $("cover2").style.display = "block";
}
function stops(e){
	if(!e) var e = event;
	e.cancelBubble = true;
	if (e.stopPropagation) e.stopPropagation();
}	
function closeFrame(){
	$("iFrame").style.display = "none";
	if($("cover")) $("cover").style.display = "none";
	if($("cover2")) $("cover2").style.display = "none";
}

var Class = "";
function Mover(obj){
	Class = obj.className;
	obj.className = "selected";
}
function Mout(obj){
	obj.className = Class;
}
//shop
var shopMenu = 'Jewelry';
var shopNum = 0;
function menuProduct(obj,val){
	var n = ss("#CPshipping .type >li");
	var i = 0;
	while(n[i]){
		if(n[i]==obj) n[i].className += " selected";
		else n[i].className = n[i].className.replace(/ selected/gi,"");
		i++;	
	}
	shopMenu = val;
	shopNum = 0;
	daumProduct(0);
}
function daumProduct(val){
	var n = ss("#productslide .product");
	var m = ss("#CPshipping .category");
	n[0].innerHTML = "";
	$("shop_loading").style.display = "block";
	xmlHT=GetXmlHttpOBJ();
	shopNum = parseInt(shopNum)+val;
	if(shopNum<0) shopNum = 0;
	var url="/us/template/shop_process.php?menu="+shopMenu;
	url += "&idx="+shopNum;
	url += "&shopJs="+shopJS;
	xmlHT.onreadystatechange=function(){
		if(xmlHT.readyState==4 || xmlHT.readyState=="complete"){			
			var content = xmlHT.responseText.split("*=*");
			$("shop_loading").style.display = "none";
			if(n[0]) n[0].innerHTML = content[0];
			if(m[0]) m[0].innerHTML = content[1];
			shopNum = content[2];
		}
	}; 
	xmlHT.open("GET",url,true);
	xmlHT.send(null);		
}
//popular box
var tabTime;
function popular(obj){
	if(tabTime) clearTimeout(tabTime);
	if(obj) tabTime = setTimeout(function(){popularOpen(obj)},300);
}
function popularOpen(obj){
	var n = ss("#popularTop li");
	var m = ss("#popularBox .cont >div");
	var i = 0;
	while(n[i]){
		if(n[i]==obj){ 
			n[i].className = "selected";
			m[i].className = "popularContent";
		}else{
			n[i].className = "";
			m[i].className = "none";
		} 
		i++;
	}	
}
//topic box
function showTopic(){
	$("topicBox").style.display = "block";
}
function topicBoxOver(){
	if(topicTime) clearTimeout(topicTime);
	$("topicBox").style.display = "block";
}
var topicTime;
function topicBoxOut(){
	if(topicTime) clearTimeout(topicTime);
	topicTime = setTimeout("topicHidden();",1000);
}
function topicHidden(){
	$("topicBox").style.display = "none";
}
//slide
function slide(obj,duration,space,limit,automoving){
	this.Zobj = obj;
	this.num = 0;
	this.target;
	this.point; // left=-1 right = 1
	this.space = space;
	this.autos = automoving;;
	this.limit = limit;
	this.distance;
	this.interval = 20000;
	this.duration = duration*1000;
	this.frequency = 50;
	this.freq = parseInt(this.duration/this.frequency);
	this.svs = 1;
	this.move = s_move;
	this.goto = s_goto;
	this.horizontal = s_horizontal;
	this.direct = adonde;
	this.automatic = s_automatic;
	this.start = s_start;
	this.clear = s_clear;
	this.moving = false;
}
function s_move(val){
	this.clear();
	if(val==1){ //right				
		if(this.num>=this.limit){
			this.num=0;
			this.Zobj.style.left = 0;		
		}
	}else{	// left		
		if(this.num<=0){
			this.num=this.limit;
			this.Zobj.style.left = -this.space*this.num+"px";				
		}
	}
	this.target = -1*this.space*(this.num+val);
	this.point = val;
	this.svs = 1;
	this.distance = Math.abs(this.target + this.num*this.space);
	this.moving = true;
	this.horizontal();
	var m = (val==1)?++this.num : --this.num;
	return this.num;
}
function s_goto(val){
	this.clear();
	this.target = -1*this.space*val;
	this.distance = Math.abs(this.target + this.num*this.space);
	this.point = (this.num>val && this.num<this.limit)?-1:1;
	if(this.num==this.limit) this.Zobj.style.left = 0;
	this.svs = 1;
	this.moving = true;
	this.horizontal();
	this.num = val;			
}
function adonde(val){
	this.clear();
	this.Zobj.style.left = -1*this.space*val+"px"; 
	this.num = val;		
}
function s_horizontal(){
	var amount = -this.distance/2/this.freq*Math.PI*Math.sin(Math.PI*this.svs/this.freq)*this.point;
	this.Zobj.style.left = parseInt(this.Zobj.style.left) + amount + "px";	
	var thisObj = this;
	var sss = window.setTimeout(function(){thisObj.horizontal();},this.frequency,this);
	if(this.svs>=(this.freq-1)){
		clearTimeout(sss);
		this.Zobj.style.left = this.target+"px"; 
		this.automatic();
		this.moving = false;
	}
	this.svs++;
}	
function s_automatic(){
	if(this.autos){ 
		var thisObj = this;
		this.autos = window.setTimeout(function(){thisObj.move(1);},this.interval,this);			
	}	
}
function s_clear(){
	if(this.autos) clearTimeout(this.autos);
	this.autos = false;
}
function s_start(){	
	this.Zobj.style.left = 0;
	this.automatic();
}
