function SubscribeNewsletter()
{

	if( $('#email').attr("value") == "" )
	{
		alert( 'Nu ati completat campul Email' );
		$('#email').focus();
		return false;
	}
	
	var temp= new String($('#email').attr("value"));
	var len=temp.length - 3;
	if(temp=="" || temp.indexOf("@")<0 || temp.indexOf(".")<0 || temp.lastIndexOf(".")> len || temp.length-temp.lastIndexOf(".")>4)
	{
		alert("Va rugam introduceti o adresa de email corecta!");
	//	$('#email').attr("value") = "";
		$('#email').focus();
		return false;
	}
    
	
	$.ajax({
		  type: "POST",
		  url: "/framework/newsletter/newsletter.php",  
		  data:$("#ajax-form").serialize(),  
		  success: function(data,text) {
			 $("#body_form").html(data);
		  }
	});
	 
}	


function mycarousel_initCallback(carousel)
{
	$("#"+carousel.options.id+' .jcarousel-control a').bind('click', function() {
		carousel.scroll(jQuery.jcarousel.intval(jQuery(this).attr( "id" )));
		//carousel.stopAuto();
		return false;
	});
	
	
	$("#"+carousel.options.id+' .jcarousel-control a').hover(function() {
        carousel.stopAuto();
    }, function() {
        carousel.startAuto();
    });
	
    // Pause autoscrolling if the user moves with the cursor over the clip.
    carousel.clip.hover(function() {
        carousel.stopAuto();
    }, function() {
        carousel.startAuto();
    });
};

function mycarousel_itemVisibleInCallback(carousel,list,idx)
{
	$("#"+carousel.options.id+' .jcarousel-control').children(".selected").removeClass("selected");
	$("#"+carousel.options.id+' .jcarousel-control').children("#"+idx).addClass( "selected" );
}


function updateClock ()
{
  var currentTime = new Date ( );
  var currentHours = currentTime.getHours ( );
  var currentMinutes = currentTime.getMinutes ( );
  var currentSeconds = currentTime.getSeconds ( );
  // Pad the minutes and seconds with leading zeros, if required
  currentMinutes = ( currentMinutes < 10 ? "0" : "" ) + currentMinutes;
  currentSeconds = ( currentSeconds < 10 ? "0" : "" ) + currentSeconds;
  currentHours = ( currentHours < 10 ? "0" : "" ) + currentHours;
  var currentTimeString = currentHours + ":" + currentMinutes;
  $('#clock').html(currentTimeString);
}


jQuery(document).ready(function() {	
  	var currentTime = new Date();
	var hours = currentTime.getHours();
	var minutes = currentTime.getMinutes();
	if (minutes<10){minutes = "0"+minutes;}
	var time = hours + ":" + minutes;
	//alert(time);
	$('#clock').html(time);
	setInterval('updateClock()', 5000);
})

function open_window(a,w,h) {
  window.open(a.href, 'Antena3', 'resizable=no,location=no,menubar=no,scrollbars=yes,status=no,width='+w+',height='+h+'');
  return false;
}


jQuery.fn.resetDefaultValue = function() {
	function _clearDefaultValue() {
		var _$ = $(this);
		if ( _$.val() == this.defaultValue ) { _$.val(''); }
	};
	function _resetDefaultValue() {
		var _$ = $(this);
		if ( _$.val() == '' ) { _$.val(this.defaultValue); }
	};
	return this.click(_clearDefaultValue).focus(_clearDefaultValue).blur(_resetDefaultValue);
}

function Galerie(id)
{
	window.open("/popup_"+id+".html",'','width=800,height=630,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=no,resizable=0');
}


function CreateBookmarkLink() { 
	title = document.title;   // Blogger - Replace with <$BlogItemTitle$>   // MovableType - Replace with <$MTEntryTitle$> 
	url = window.location.href;  // Blogger - Replace with <$BlogItemPermalinkURL$>   // MovableType - Replace with <$MTEntryPermalink$>  // WordPress - <?php bloginfo('url'); ?>	
	if($.browser.msie){

		window.external.AddFavorite( url, title); 
	} else if( window.sidebar ) { // IE Favorite
		window.sidebar.addPanel(title, url,"");	
	}	else if(window.opera && window.print) { // Opera Hotlist		
		return true; 
	} 
} 



function OpenPrint(){
	window.open(window.location.href+'?print','print','width=700,height=500,scrollbars=yes');
}
function Show(obiect,day)
{
	var s=new jQuery(obiect);
	var position = s.position();
	
	$("#box_calendar_events").css("display","block");
	$("#box_calendar_events").css("left",position.left+20);
	$("#box_calendar_events").css("top",position.top +20);
	$("#box_calendar_events .body").html(ev[day]);
}


function Yahoo()
{
	window.location=encodeURI('ymsgr:im?msg='+(window.location.href));
}

//---------------------send email		
function SendEmail(url){
	if (CheckFormEmail()){
		  var name = $("input#name").val();
		  var email = $("input#email").val();
		  var name_friend = $("input#name_friend").val();
		  var email_friend = $("input#email_friend").val();
		  var id = $("input#id").val();
		  var dataString = 'send=send&id='+ id + '&name='+ name + '&email=' + email + '&name_friend=' + name_friend + '&email_friend=' + email_friend;
  		
		    $.ajax({
			  type: "POST",
			  url: url,
			  data: dataString,
			  success: function(data,text) {
				$("#box_email").html(data);
			  }
			});
			return false;
	}	 
}

function CheckFormEmail(){
	
	if( $("#name").attr("value") == "" )
	{
		alert( 'Nu ati completat campul Nume' );
		$('#name').focus();
		return false;
	}
	
	if( $('#email').attr("value") == "" )
	{
		alert( 'Nu ati completat campul Email' );
		$('#email').focus();
		return false;
	}
	var temp= new String($('#email').attr("value"));
	var len=temp.length - 3;
	if(temp=="" || temp.indexOf("@")<0 || temp.indexOf(".")<0 || temp.lastIndexOf(".")> len || temp.length-temp.lastIndexOf(".")>4)
	{
		alert("Va rugam introduceti o adresa de email corecta!");
	//	$('#email').attr("value") = "";
		$('#email').focus();
		return false;
	}
	
	
	if( $("#name_friend").attr("value") == "" )
	{
		alert( 'Nu ati completat campul Nume prieten' );
		$('#name_friend').focus();
		return false;
	}
	
	
	if( $('#email_friend').attr("value") == "" )
	{
		alert( 'Nu ati completat campul Email' );
		$('#email_friend').focus();
		return false;
	}
	var temp= new String($('#email_friend').attr("value"));
	var len=temp.length - 3;
	if(temp=="" || temp.indexOf("@")<0 || temp.indexOf(".")<0 || temp.lastIndexOf(".")> len || temp.length-temp.lastIndexOf(".")>4)
	{
		alert("Va rugam introduceti o adresa de email corecta!");
	//	$('#email').attr("value") = "";
		$('#email_friend').focus();
		return false;
	}
	
	return true;
}

function OpenBox(url){
	 $("#box_email").load(url);
	 
	ttop=0;
	if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
		ttop=window.pageYOffset;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
		ttop=document.documentElement.scrollTop;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		myWidth = document.body.clientWidth;
		myHeight = document.body.clientHeight;
		ttop=document.body.scrollTop;
	}

	l = (myWidth-700)/2;
	t = (myHeight-250)/2+ttop ; 
	
	 $('#box_email').css('left',l+'px');
	 $('#box_email').css('top' , t+'px'); 
	 
	 $('#box_email').css('display','block');
}

function Close(name){
	$('#'+name).css('display','none');
} 
function ChangeMonthCalendar(year,month)
{
	$("#box_calendar").load('/calendar_show.php?year='+year+"&month="+month);
}

function countChar(text,div,numar_caractere) {	
	val = text.value;
	if (val.length > numar_caractere) {
		alert('Textul dumneavoastra depaseste limita de '+numar_caractere+' de caractere!');
		text.value = val.substring(0,numar_caractere);
		text.focus();
	}
	document.getElementById(div).innerHTML = parseInt(val.length);
}


//-------------- SUBMENU

function showSubcategs(id) {
	setTimeout("showSubcategsTrue("+id+")", 100);
}

function showSubcategsTrue(id) {
	if (id == 100){
		return;	
	}
	
	var subcategDiv = document.getElementById("subcategs");
	if (subcategDiv){
		var visible = true;
		//var links = '<span>';
		
		//links += '</span>';
		//subcategDiv.innerHTML = links;
		
		var menuXPosition = getElementLeftParent("categ" + id); 	// 24 = padding

		var menuWidth = getElementWidth("categ" + id);
		
		var width = getElementWidth("subcategs");
		
		if (menuWidth <= 0 || width <= 0){
			setTimeout("showSubcategsTrue("+id+")", 100);
			return;
		}
		
		if (width <= 10){
			width = 100;	
		}
		//alert(menuWidth+'-'+width+'-'+menuXPosition);
		
		var diffWidth = width - menuWidth;
		var xPosition = menuXPosition;
		if (diffWidth > 0){
			xPosition = menuXPosition - diffWidth / 2;
		}else{
			xPosition = menuXPosition - diffWidth / 2;
		}
		
		if (xPosition + width > 980){
			xPosition = 980 - width;
		}
		
		if (xPosition < 0){
			xPosition = 0;
		}
		
		// added for right menu 
		if (id != 1000){
			subcategDiv.style.left = xPosition + "px";
		}
		
		if (visible){
			subcategDiv.style.visibility = "visible";
			overSubmenu = true;
		}else{
			subcategDiv.style.visibility = "hidden";
		}
	}
}

function getElementLeft(Elem) {
	var elem;
	if(document.getElementById) {
		var elem = document.getElementById(Elem);
	} else if (document.all){
		var elem = document.all[Elem];
	}
	xPos = elem.offsetLeft;
	tempEl = elem.offsetParent;
	while (tempEl != null) {
		xPos += tempEl.offsetLeft;
		tempEl = tempEl.offsetParent;
	}
	return xPos;
}

function getElementLeftParent(Elem) {
	var elem;
	if(document.getElementById) {
		var elem = document.getElementById(Elem);
	} else if (document.all){
		var elem = document.all[Elem];
	}
	xPos = elem.offsetLeft;
	return xPos;
}


function getElementTop(Elem) {
	var elem;
	if(document.getElementById) {	
		var elem = document.getElementById(Elem);
	} else if (document.all) {
		var elem = document.all[Elem];
	}
	yPos = elem.offsetTop;
	tempEl = elem.offsetParent;
	while (tempEl != null) {
		yPos += tempEl.offsetTop;
		tempEl = tempEl.offsetParent;
	}
	return yPos;
}

function getElementHeight(Elem) {
	if(document.getElementById) {
		var elem = document.getElementById(Elem);
	} else if (document.all){
		var elem = document.all[Elem];
	}
	if (elem.style.pixelHeight) { 
		xPos = elem.style.pixelHeight;
	} else {
		xPos = elem.offsetHeight;
	}
	return xPos;
}

function getElementWidth(Elem) {
	if(document.getElementById) {
		var elem = document.getElementById(Elem);
	} else if (document.all){
		var elem = document.all[Elem];
	}
	if (elem.style.pixelWidth) {
		xPos = elem.style.pixelWidth;
		if (xPos <= 15){
			xPos = elem.offsetWidth;
		}
	} else {
		xPos = elem.offsetWidth;
		if (xPos <= 15){
			xPos = elem.style.pixelWidth;
		}
	}
	return xPos;
}



