
/**
 * Tree folding/unfolding code
 */
$(function(){
	$("#tree>ul>li>a").click(function(){
		$(this).parent().children("ul").each(function(){
			$(this).slideToggle(400);
		});
	});
	$("#tabs").tabs({});

	// sIFR replacements
	if(typeof sIFR == "function"){
		sIFR.replaceElement("#tree h2", named({
													sFlashSrc: "swf/helveticalight.swf", 
													sColor: "#000",
													sWmode:'transparent',
													sBgColor:"#ffffff"
												})
											);
		sIFR.replaceElement(".list-box h2", named({
													sFlashSrc: "swf/helveticalight.swf", 
													sColor: "#000",
													sWmode:'transparent',
													sBgColor:"#ffffff"
												})
											);
	
	}
	
	// add center object function
	jQuery.fn.center = function () {

		// detect IE6
		if ($.browser.msie && $.browser.version.substr(0,1)<7){
			this.css("position","absolute");
		    this.css("top", ( $(window).height() - this.outerHeight() ) / 2+$(window).scrollTop() + "px");
		    this.css("left", ( $(window).width() - this.outerWidth() ) / 2+$(window).scrollLeft() + "px");
		} else {
			this.css("position","fixed");
		    this.css("top", ( $(window).height() - this.outerHeight() ) / 2 + "px");
		    this.css("left", ( $(window).width() - this.outerWidth() ) / 2 + "px");
		}
	    return this;
	};
	
});

var radiowindow;

/**
 * Pops up the radio window
 * 
 * @param id Channel index
 */
function popMusicBox(channel)
{
	channel = channel ? channel : 0;
	buddyid = channel ? 1 : 0;
	url = "http://www.orange.ro/music/musicbox.html?channel="+channel+"&buddy="+buddyid+"&WT.mc_id=synergy_orangero_musicbox";
	boxwindow=window.open(url,'MusicBox','height=575,width=965, resizable=false, scrollbars=false, toolbar=no, menubar=no, location=no, status=no');
	if (window.focus && radiowindow)
	{
		boxwindow.focus();
	}
}

/**
 * Selects one item from the top menu
 * 
 * @param id ID of the menu to select
 */
function selectMenu(id){
	var elementId="item-"+id;
	$('#header #menu li#'+elementId).each(function(){
		$(this).text($(this).text());
		$(this).addClass('selected');
	});	
}

/**
 * Checks newsletter form 
 */
function checkNewsletter(){
	var email=$("input[name=newsletter-email]").val();
	var reEmail= /^[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,4}$/i;
	var msg="";
	if (!email.length)
		msg+="Nu ati scris adresa de email.";
	else if (!reEmail.exec(email))
 			msg+="Adresa de email introdusa este invalida.\n\nDaca doresti sa primesti newsletterul Orange PrePay Music, te rugam sa reintroduci corect adresa de e-mail.";

	if (msg){
		alert (msg);
		return false;
	}
	return true;
}

