picHtml = '';

function changeNavigateHeader(index)
{
	$('cat').innerHTML = headerArr[index];
	$('cat1').innerHTML = news1Arr[index];
	$('cat2').innerHTML = news2Arr[index];
	$('cat3').innerHTML = news3Arr[index];
	$('cat4').innerHTML = news4Arr[index];
	changeNavigateDetail(index);
}

function changeNavigateDetail(index)
{
	var startIndex = index * 4;
	var refIndex = 1;
	if(newsIdArr[category -1][0] != ev_id)
	{
		refIndex = 0;
	}
	//change picture url
	if($('otherTitle1').innerHTML.length == 0)
	{
		if(startIndex + 1 == category)
		{
			$('navpic1').src = '/' + newsPicArr[startIndex][refIndex];
			$('navpic1').title = newsTitleArr[startIndex][refIndex];
			$('navurl1').href = getHTMLPath(startIndex + 1) + newsIdArr[startIndex][refIndex] + '_' + (startIndex + 1) + '_' + getHTMLName(trim(newsTitleArr[startIndex][refIndex])) + '.html';
			$('otherTitle1').innerHTML = newsTitleArr[startIndex][refIndex];
			$('otherDesc1').innerHTML = newsDescArr[startIndex][refIndex];
			$('otherTitle1').href = 'event_detail.php?id=' + newsIdArr[startIndex][refIndex] + '&cat=' + (startIndex + 1);
		}
		else
		{
			$('navpic1').src = '/' + newsPicArr[startIndex][0];
			$('navpic1').title = newsTitleArr[startIndex][0];
			$('navurl1').href = getHTMLPath(startIndex + 1) + newsIdArr[startIndex][refIndex] + '_' + (startIndex + 1) + '_' + getHTMLName(trim(newsTitleArr[startIndex][refIndex])) + '.html';
			$('otherTitle1').innerHTML = newsTitleArr[startIndex][0];
			$('otherDesc1').innerHTML = newsDescArr[startIndex][0];
			$('otherTitle1').href = 'event_detail.php?id=' + newsIdArr[startIndex][0] + '&cat=' + (startIndex + 1);
		}
	}
	
	if($('otherTitle2').innerHTML.length == 0)
	{
		if(startIndex + 2 == category)
		{
			$('navpic2').src = '/' + newsPicArr[startIndex + 1][refIndex];
			$('navpic2').title = newsTitleArr[startIndex + 1][refIndex];
			$('navurl2').href = getHTMLPath(startIndex + 2) + newsIdArr[startIndex + 1][refIndex] + '_' + (startIndex + 2) + '_' + getHTMLName(trim(newsTitleArr[startIndex + 1][refIndex])) + '.html';
			$('otherDesc2').innerHTML = newsDescArr[startIndex + 1][0];
			$('otherTitle2').innerHTML = newsTitleArr[startIndex + 1][refIndex];
			$('otherTitle2').href = 'event_detail.php?id=' + newsIdArr[startIndex + 1][refIndex] + '&cat=' + (startIndex + 2);
		}
		else
		{
			$('navpic2').src = '/' + newsPicArr[startIndex + 1][0];
			$('navpic2').title = newsTitleArr[startIndex + 1][0];
			$('navurl2').href = getHTMLPath(startIndex + 2) + newsIdArr[startIndex + 1][refIndex] + '_' + (startIndex + 2) + '_' + getHTMLName(trim(newsTitleArr[startIndex + 1][refIndex])) + '.html';
			$('otherTitle2').innerHTML = newsTitleArr[startIndex + 1][0];
			$('otherDesc2').innerHTML = newsDescArr[startIndex + 1][0];
			$('otherTitle2').href = 'event_detail.php?id=' + newsIdArr[startIndex + 1][0] + '&cat=' + (startIndex + 2);
		}
	}
		
	if($('otherTitle3').innerHTML.length == 0)
	{
		if(startIndex + 3 == category)
		{
			$('navpic3').src = '/' + newsPicArr[startIndex + 2][refIndex];
			$('navpic3').title = newsTitleArr[startIndex + 2][refIndex];
			$('navurl3').href = getHTMLPath(startIndex + 3) + newsIdArr[startIndex + 2][refIndex] + '_' + (startIndex + 3) + '_' + getHTMLName(trim(newsTitleArr[startIndex + 2][refIndex])) + '.html';
			$('otherTitle3').innerHTML = newsTitleArr[startIndex + 2][refIndex];
			$('otherDesc3').innerHTML = newsDescArr[startIndex + 2][refIndex];
			$('otherTitle3').href = 'event_detail.php?id=' + newsIdArr[startIndex + 2][refIndex] + '&cat=' + (startIndex + 3);
		}
		else
		{
			$('navpic3').src = '/' + newsPicArr[startIndex + 2][0];
			$('navpic3').title = newsTitleArr[startIndex + 2][0];
			$('navurl3').href = getHTMLPath(startIndex + 3) + newsIdArr[startIndex + 2][refIndex] + '_' + (startIndex + 3) + '_' + getHTMLName(trim(newsTitleArr[startIndex + 2][refIndex])) + '.html';
			$('otherTitle3').innerHTML = newsTitleArr[startIndex + 2][0];
			$('otherDesc3').innerHTML = newsDescArr[startIndex + 2][0];	
			$('otherTitle3').href = 'event_detail.php?id=' + newsIdArr[startIndex + 2][0] + '&cat=' + (startIndex + 3);
		}
	}
	
	if($('otherTitle4').innerHTML.length == 0)
	{
		if(startIndex + 4 == category)
		{
			$('navpic4').src = '/' + newsPicArr[startIndex + 3][refIndex];
			$('navpic4').title = newsTitleArr[startIndex + 3][refIndex];
			$('navurl4').href = getHTMLPath(startIndex + 4) + newsIdArr[startIndex + 3][refIndex] + '_' + (startIndex + 4) + '_' + getHTMLName(trim(newsTitleArr[startIndex + 3][refIndex])) + '.html';
			$('otherTitle4').innerHTML = newsTitleArr[startIndex + 3][refIndex];
			$('otherDesc4').innerHTML = newsDescArr[startIndex + 3][refIndex];	
			$('otherTitle4').href = 'event_detail.php?id=' + newsIdArr[startIndex + 3][refIndex] + '&cat=' + (startIndex + 4);
		}
		else	
		{
			$('navpic4').src = '/' + newsPicArr[startIndex + 3][0];
			$('navpic4').title = newsTitleArr[startIndex + 3][0];
			$('navurl4').href = getHTMLPath(startIndex + 4) + newsIdArr[startIndex + 3][refIndex] + '_' + (startIndex + 4) + '_' + getHTMLName(trim(newsTitleArr[startIndex + 3][refIndex])) + '.html';
			$('otherTitle4').innerHTML = newsTitleArr[startIndex + 3][0];
			$('otherDesc4').innerHTML = newsDescArr[startIndex + 3][0];	
			$('otherTitle4').href = 'event_detail.php?id=' + newsIdArr[startIndex + 3][0] + '&cat=' + (startIndex + 4);
		}
	}
}


function showClips()
{
	if(picHtml.length == 0)
		picHtml = $('picAndClip').innerHTML;
	var clipHtml = fixEmbeddedVideo('<object width="100%" height="100%"> <param name="wmode" value="transparent" /> <param name="movie" value="http://www.youtube.com/v/' + embeded + '&hl=en&fs=1&autoplay=1&loop=1"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/' + embeded + '&hl=en&fs=1&autoplay=1&loop=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="100%" height="100%"></embed></object>');
	$('picAndClip').innerHTML = clipHtml;
	$('clipsShow').className = 'txt_event_bigblue2';
	$('photosShow').className = 'txt_event_navgrey3';
	//$('picClipHeader').innerHTML = '<h3><a href="javascript:void(0)" onclick="shoPic()" class="txt_event_navgrey3">PHOTOS</a>  |  <span class="txt_event_bigblue2">VIDEO</span></h3>';
	$('picShow').style.visibility = 'hidden';
	$('picShow').style.height = '0px';
	$('picShow').style.paddingTop = '0px';
	$('picShow').style.paddingBottom = '0px';
}



var fixEmbeddedVideo = function(embedCode) {
	if(embedCode && embedCode.toLowerCase().indexOf('classid') == -1) {
		var objPos = embedCode.toLowerCase().indexOf('object ') + 'object '.length;
		return embedCode.substr(0, objPos) + 'classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" ' + embedCode.substr(objPos);
	} else {
		return embedCode;
	}
}

function showPic()
{
	if(picHtml.length > 0)
		$('picAndClip').innerHTML = picHtml
	//$('picClipHeader').innerHTML = '<h3><span class="txt_event_bigblue2">PHOTOS</span>  |  <a href="javascript:void(0)" onclick="shoClips()" class="txt_event_navgrey3">VIDEO</a></h3>';
	$('clipsShow').className = 'txt_event_navgrey3';
	$('photosShow').className = 'txt_event_bigblue2';
	$('picShow').style.height = '82px';
	$('picShow').style.paddingTop = '7px';
	$('picShow').style.paddingBottom = '7px';
	$('picShow').style.visibility = 'visible';
}

function setAttachImage()
{
	for(var i = 1 ; i <= imgThumb.length ; i++)
	{
		if(i>3) 
			break;
		$('p'+ i).innerHTML = '<img src="/' + imgThumb[i-1] + '" width="100%" style="cursor:pointer" height="100%" onclick="$(\'mainImg\').src = \'/' + imgLogo[i-1] + '\'" />';
	}
}

function changeLink(index)
{
	$('link1').href = 'allnews.php?ch=' + (index+1) + '&i=1';
	$('link2').href = 'allnews.php?ch=' + (index+1) + '&i=2';
	$('link3').href = 'allnews.php?ch=' + (index+1) + '&i=3';
	$('link4').href = 'allnews.php?ch=' + (index+1) + '&i=4';
}

function toComment()
{
	if(isUser)
	{
		scrollToComment();
	}
	else
	{
		alert('Login ,to use this function');	
	}
}

function scrollToComment()
{
	Effect.ScrollTo('commentBoxIndex' , { duration: 1.0 });
}

function expandCommentBox()
{
	Effect.SlideDown('commentBox'); 
	return false;
}

function cancleComm()
{
	Effect.SlideUp('commentBox' , { duration: 1.0 });
	setTimeout("scrollToReview()",1000);		
}

function scrollToReview()
{
	Effect.ScrollTo('reviewBox' , { duration: 1.0 ,offset :-100});
	reloadIframeMsg();
	return false;
}

function submitComm()
{
	$('msgForm').submit();
	Effect.SlideUp('commentBox');
	$('commentMsg').value = '';
	setTimeout("scrollToReview();reloadIframeMsg();",1000);
	reloadIframeMsg();
}

function reloadIframeMsg()
{
	var location = getMsgFrame.location.toString();
	getMsgFrame.location.replace(location);
}

function onmouseOver(index)
{
	if(index==1)
	{
		$('btn1').src = '/images/event_btn_rollover04.gif';
	}
	else if(index==2)
	{
		$('btn2').src = '/images/event_btn_rollover01.gif';
	}
	else if(index==3)
	{
		$('btn3').src = '/images/event_btn_rollover02.gif';
	}
	else if(index==4)
	{
		$('btn4').src = '/images/event_btn_rollover03.gif';
	}
	else if(index==5)
	{
		$('submitComment').src = '/images/btn_submit2.gif';
	}
	else if(index==6)
	{
		$('cancleComment').src = '/images/btn_cancel_rollover.gif';
	}
	else if(index==7)
	{
		$('btn5').src = '/images/btn_viewmap_rollover.gif';	
	}
	else if(index==8)
	{
		$('btn6').src = '/images/btn/btn_myka2.gif';	
	}
	else if(index==9)
	{
		$('btn7').src = '/images/btn/btn_remove2.gif';	
	}
	else if(index==10)
	{
		$('postMsg').src = '/images/btn/btn_send2.gif';	
	}
	else if(index==11)
	{
		$('ticketBtn').src = '/images/btn/btn_ticket2.gif';	
	}
	else if(index==12)
	{
		$('fevBtn').src = '/images/btn/btn_favor2.gif';	
	}
	else if(index==13)
	{
		$('btn8').src = '/images/btn/btn_deal2.gif';	
	}
	else if(index==14)
	{
		$('btn9').src = '/images/btn/btn_transport2.gif';	
	}
	else if(index==15)
	{
		$('btnAddLink').src = '/images/btn/btnpop_add2.gif';	
	}
	else if(index==16)
	{
		$('btnCancleLink').src = '/images/btn/btnpop_cancel2.gif';	
	}
	else if(index==17)
	{
		$('btnAddTag').src = '/images/btn/btnpop_add2.gif';	
	}
	else if(index==18)
	{
		$('btnCancleTag').src = '/images/btn/btnpop_cancel2.gif';	
	}
}

function onmouseOut(index)
{
	if(index==1)
	{
		$('btn1').src = '/images/event_btn_active04.gif';
	}
	else if(index==2)
	{
		$('btn2').src = '/images/event_btn_active01.gif';
	}
	
	else if(index==3)
	{
		$('btn3').src = '/images/event_btn_active02.gif';
	}
	
	else if(index==4)
	{
		$('btn4').src = '/images/event_btn_active03.gif';
	}
	else if(index==5)
	{
		$('submitComment').src = '/images/btn_submit1.gif';
	}else if(index==6)
	{
		$('cancleComment').src = '/images/btn_cancel.gif';
	}
	else if(index==7)
	{
		$('btn5').src = '/images/btn_viewmap.gif';	
	}
	else if(index==8)
	{
		$('btn6').src = '/images/btn/btn_myka1.gif';	
	}
	else if(index==9)
	{
		$('btn7').src = '/images/btn/btn_remove1.gif';	
	}
	else if(index==10)
	{
		$('postMsg').src = '/images/btn/btn_send1.gif';	
	}
	else if(index==11)
	{
		$('ticketBtn').src = '/images/btn/btn_ticket1.gif';	
	}
	else if(index==12)
	{
		$('fevBtn').src = '/images/btn/btn_favor1.gif';	
	}else if(index==13)
	{
		$('btn8').src = '/images/btn/btn_deal1.gif';	
	}
	else if(index==14)
	{
		$('btn9').src = '/images/btn/btn_transport1.gif';	
	}
	else if(index==15)
	{
		$('btnAddLink').src = '/images/btn/btnpop_add.gif';	
	}
	else if(index==16)
	{
		$('btnCancleLink').src = '/images/btn/btnpop_cancel.gif';	
	}
	else if(index==17)
	{
		$('btnAddTag').src = '/images/btn/btnpop_add.gif';	
	}
	else if(index==18)
	{
		$('btnCancleTag').src = '/images/btn/btnpop_cancel.gif';	
	}
}

function addEvent()
{
	var url = '/mykalenda/addMyKalenda.php?id=' + ev_id + '&cat=' + category;
	//window.open(url);
	addRemoveFrame.location.replace(url);
}

function removeEvent()
{
	var url = '/mykalenda/removeMyKalenda.php?id=' + ev_id + '&cat=' + category;
	addRemoveFrame.location.replace(url);	
}

function refreshMessage()
{
	var location = getMsgFrame.location.toString();
	getMsgFrame.location.replace(location);
}

function createMessage()
{
	if(messageArr.length == 0)
	{
		var noMessage = '<div class="commentboxx_no">'
						+'<p>&nbsp;</p>'
						+'<p>&nbsp;</p>'
						+'<p>&nbsp;</p>'
						+'<p>&nbsp;</p>'
						+'<p>No comment</p>'
					  	+'</div>';
		$('reviewBox').innerHTML = noMessage;	
	}
	else
	{
		var msgHtml = '';
		var nameIndex = 0;
		var msgIndex = 1;
		var dateIndex = 2;
		var imageIndex = 3;
		
		for(var i = 0 ; i < messageArr.length; i++)
		{
			msgHtml += '<div class="commentboxx">';
			if(messageArr[i][imageIndex].length > 2 )
			{
				msgHtml += 	'<img src="' + messageArr[i][imageIndex] + '" width="200"  hspace="10" vspace="5" align="left" />';
			}
			msgHtml += messageArr[i][msgIndex] + '</div>'
          			+'<div class="commentby_wrap">'
            		+'<div class="commentby"><span class="txt_event_normalblue">Posted by ' + messageArr[i][nameIndex] + '</span> '
					+ messageArr[i][dateIndex] + '</div><div class="commentby2">'
					+'<a href="#" class="txt_event_moreblue">Report</a></div></div>'
					+'<div class="commentline"></div>';
		}
		$('reviewBox').innerHTML = msgHtml;	
		
	}
	hideCommLoad();
	$('commentMsg').disabled = '';
	$('commentPic').disabled = '';
	$('commentForm').reset();
}

function hideCommLoad()
{
	$('postLoad').style.visibility = 'hidden';
}

function showCommLoad()
{
	$('postLoad').style.visibility = 'visible';
}

function postComment()
{
	if(isUser)
	{
		showCommLoad();
		$('commentForm').submit();
		$('commentMsg').disabled = 'disabled';
		$('commentPic').disabled = 'disabled';
	}
	else
	{
		alert('Login ,to use this function');	
	}
}

function toLogin()
{
	var login = confirm("Please login to comment");
	if(login)
	{
		parent.document.location = '/signin.php?r=' + escape(window.location);
	}
}

function share(type,uri , desc)
{
	var uri= encodeURIComponent(uri);
	//var uri = encodeURIComponent(uri);
	var desc = encodeURIComponent(desc);
	if(type =='digg')
		window.open('http://digg.com/submit?phase=2&url=' + uri +'&title=' + desc);
	else if(type == 'twitter')
		window.open('http://twitter.com/home?status=' + uri);
	else if(type == 'stumbleupon')
		window.open('http://www.stumbleupon.com/submit?url=' + uri);
	else if(type == 'icio')
		window.open('http://del.icio.us/post?url=' + uri +'&title=' + desc);
	else if(type == 'facebook')
		window.open('http://www.facebook.com/share.php?u=' + uri );
	else if(type == 'myspace')
		window.open('http://www.myspace.com/Modules/PostTo/Pages/?l=3&u=' + uri);
	else if(type == 'google')
		window.open('http://www.google.com/bookmarks/mark?op=edit&bkmk=' + uri);
	else if(type == 'technorati')
		window.open('http://technorati.com/cosmos/search.html?url=' + uri);
	
}

var travelRouteIndex = 1;

function setTravelRouteIndex(index)
{
	Effect.ScrollTo('travelrouteScroll' , { duration: 0.8 });
	travelRouteIndex = index;
	
	if(index < Math.ceil(travelCount/4))
	{
		$('next').style.display = '';	
		$('nextE').style.display = '';
	}else
	{
		$('next').style.display = 'none';	
		$('nextE').style.display = 'none';	
	}
	
	if(index > 1)
	{
		$('back').style.display = '';	
		$('backE').style.display = '';
	}else
	{
		$('back').style.display = 'none';	
		$('backE').style.display = 'none';	
	}
	
	for(var i = 1;i <= Math.ceil(travelCount/4) ;i++)
	{
		var divId = 'travelrouteIndex' + i;	
		var travelRouteId = 'travelrouteDiv' + i;
		if(i != index)
		{
			$(divId.toString()).className = 'txt_event_normalblue2';
			$(travelRouteId.toString()).style.display = 'none';
		}
		else
		{
			$(divId.toString()).className = 'txt_event_greybold';
			$(travelRouteId.toString()).style.display = '';
		}
	}
}

function nextTravelRoute()
{
	setTravelRouteIndex(travelRouteIndex + 1);
}

function backTravelRoute()
{
	setTravelRouteIndex(travelRouteIndex - 1);
}

function showAllTravelRoute()
{
	$('showall').style.visibility = 'hidden';
	$('showallIndex').style.visibility = 'hidden';
	for(var i = 1;i <= Math.ceil(travelCount/4) ;i++)
	{
		var travelRouteId = 'travelrouteDiv' + i;
		$(travelRouteId.toString()).style.display = '';
	}
}

function showAddLink(obj)
{
	try{
		$('linkError').innerHTML = '';
	}catch(err){}
	if(isUser)
	{
		if($('addLink').style.display == 'none')
		{	
			$('addLink').style.top = (obj.offsetTop+20)+'px';
			Effect.BlindDown('addLink',{duration:0.3});			
			$('addLinkStatus').innerHTML = '-';			
			return false;
		}else
		{
			Effect.BlindUp('addLink',{duration:0.3});
			$('addLinkStatus').innerHTML = '+';
			return false;
		}
	}else
	{
		var login = confirm("Please login to add link.");
		if(login)
		{
			parent.document.location = '/signin.php?r=' + escape(window.location);
		}
	}
}

function showAddTag(obj)
{
	try{
		$('tagError').innerHTML = '';
	}catch(err){}
	if(isUser)
	{
		if($('addTag').style.display == 'none')
		{
			$('addTag').style.top = (obj.offsetTop+20)+'px';
			Effect.BlindDown('addTag',{duration:0.3}); 
			$('addTagStatus').innerHTML = '-';
			return false;	
		}else
		{
			Effect.BlindUp('addTag',{duration:0.3});
			$('addTagStatus').innerHTML = '+';
			return false;
		}
	}else
	{
		var login = confirm("Please login to add tag.");
		if(login)
		{
			parent.document.location = '/signin.php?r=' + escape(window.location);
		}
	}
}

function hideAddLink()
{
	$('link').value = '';
	Effect.BlindUp('addLink',{duration:0.3});
	$('addLinkStatus').innerHTML = '+';
	return false;
}

function hideAddTag()
{
	$('tag').value = '';
	Effect.BlindUp('addTag',{duration:0.3});
	$('addTagStatus').innerHTML = '+';
	return false;
}

function displayCountDown()
{
	remainSec -= 1;
	//alert(remainSec);
	if(remainSec <= 0)
	{
		$('cdDay').innerHTML = '- -';
		$('cdHour').innerHTML = '- -';
		$('cdMin').innerHTML = '- -';
		$('cdSec').innerHTML = '- -';
		clearInterval(timeInterval);
		//$('countdownDiv').style.display = 'none';		
	}else
	{
		var tempInterval = remainSec;
		var day = Math.floor(tempInterval/86400);
		tempInterval = tempInterval - day*86400;
		var hour = Math.floor(tempInterval/3600);
		tempInterval = tempInterval - hour*3600;
		var minute = Math.floor(tempInterval/60);
		tempInterval = tempInterval - minute*60;
		var sec = tempInterval;
		
		if(day < 10)
			day = '0' + day;
		if(hour < 10)
			hour = '0' + hour;
		if(minute < 10)
			minute = '0' + minute;
		if(sec < 10)
			sec = '0' + sec;
		
		$('cdDay').innerHTML = day;
		$('cdHour').innerHTML = hour;
		$('cdMin').innerHTML = minute;
		$('cdSec').innerHTML = sec;
	}
}
