var ie=navigator.appName=="Microsoft Internet Explorer";
var nn=navigator.appName=="Netscape";
var font_family="Arial, Helvetica, sans-serif";
var font_size=11;

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function RemovePx(thetext){
	re=/px/;
	return Number(thetext.replace(re,""));
}

function PopupWin(bookURL){
	var winTop = (screen.height /2) - 90;
	var winLeft = (screen.width /2) - 150;
	var winFeat = "menubar=no,status=yes,toolbar=no,scrollable=yes,height=150,width=340";
	winFeat = winFeat+",top="+winTop+",left="+winLeft;
	var newWin = window.open(bookURL,'popup'+Math.round(Math.random()*99),winFeat);
}

function PopupWin2(bookURL,w,h){
	var winLeft = (screen.width /2) - (w/2);
	var winTop = (screen.height /2) - (h/2);
	var winFeat = "menubar=no,status=yes,toolbar=no,resizable=yes,scrollbars=yes,height="+h+",width="+w;
	winFeat = winFeat+",top="+winTop+",left="+winLeft;
	var newWin = window.open(bookURL,'popup'+Math.round(Math.random()*99),winFeat);
}

function ToThumb(image){
	dot=image.lastIndexOf(".");
	if(dot!=-1){
		filename=image.substr(0,dot);
		format=image.substr(dot+1,image.length-dot);
		return filename+"_thumb."+format;
	}else{
		return image;
	}
}

function ToSuperMini(image){
	dot=image.lastIndexOf(".");
	if(dot!=-1){
		filename=image.substr(0,dot);
		format=image.substr(dot+1,image.length-dot);
		return filename+"_smini."+format;
	}else{
		return image;
	}
}


function ShowHide(target){
	var idtarget=document.getElementById(target);
	if(idtarget.style.display=="none"){
		idtarget.style.display="";
		//document.getElementById("notification_dropdown").style.display="none";
	}else{
		idtarget.style.display="none";
	}
}

function ShowHide2(target){
	var idtarget=document.getElementById(target);
	if(idtarget.style.display=="none"){
		idtarget.style.display="";
		document.getElementById("inbox_dropdown").style.display="none";
		clearTimeout(notif_fading_obj);
		clearTimeout(notif_timer_obj);
	}else{
		idtarget.style.display="none";		
		RefreshNotif();
	}
}

function FontMin(target_id){
	target=document.getElementById(target_id);
	if(target!=null){
		if(font_size>12){
			font_size-=2;
			//target.style.fontSize=font_size+"px";
			targetchildren=target.getElementsByTagName("*");
			for (i=0; i<targetchildren.length; i++){
				targetchildren[i].style.fontFamily=font_family;
				targetchildren[i].style.fontSize=font_size+"px";
			}
		}
	}
}

function FontPlus(target_id){
	target=document.getElementById(target_id);
	if(target!=null){
		if(font_size<23){
			font_size+=2;
			//target.style.fontSize=font_size+"px";
			targetchildren=target.getElementsByTagName("*");
			for (i=0; i<targetchildren.length; i++){
				targetchildren[i].style.fontFamily=font_family;
				targetchildren[i].style.fontSize=font_size+"px";
			}
		}
	}
}

function ShowContent(the_url){
	ajaxpage(the_url,'content');
}

function ShowImageUploading(){
	document.getElementById("input_process").style.display="none";
	document.getElementById("loading_process").style.display="";
}

function ShowMessageLoading(){
	location.href="#";
	target=document.getElementById("popup_message");
	target.style.display="";
	target.style.height=document.body.parentNode.clientHeight+"px";
	document.getElementById("popup_message_content").innerHTML="<div align='center' style='padding-top:40px; height:40px;'><img src='images/loading.gif'></div>";
}

function ShowWindowLoading(){
	location.href="#";
	target=document.getElementById("popup_window");
	target.style.display="";
	target.style.height=document.body.parentNode.clientHeight+"px";
	document.getElementById("popup_window_content").innerHTML="<div align='center' style='padding-top:120px; height:120px;'><img src='images/loading.gif'></div>";
}

function MessageLoad(the_url){
	ShowMessageLoading();
	ajaxpage(the_url,"popup_message_content");
}

function WindowLoad(the_url){
	ShowWindowLoading();
	ajaxpage(the_url,"popup_window_content");
}

function WindowLoadAndDoFunction(the_url,the_function){
	ShowWindowLoading();
	ajaxpageanddofunction(the_url, "popup_window_content", the_function);
}

function ClosePopupWindow(){
	if(typeof CKEDITOR!="undefined"){
		if(CKEDITOR.instances.myckeditor){
			CKEDITOR.instances.myckeditor.destroy();
		}
	}
	target=document.getElementById("popup_window");
	target.style.display="none";
}

function ClosePopupMessage(){
	target=document.getElementById("popup_message");
	target.style.display="none";
}

function FocusKeyword(){
	Field=document.getElementById("keyword");
	Field.style.color="#404040";
	if(Field.value=="keyword"){
		Field.value="";	
	}
}

function BlurKeyword(){
	Field=document.getElementById("keyword");
	Field.style.color="#999999";
	if(Field.value==""){
		Field.value="keyword";	
	}
}

function SearchCategory(the_category){
	document.getElementById("search_category").value=the_category;
	ShowHide("category_dropdown");
}

var a=0;
var div_opacity=0;
function AnnouncementTimerFunction(){
	a++;
	if(a>a_max)a=1;
	if(a<=0)a=a_max-a;
	for(b=1;b<=a_max;b++){
		document.getElementById("lines"+b).style.display="none";	
	}
	document.getElementById("lines"+a).style.display="block";
	AnnouncementFadeIn();
	announcement_timer_obj=setTimeout("AnnouncementTimerFunction()",10000);
}
function AnnouncementFadeIn(){
	div_opacity+=5;
	if(ie){
		if(document.getElementById("announcement"))document.getElementById("announcement").filters.alpha.opacity=div_opacity;
	}else{
		if(document.getElementById("announcement"))document.getElementById("announcement").style.MozOpacity=div_opacity/100;		
	}
	if(div_opacity>=100){
		div_opacity=0;
		clearTimeout(announcement_fading_obj);
	}else{
		announcement_fading_obj=setTimeout("AnnouncementFadeIn()",100);		
	}
}
function NextAnnouncement(){
	div_opacity=0;
	clearTimeout(announcement_fading_obj);
	clearTimeout(announcement_timer_obj);
	AnnouncementTimerFunction();
}
function PrevAnnouncement(){
	a-=2;
	div_opacity=0;
	clearTimeout(announcement_fading_obj);
	clearTimeout(announcement_timer_obj);
	AnnouncementTimerFunction();
}
function InitAnnouncement(){
	AnnouncementTimerFunction();
}

var c=0;
var div_teaser_opacity=0;
function TeaserTimerFunction(){
	c++;
	if(c>c_max)c=1;
	if(c<=0)c=c_max-c;
	for(d=1;d<=c_max;d++){
		document.getElementById("teaser_lines"+d).style.display="none";	
	}
	document.getElementById("teaser_lines"+c).style.display="block";
	TeaserFadeIn();
	teaser_timer_obj=setTimeout("TeaserTimerFunction()",10000);
}
function TeaserFadeIn(){
	div_teaser_opacity+=5;
	if(ie){
		if(document.getElementById("teaser"))document.getElementById("teaser").filters.alpha.opacity=div_teaser_opacity;
	}else{
		if(document.getElementById("teaser"))document.getElementById("teaser").style.MozOpacity=div_teaser_opacity/100;		
	}
	if(div_teaser_opacity>=100){
		div_teaser_opacity=0;
		clearTimeout(teaser_fading_obj);
	}else{
		teaser_fading_obj=setTimeout("TeaserFadeIn()",100);		
	}
}
function NextTeaser(){
	div_teaser_opacity=0;
	clearTimeout(teaser_fading_obj);
	clearTimeout(teaser_timer_obj);
	TeaserTimerFunction();
}
function PrevTeaser(){
	c-=2;
	div_teaser_opacity=0;
	clearTimeout(teaser_fading_obj);
	clearTimeout(teaser_timer_obj);
	TeaserTimerFunction();
}
function InitTeaser(){
	TeaserTimerFunction();
}
function InviteFriend(){
	WindowLoad("member_invite_friends_ajax.php");
}
function CheckEmail(theelement){
	Field=document.getElementById(theelement)
	if((Field.value.indexOf("@")==-1)||(Field.value.indexOf(".")==-1)){
		alert("Email not valid");
		Field.focus();
		return false;
	}else{
		pos1=Field.value.lastIndexOf("@");
		pos2=Field.value.lastIndexOf(".");
		if(
			(Field.value.charAt(pos1-1)=="")||
			(Field.value.charAt(pos1+1)==".")||
			(Field.value.charAt(pos2-1)=="")||
			(Field.value.charAt(pos2+1)=="")||
			(pos1>pos2)
		){
			alert("Email not valid");
			Field.focus();
			return false;
		}
	}
	return true;
}
function CheckBlank(theelement,themessage){
	Field=document.getElementById(theelement);
	if(Field.value==""){
		alert(themessage);
		Field.focus();
		return false;
	}else{
		return true;
	}
}
function CheckInviteForm(){		
	Field1 = document.getElementById("email_address_1");
	Field2 = document.getElementById("email_address_2");
	Field3 = document.getElementById("email_address_3");
	Field4 = document.getElementById("email_address_4");
	Field5 = document.getElementById("email_address_5");
	Field6 = document.getElementById("email_address_6");
	Field7 = document.getElementById("email_address_7");
	Field8 = document.getElementById("email_address_8");
	Field9 = document.getElementById("email_address_9");
	Field10 = document.getElementById("email_address_10");
	if(Field1.value==""&&Field2.value==""&&Field3.value==""&&Field4.value==""&&Field5.value==""&&Field6.value==""&&Field7.value==""&&Field8.value==""&&Field9.value==""&&Field10.value==""){
		alert("Please fill at least one email address");
		Field1.focus();
		return false;
	}
	if(!CheckEmail("email_address_1"))return false;
	if(Field2.value!="")if(!CheckEmail("email_address_2"))return false;
	if(Field3.value!="")if(!CheckEmail("email_address_3"))return false;
	if(Field4.value!="")if(!CheckEmail("email_address_4"))return false;
	if(Field5.value!="")if(!CheckEmail("email_address_5"))return false;
	if(Field6.value!="")if(!CheckEmail("email_address_6"))return false;
	if(Field7.value!="")if(!CheckEmail("email_address_7"))return false;
	if(Field8.value!="")if(!CheckEmail("email_address_8"))return false;
	if(Field9.value!="")if(!CheckEmail("email_address_9"))return false;
	if(Field10.value!="")if(!CheckEmail("email_address_10"))return false;
	
	Field = document.getElementById("sender_name");
	if(Field!=null){
		if( !CheckBlank("sender_name","Please fill your name") )return false;
	}
	return true;	
}

var comment_header_opacity=0;
var comment_opacity=0;
var comment_status="active";//active,focusing,focused,sending,retrieving,animating
var comment_id="";

function FocusComment(){
	if(comment_status=="active"){
		ShowHide("comment_give_comment");
		ShowHide("comment_give_comment_teaser");
		comment_id="txaCommentComment";
		target=document.getElementById(comment_id);
		target.focus();
		CommentHeaderFadeIn();
	}
}
function BlurComment(){
	if(comment_status=="focused"){
				
			ShowHide("comment_give_comment");
			ShowHide("comment_give_comment_teaser");
			comment_id="";
			CommentHeaderFadeOut();
		
	}
}
function SubmitComment(){
	comment_status="sending";
}
function DisableComment(){
	document.getElementById("txaCommentComment").readOnly=true;
	document.getElementById("btnCommentSubmit").readOnly=true;
	document.getElementById("txaCommentComment").style.backgroundColor="#d0d0d0";
	target=document.getElementById("txtCommentName");
	if(target!=null){
		target.readOnly=true;
		target.style.backgroundColor="#d0d0d0";
	}
	target=document.getElementById("txtCommentSSC");
	if(target!=null){
		target.readOnly=true;
		target.style.backgroundColor="#d0d0d0";
	}
}
function EnableComment(){
	document.getElementById("txaCommentComment").readOnly=false;
	document.getElementById("btnCommentSubmit").readOnly=false;
	document.getElementById("txaCommentComment").style.backgroundColor="#ffffff";
	target=document.getElementById("txtCommentName");
	if(target!=null){
		target.readOnly=false;
		target.style.backgroundColor="#ffffff";
	}
	target=document.getElementById("txtCommentSSC");
	if(target!=null){
		target.readOnly=false;
		target.style.backgroundColor="#ffffff";
	}
}
function CommentHeaderFadeIn(){
	comment_status="focusing";
	comment_header_opacity+=10;
	if(document.getElementById("comment_give_comment")){
		if((document.getElementById("comment_give_comment").style.MozOpacity!=null)||(document.getElementById("comment_give_comment").style.MozOpacity!="undefined")){
			document.getElementById("comment_give_comment").style.MozOpacity=comment_header_opacity/100;
		}else{
			document.getElementById("comment_give_comment").filters.alpha.opacity=comment_header_opacity;
		}
	}
	if(comment_header_opacity>=100){
		comment_header_opacity=0;
		comment_status="focused";
		clearTimeout(comment_header_timer_obj);
	}else{
		comment_header_timer_obj=setTimeout("CommentHeaderFadeIn()",30);		
	}
}
function CommentHeaderFadeOut(){
	comment_status="focusing";
	comment_header_opacity+=10;
	if(document.getElementById("comment_give_comment_teaser")){
		if((document.getElementById("comment_give_comment_teaser").style.MozOpacity!=null)||(document.getElementById("comment_give_comment_teaser").style.MozOpacity!="undefined")){
			document.getElementById("comment_give_comment_teaser").style.MozOpacity=comment_header_opacity/100;
		}else{
			document.getElementById("comment_give_comment_teaser").filters.alpha.opacity=comment_header_opacity;
		}
	}
	if(comment_header_opacity>=100){
		comment_header_opacity=0;
		comment_status="active";
		clearTimeout(comment_header_timer_obj);
	}else{
		comment_header_timer_obj=setTimeout("CommentHeaderFadeOut()",30);		
	}
}
function CommentFadeIn(){
	comment_status="animating";
	comment_opacity+=10;
	if(document.getElementById("comment_listing_wrapper_2")){
		if((document.getElementById("comment_listing_wrapper_2").style.MozOpacity!=null)||(document.getElementById("comment_listing_wrapper_2").style.MozOpacity!="undefined")){
			document.getElementById("comment_listing_wrapper_2").style.MozOpacity=comment_opacity/100;
		}else{
			document.getElementById("comment_listing_wrapper_2").filters.alpha.opacity=comment_opacity;
		}
		document.getElementById("comment_listing_wrapper_3").style.marginTop=(-64+Math.ceil(comment_opacity/100*64))+"px";
	}
	if(comment_opacity>=100){
		comment_opacity=0;
		comment_status="active";
		clearTimeout(comment_timer_obj);
		EnableComment();//this is localized for each section
	}else{
		comment_timer_obj=setTimeout("CommentFadeIn()",30);		
	}
}

var menu_array=Array("dd_news","dd_review","dd_gadget","dd_store");
function HideAllMenu(){
	for(x=0;x<=3;x++){
		target=menu_array[x];
		var idtarget=document.getElementById(target);
		idtarget.style.display="none";
	}
}
function ShowMenu(the_index){
	HideAllMenu();
	target=menu_array[the_index];
	var idtarget=document.getElementById(target);
	idtarget.style.display="";
}
function HideMenu(the_index){
	target=menu_array[the_index];
	var idtarget=document.getElementById(target);
	idtarget.style.display="none";
}
function ActivateCKEditor(){
	CKEDITOR.replace( 'myckeditor' );	
}

function InboxTimerFunction(){
	RefreshInboxIndicator2();	
	InboxFadeIn();
	inbox_timer_obj=setTimeout("InboxTimerFunction()",10000);

}
function InboxFadeIn(){
	div_opacity+=5;
	if(ie){
		if(document.getElementById("inbox_indicator3"))document.getElementById("inbox_indicator3").filters.alpha.opacity=div_opacity;
	}else{
		if(document.getElementById("inbox_indicator3"))document.getElementById("inbox_indicator3").style.MozOpacity=div_opacity;
	}
	if(div_opacity>=100){
		div_opacity=0;
		clearTimeout(inbox_fading_obj);
	}else{
		inbox_fading_obj=setTimeout("InboxFadeIn()",100);		
	}
}
function InitInbox(){
	InboxTimerFunction();
}
function RefreshInboxIndicator2(){
	ajaxpage("inbox_indicator_ajax_rev.php","inbox_dropdown");
	ajaxpage("inbox_indicator_ajax2_rev.php","inbox_indicator2");
	ajaxpage("inbox_button.php","inbox_button_count");
}

function NotifTimerFunction(){
	RefreshNotification();
	NotifFadeIn();
	notif_timer_obj=setTimeout("NotifTimerFunction()",10000);

}

function NotifFadeIn(){
	div_opacity+=5;
	if(ie){
		if(document.getElementById("inbox_indicator5"))document.getElementById("inbox_indicator5").filters.alpha.opacity=div_opacity;
		if(document.getElementById("notif_indicator_text"))document.getElementById("notif_indicator_text").filters.alpha.opacity=div_opacity;
	}else{
		if(document.getElementById("inbox_indicator5"))document.getElementById("inbox_indicator5").style.MozOpacity=div_opacity;
		if(document.getElementById("notif_indicator_text"))document.getElementById("notif_indicator_text").style.MozOpacity=div_opacity;
	}
	if(div_opacity>=100){
		div_opacity=0;
		clearTimeout(notif_fading_obj);
	}else{
		notif_fading_obj=setTimeout("NotifFadeIn()",100);		
	}
}
function InitNotif(){
	NotifTimerFunction();
}

function RefreshTime(member_id){
	ajaxpage("notification_indicator_ajax.php?id="+member_id,"notif_indicator_text")
	ajaxpage("notif_button_ajax.php","inbox_indicator5");
}
function RefreshNotification(){
	ajaxpage("notification_indicator_ajax.php","notif_indicator_text");
	ajaxpage("notif_button_ajax.php","inbox_indicator5");
}
function RefreshNotif(){
	ajaxpage("notification_indicator_ajax2.php","notification_dropdown");
	ajaxpage("notif_button_ajax.php","inbox_indicator5");
}

function ShowLikeLoading(the_id){
	target=document.getElementById("btn_like_"+the_id);
	target.innerHTML="<img src='images/miniloading.gif'>";
}


function NewsLikeThis(the_id){
	ShowLikeLoading(the_id);
	ajaxpage("news_like_ajax.php?id="+the_id,"news_like_count_"+the_id);
	document.getElementById("btn_like_"+the_id).style.display="none";
}

function ReviewLikeThis(the_id){
	ShowLikeLoading(the_id);
	ajaxpage("review_like_ajax.php?id="+the_id,"review_like_count_"+the_id);
	document.getElementById("btn_like_"+the_id).style.display="none";
}

function GadgetLikeThis(the_id){
	ShowLikeLoading(the_id);
	ajaxpage("gadget_like_ajax.php?id="+the_id,"gadget_like_count_"+the_id);
	document.getElementById("btn_like_"+the_id).style.display="none";	
}	


