var self_host= "http://"+location.hostname+"/si/";
var thought_time;

JQ_eventListener = {
	init : function() {
		$("#close_quick_news").click(function(){
			$('#latest_news').cycle("stop");
			$('#latest_news').remove();
			$("#quick_news_window").slideUp("fast");
		});
	},

/*****************************************************************************************************************************************************************************************************/
/******************************************************************************************** AKCIJE *************************************************************************************************/
/*****************************************************************************************************************************************************************************************************/
	/*****************  ?? ACTIONS *******************/		
	show_thought_window : function(){
		//var cookie_val= Get_Cookie("thought");
		//var cookie_val= Get_Cookie("question");
		var cookie_val= Get_Cookie("echo");
		if(cookie_val==null){
			//tb_show("","/misel.php?keepThis=true&TB_iframe=true&height=394&width=480&modal=true","");
			//tb_show("","/popup_vprasanje.php?keepThis=true&TB_iframe=true&height=405&width=500&modal=true","");
			tb_show("","/popup_odmev.php?keepThis=true&TB_iframe=true&height=405&width=500&modal=true","");
			thought_time= setTimeout("JQ_eventListener.close_thought_window()",15000);
		}
	},
	
	close_thought_window : function(){
		//Set_Cookie( "thought", 0, null, "/");
		Set_Cookie( "echo", 0, null, "/");
		tb_remove();
	},
	
	clear_timeout : function(){
		clearTimeout(thought_time);
	},
	
	remove_thought_link : function(){
		$("tr.echo_link").remove();
	}
}


$(document).ready(
	function() {
		JQ_eventListener.init();
		
		$('#latest_news').cycle({ 
		    fx:      'custom', 
		    cssBefore: {  
		        left: 115,  
		        top:  115,  
		        width: 0,  
		        height: 0,  
		        opacity: 1, 
		        zIndex: 1 
		    }, 
		    animOut: {  
		        opacity: 0  
		    }, 
		    animIn: {  
		        left: 0,  
		        top: 0,  
		        width: 500,  
		        height: 200
		    }, 
		    cssAfter: {  
		        zIndex: 0
		    }, 
		    delay: -3000,
			timeout: 10000,
			random: 1
		});
		
		var myDate=new Date();
		myDate.setFullYear(2009,5,9); // drugi parameter so meseci z začetnim indeksom 0
		var today = new Date();
		
		if($("#jdebug").val() > 0){
			//alert("today: "+today+"\nmyDate: "+myDate);
		}	
		
		if($("#myLang").val()== "slo" && $("#inEventID").val()=="2610" && today < myDate)
			JQ_eventListener.show_thought_window();
			
		if($("#myLang").val()== "slo" && ($("#page4js").val()=="" && today < myDate) || $("#jdebug").val() > 0)
			JQ_eventListener.show_thought_window();
	}
); 


String.prototype.trim = function() {
	return this.replace("/^\s+|\s+$/g","");
}


jQuery['break'] = new Object();
	jQuery.extend({
	   each: function( obj, fn, args ) {
	       if ( obj.length == undefined )
	           for ( var i in obj )
	               try {
	                   fn.apply( obj[i], args || [i, obj[i]] );
	               } catch (e) {
	                   if (e == jQuery['break']) break;
	                   throw e;
	               }
	       else
	           for ( var i = 0; i < obj.length; i++ )
	               try {
					   fn.apply( obj[i], args || [i, obj[i]] );
	               } catch(e) {
	                   if (e == jQuery['break']) break;
	                   throw e;
	               }
	       return obj;
	   }
});


function IsNumeric(sText){
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;

 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
   
}

function getChexkAll(rel,thisdiv){
	if($('#'+thisdiv).is(':checked')){
		//$("input[rel='checkInput']").click();
		
		$("input[rel='"+rel+"']").attr("checked","checked");
	} else {
		$("input[rel='"+rel+"']").attr("checked","");
	}
}


function resetpassword(user_id){
	$.ajax({
		type: "POST",
		url: self_host+"ajax/",
		data: "act=reset_password&user_id="+user_id,
		async: false,
		success: function(msg){
			
		}
	});
}


function Set_Cookie( name, value, expires, path, domain, secure ) {
	// set time, it's in milliseconds
	var today = new Date();
	today.setTime( today.getTime() );

	/*
	if the expires variable is set, make the correct 
	expires time, the current script below will set 
	it for x number of days, to make it for hours, 
	delete * 24, for minutes, delete * 60 * 24
	*/
	if ( expires )
	{
	expires = expires * 1000 * 60 * 60 * 24;
	}
	var expires_date = new Date( today.getTime() + (expires) );

	document.cookie = name + "=" +escape( value ) +
	( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + 
	( ( path ) ? ";path=" + path : "" ) + 
	( ( domain ) ? ";domain=" + domain : "" ) +
	( ( secure ) ? ";secure" : "" );
}

function Get_Cookie( check_name ) {
	// first we'll split this cookie up into name/value pairs
	// note: document.cookie only returns name=value, not the other components
	var a_all_cookies = document.cookie.split( ';' );
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';
	var b_cookie_found = false; // set boolean t/f default f

	for ( i = 0; i < a_all_cookies.length; i++ )
	{
		// now we'll split apart each name=value pair
		a_temp_cookie = a_all_cookies[i].split( '=' );


		// and trim left/right whitespace while we're at it
		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');

		// if the extracted name matches passed check_name
		if ( cookie_name == check_name )
		{
			b_cookie_found = true;
			// we need to handle case where cookie has no value but exists (no = sign, that is):
			if ( a_temp_cookie.length > 1 )
			{
				cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
			}
			// note that in cases where cookie is initialized but no value, null is returned
			return cookie_value;
			break;
		}
		a_temp_cookie = null;
		cookie_name = '';
	}
	if ( !b_cookie_found )
	{
		return null;
	}
}