//var cookieEnabled = (navigator.cookieEnabled) ? true : false;
//var browser=navigator.appName
//if ( cookieEnabled == false )
	//window.location = "/missingjavascript.html";


	//errorCookie=get_cookie("error_login_cookie");

	function loadComments (topic_id, content_id, type, offset, div_id, total_comments )
	{

			var url='/api/web18/apiFetchIBNComments.php';
			var parametri="content_id="+content_id+"&topic_id="+topic_id+"&type="+type+"&offset="+offset+"&total_comments="+total_comments;

			$("load-"+offset+"-more").html("<div align='center'><img src='http://static.ibnlive.com/pix/comments-cmsmodule/loadinfo.net.gif' border='0'></div>");

			$.ajax({	
				  type: "GET",
				  url: url,
				  data: parametri,
				  success: function(msg, textStatus, XMLHttpRequest){
						//alert ("Div id :" +div_id+" offset "+offset );
					  document.getElementById("load-"+offset+"-more").style.display = 'none';
					  document.getElementById(div_id).style.display = 'block';
					  document.getElementById(div_id).innerHTML=msg;
				  }
			  });
	}

	function loadCommentsVideos (topic_id, content_id, type, offset, div_id, total_comments )
	{

			var url='/api/web18/apiFetchIBNCommentsVideo.php';
			var parametri="content_id="+content_id+"&topic_id="+topic_id+"&type="+type+"&offset="+offset+"&total_comments="+total_comments;

			$("load-"+offset+"-more").html("<div align='center'><img src='http://static.ibnlive.com/pix/comments-cmsmodule/loadinfo.net.gif' border='0'></div>");

			$.ajax({	
				  type: "GET",
				  url: url,
				  data: parametri,
				  success: function(msg, textStatus, XMLHttpRequest){
						//alert ("Div id :" +div_id+" offset "+offset );
//alert(msg)
					  document.getElementById("load-"+offset+"-more").style.display = 'none';
					  document.getElementById(div_id).style.display = 'block';
					  document.getElementById(div_id).innerHTML=msg;
				  }
			  });
	}

	

	function getDefaultEvent()
	{
		var postId=get_cookie('MESSAGE_POSTID');
		var eventId=get_cookie('MESSAGE_EVENT');
  	    
		var d = new Date();
		document.cookie = "MESSAGE_POSTID=1;expires=" + d.toGMTString() + ";" + ";";
		document.cookie = "MESSAGE_EVENT=1;expires=" + d.toGMTString() + ";" + ";";
		
		if(errorCookie!="")
		{
			//displays error page..
			var field="popUpLogin"+postId;
			var url='/conversations/popuploginArticle.php';
			var parametri="post_id="+postId+"&element="+eventId+"&errorMessage="+errorCookie;			
			
			$.ajax({	
				  type: "POST",
				  url: url,
				  data: parametri,
				  success: function(msg){
					  document.getElementById(field).style.display = 'block';
					  document.getElementById(field).innerHTML=msg;
				  }
			  });
		}
		else
		{
			if(postId==0)
			{
				window.location.href = "/conversations/post/####TOPIC_ID####.html";
			}
			else if(postId>0)
			{
				var cookie = get_cookie("POST_DATA_IBN");
				if(cookie!='')
				{
					if(eventId==5)
					{
						field='####DEFAULT_FIELD####';
						document.getElementById(field).style.display = 'block';
					}
					else
					{
						url='####DEFAULT_FILE####';
						parametri='####DEFAULT_URL####';
						$.ajax({	
							  type: "POST",
							  url: url,
							  data: parametri,
							  success: function(msg){
								  document.getElementById('####DEFAULT_FIELD####').style.display = 'block';
								  document.getElementById('####DEFAULT_FIELD####').innerHTML=msg;
  							  }
						  });
					}
				}
				else
				{
					document.getElementById('####DEFAULT_FIELD####').style.display = 'block';
				}
			}
		
		}
	}
	
	//$(document).ready(function() 
	//{
	//	getDefaultEvent();
	//	funcLoading(####TOPIC_ID####, '/conversations/save_topic_hits.php');
	 //});

	//$(document).ready(function() 
	//{	
	//	loadLoginContainer ('0', '116978'); //####TOPIC_ID####);
	 //});

	function loadLoginContainer (post_id, topic_id)
	{	
		//alert ("Default : "+post_id+" "+topic_id+" Cookie value "+ get_cookie("POST_DATA_IBN_IBN") );
		if ( get_cookie("POST_DATA_IBN")== ''  )
		{		
			url="/conversations/popuploginArticle.php";
			parametri="topic_id="+topic_id+"&post_id="+post_id+"&element=0";
			field="popUpLogin"+post_id;
					
			$.ajax({	
			  type: "POST",
			  url: url,
			  data: parametri,
			  success: function(msg){
				//alert (msg);
			  	//document.getElementById(field).style.display = 'block';
				  document.getElementById(field).innerHTML=msg;
			  }
	 	       });
			return false;
		}	
	}	 
	
	function validateCookie (post_id, arg, web18_user_id, web18_user_name, topic_id)
	{
		//alert ("validate post id  "+post_id+" Cookie "+cookie);
		var cookie = get_cookie("POST_DATA_IBN");
		//if ( post_id != 0 ){
			$("div[id^=popUpReplyPost]").hide();
			$("div[id^=popUpRating]").hide();
			$("div[id^=popUpTrackBorder]").hide();
			$("div[id^=popUpOffensive]").hide();
			$("div[id^=popUpTrackTopic]").hide();
			$("div[id^=popUpLogin]").hide();
			$("div[id^=popUpError]").hide();
		//}
		
		//document.getElementById("popUpLogin0").style.display = 'block';
		//By default make it on
		$("#popUpReplyPost0").show();


		if ( cookie == null  )
		{		
			url="/conversations/popuploginArticle.php";
			parametri="topic_id="+topic_id+"&post_id="+post_id+"&element="+arg;
			field="popUpLogin"+post_id;
					
			//$("#popUpLogin0").ajaxSend(function(evt, request, settings){
			 //       $(this).html("<div class='cblueBox'><b>Loading..</b>.</div>");
		      //});
			//alert ("----------"+field);
			$.ajax({	
			  type: "POST",
			  url: url,
			  data: parametri,
			  success: function(msg){
			  	document.getElementById(field).style.display = 'block';
				  document.getElementById(field).innerHTML=msg;
			  }
	 	       });


			return false;
		}
		
			
		switch (arg)
		{

			case 1:				
				url="/conversations/replypostArticle.php";
				parametri="post_id="+post_id+"&web18_user_id="+web18_user_id+"&web18_user_name="+web18_user_name+"&TOPIC_ID="+topic_id;
				field="popUpReplyPost"+post_id;
				break;	
			case 2:
					url="/conversations/rating.php";
					parametri="post_id="+post_id+"&web18_user_id="+web18_user_id+"&web18_user_name="+web18_user_name+"&TOPIC_ID="+topic_id;
				field="popUpRating"+post_id;
				break;				
			case 3:
					url="/conversations/tracking.php";
					parametri="post_id="+post_id+"&web18_user_id="+web18_user_id+"&web18_user_name="+web18_user_name+"&TOPIC_ID="+topic_id;
				field="layer"+post_id;	
				break;
			case 4:
					url="/conversations/offensive.php";
					parametri="post_id="+post_id+"&web18_user_id="+web18_user_id+"&web18_user_name="+web18_user_name+"&TOPIC_ID="+topic_id;
				field="popUpOffensive"+post_id;
				break;
			case 5:
				document.getElementById("layer").style.display='block';
				return;
				break;
			case 6:
				window.location.href = "/conversations/post/"+topic_id+".html";
				return;
				break;	
		}
		
		$.ajax({	
			  type: "POST",
			  url: url,
			  data: parametri,
			  success: function(msg){
				  document.getElementById(field).style.display = 'block';
				  document.getElementById(field).innerHTML=msg;
			  }
		  });
		  	
		

	}
	
	function procesareForm(option, post_id, web18_user_id, web18_user_name, topic_id, arg, arg2 )
	{

		if ( (get_cookie("POST_DATA_IBN") == '') && (post_id ==0) ) {
			$("#popUpReplyPost0").hide();
			$("#popUpLogin0").show();			
			$("#popUpReplyPost0").slideDown("slow");
			return false;
		}
	
		  var url_option = Array ("/conversations/submitReplyPost.php", "/conversations/submitOfRating.php", "/conversations/submitTrackBorder.php", "/conversations/submitOffensive.php", "/conversations/submitTrackTopic.php");	
		  
		  var tempInnerHTML = Array ("popUpReplyPost", "popUpRating", "popUpTrackBorder", "popUpOffensive",  "popUpTrackTopic");	
	
		if ( option == 3 || option == 4 || option == 5)
		{
			  var data = "";
			  var obj = document.getElementsByName(arg);

			  for ( var i=0 ; i < obj.length ; i++ ) {
				  if ( (obj[i].checked) == true ) {
					  data = obj[i].value; continue; 
				  }
			  }
			  if ( data == "" )
			  {
			 	alert ("Please select an option");
				return false;
			  }			  
			 arg = data;
		}
	
	  	 if ( option == 5 )
			 var temp = tempInnerHTML[ option - 1 ]; 
		  else
			  var temp = tempInnerHTML[ option - 1 ]+post_id;
			  
		  var parametri = "post_id="+post_id+"&web18_user_id="+web18_user_id+"&web18_user_name="+web18_user_name+"&topic_id="+topic_id+"&arg="+escape(arg);
		  
		 // alert (parametri);
		//"&arg2="+arg2+"&arg3="+arg3;
		
		if ( (option == 1) && (document.getElementById("post_text"+post_id).value == "") )
		{
			alert ("Please Put some comments");
			document.getElementById("post_text"+post_id).focus();
		}	  
		else
		{
			
  			if ( option == 3 )  // Track Border Layer to Blocked
			{
				document.getElementById("layer"+post_id).style.display='none';				
				document.getElementById("popUpTrackBorder"+post_id).style.display='block';				
			}

  			if ( option == 5 )  // Track Topic Layer to Blocked
			{
				document.getElementById("layer").style.display='none';				
				document.getElementById("popUpTrackTopic").style.display='block';				
			}

			$.ajax({	
			  type: "POST",
			  url: url_option[ option - 1 ],
			  data: parametri,
			  success: function(msg)
			  {				  
				$('#'+temp).attr( "innerHTML", msg );
			  }
			});
			return false;
		}  
		return false;
	 }
	 
	 
	function procesareFormTag(option, post_id, web18_user_id, web18_user_name, topic_id, arg, arg2 )
	{

		if ( (get_cookie("POST_DATA_IBN") == '') && (post_id ==0) ) {
			$("#popUpReplyPost0").hide();
			$("#popUpLogin0").show();			
			$("#popUpReplyPost0").slideDown("slow");
			return false;
		}
	
		  var url_option = Array ("/conversations/submitReplyPostTag.php", "/conversations/submitTrackTopic.php");	
		  
		  var tempInnerHTML = Array ("popUpReplyPost", "popUpTrackTopic");	
		  var temp = tempInnerHTML[ option - 1 ]+post_id;
	
		  var parametri = "post_id="+post_id+"&topic_id="+topic_id+"&arg="+escape(arg);
		  
		 //alert (parametri);
		//"&arg2="+arg2+"&arg3="+arg3;
		
		if ( (option == 1) && (document.getElementById("post_text"+post_id).value == "") )
		{
			alert ("Please Put some comments");
			document.getElementById("post_text"+post_id).focus();
		}	  
		else
		{
	
			$.ajax({	
			  type: "POST",
			  url: url_option[ option - 1 ],
			  data: parametri,
			  success: function(msg)
			  {				  
				$('#'+temp).attr( "innerHTML", msg );
			  }
			});
			return false;
		}  
		return false;
	 }
	 
	 function validateLogin ( form , post_id, element, topic_id)
	 {
		var login    = document.getElementById("login"+post_id).value;
		var password = document.getElementById("password"+post_id).value;

		//alert ("Login "+login+ " Password "+password);
	 	if ( login == "" ) {
			alert ("Login should not be blank"); document.getElementById("login"+post_id).focus();
			return false;
		}
		if ( password == "" ) 		{
			alert ("Password should not be blank");  document.getElementById("password"+post_id).focus();
			return false;
		}

		$("#popUpError"+post_id).html("<div align='center'><img src='http://static.ibnlive.com/pix/comments-cmsmodule/loadinfo.net.gif' border='0'></div>");

		$.ajax({	
			  type: "POST",
			  url: "/ibnregistration/loginverifyAjax.php",
			  data: "login="+login+"&password="+password,
			  success: function(msg){				

				if (msg == '1') {									
					var us_name = get_cookie_variable(get_cookie("POST_DATA_IBN"),1);
					var us_id   = get_cookie_variable(get_cookie("POST_DATA_IBN"),0);
					$("#popUpError"+post_id).html("<div align='center' class='fL btxt12' style='padding:5px 0px 0px 10px;'><b><a href='/conversations/user/"+us_id+".html'>Welcome "+us_name+"</a> | <a href='/ibnregistration/logout.php' target='_top'>Logout</a></b></div>");
					$("#popUpLogin"+post_id).hide();
					$("#popUpReplyPost"+post_id).show();
				}
				else 				
					$("#popUpError"+post_id).html("<div align='center' class='btxt12'><b>Error : username/password not matched</b></div>");					
			  }
		  });

		var today = new Date();
		today.setTime( today.getTime() );

		var expires_date = new Date( today.getTime() + (20*1000) );

		document.cookie="MESSAGE_POSTID="+post_id+";expires="+expires_date.toGMTString();
		document.cookie="MESSAGE_EVENT="+element+";expires="+expires_date.toGMTString();
		return false;
	 }


	 function checkMaxInput(frm, post_id, topic_id)
	 {	

		if ( get_cookie("POST_DATA_IBN") != '')	{
	 		maxLen = 2000;
			/*if ( document.getElementById(post_id).value.length > maxLen)
				document.getElementById(post_id).value.length = document.getElementById(post_id).value.substring(0, maxLen);
			else
				frm.charnum.value = maxLen - document.getElementById(post_id).value.length;*/
		}
		else
		{
			$("#popUpReplyPost0").hide();
			$("#popUpLogin0").show();			

			$("#popUpReplyPost0").slideDown("slow");
		}
	 }
	 
	//$(document).ready(function() 
	//{	
	//	$('#post_text0').click(function () {
	//		if ( get_cookie("POST_DATA_IBN") == '')	{
	//			$("#popUpReplyPost0").hide();
	//			$("#popUpLogin0").show();			
	//			$("#popUpReplyPost0").slideDown("slow");							
	//		}
	//	});
	//});

	  function funcPolling(arg1, arg2, topic_id)
	 {
	 	var obj = document.getElementsByName ("poll");
		
		for ( var i=0; i < obj.length ; i++ ) 
		{
			if ( obj[i].checked == true)
			{
				$.ajax({	
				  type: "POST",
				  url: "/conversations/poll_submit.php",
				  data: "arg1="+obj[i].value+"&arg2="+arg2+"&topic_id="+topic_id,
				  success: function(msg){
					$('#ajax_poll').attr( "innerHTML", msg );
				  }
			  });
				return false;
			}			
		}
		alert ("Please select a poll option");
		return false;		
	 }
	 
var state = 'none';
function changeImage(imgName, thread_box)
{
	if(document[imgName].alt == 'less')
	{
		document[imgName].alt = 'more';
		document[imgName].src = '/pix/conversion/plus.gif';
		state = 'none';
	}
	else
	{
		document[imgName].alt = 'less';
		document[imgName].src = '/pix/conversion/minus.gif';
		state = 'block';
	}
	if (document.all) 
	{ //IS IE 4 or 5 (or 6 beta)
		eval( "document.all." + thread_box + ".style.display = state");
	}
	
	if (document.layers) 
	{ //IS NETSCAPE 4 or below
		document.layers[thread_box].display = state;
	}
	if (document.getElementById && !document.all) {
		hza = document.getElementById(thread_box);
		hza.style.display = state;
	}
}

function changeTopicType(val, TOPIC_ID)
{
	var fileName='';
	switch(val)
	{
		case 'withthreading':
					fileName = "/conversations/thread/"+TOPIC_ID+".html";	
					break;	
		case 'nothreading':
					fileName = "/conversations/thread/flat/"+TOPIC_ID+".html";	
					break;
		case 'oldestfirst':
					fileName = "/conversations/thread/flat-asc/"+TOPIC_ID+".html";	
					break;	
		case 'toprated':
					fileName = "/conversations/thread/rate/"+TOPIC_ID+".html";	
					break;
	}
	window.location.href=fileName;
}


function funcOpenTrending (tab_id)
{
		$("div[id^=arrow] img").attr({'src':'http://static.ibnlive.com/pix/ibnhome/wt_hs_icon2.gif'});
		$("div[id^=widget]").hide();
		//$("#widget_"+tab_id).slideDown("slow");
		$("#widget_"+tab_id).show();
		$("div#arrow-"+tab_id+" img").attr({'src':'http://static.ibnlive.com/pix/ibnhome/wt_hs_icon.gif'});
}

var cssmenuids=["cssmenu1","cssmenu3"] //Enter id(s) of CSS Horizontal UL menus, separated by commas
var csssubmenuoffset=-1 //Offset of submenus from main menu. Default is 0 pixels.

/*function createcssmenu2(){
for (var i=0; i<cssmenuids.length; i++){
  var ultags=document.getElementById(cssmenuids[i]).getElementsByTagName("ul")
    for (var t=0; t<ultags.length; t++){
			ultags[t].style.top=ultags[t].parentNode.offsetHeight+csssubmenuoffset+"px"
    	var spanref=document.createElement("span")
			spanref.className="arrowdiv"
			spanref.innerHTML="&nbsp;&nbsp;&nbsp;&nbsp;"
			ultags[t].parentNode.getElementsByTagName("a")[0].appendChild(spanref)
    	ultags[t].parentNode.onmouseover=function(){
					this.className="active"
					this.style.zIndex=100
    	this.getElementsByTagName("ul")[0].style.visibility="visible"
					this.getElementsByTagName("ul")[0].style.zIndex=0
    	}
    	ultags[t].parentNode.onmouseout=function(){
					this.className=""
					this.style.zIndex=0
					this.getElementsByTagName("ul")[0].style.visibility="hidden"
					this.getElementsByTagName("ul")[0].style.zIndex=100
    	}
    }
  }
}

if (window.addEventListener)
window.addEventListener("load", createcssmenu2, false)
else if (window.attachEvent)
window.attachEvent("onload", createcssmenu2)*/



//// Live TV
var timeout	= 200;
var closetimer	= 0;
var ddmenuitem	= 0;
function mopen(id)
{	
	mcancelclosetime();
	if(ddmenuitem) ddmenuitem.style.visibility = 'hidden';
	ddmenuitem = document.getElementById(id);
	ddmenuitem.style.visibility = 'visible';

}
function mclose()
{
	if(ddmenuitem) ddmenuitem.style.visibility = 'hidden';
}
function mclosetime()
{
	closetimer = window.setTimeout(mclose, timeout);
}

// cancel close timer
function mcancelclosetime()
{
	if(closetimer)
	{
		window.clearTimeout(closetimer);
		closetimer = null;
	}
}

// close layer when click-out
document.onclick = mclose; 
