function popUp(strFile, strNombre, intWidth, intHeight)
{
	leftVal = (screen.width - intWidth) / 2;
	topVal = (screen.height - intHeight) / 2;

	window.open(strFile, strNombre,'width=' + intWidth + ',height=' + intHeight + ',left=' + leftVal + ',top=' + topVal + ",scrollbars=yes");
}

function isConfirm(url, message)
{
	var resp = confirm(message, "");
	
	if(resp == true)
		document.location.href = url;
}

function goto(filename)
{
	document.location.href = filename;
}

function changeClass(obj, id)
{
	var element = document.getElementById(id);
	(obj.checked == true) ? element.className = "element_show" : element.className = "element_hidden";
}

function show_hide(obj)
{
	var elem = document.getElementById(obj);
	if(elem.className == "elem-hidden") elem.className = "elem-visible";
	else elem.className = "elem-hidden";
}

function genPWD()
{
	var pwd_field = $('#pwd');
  var chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
  pass = "";
  for(x=0; x<8; x++)
  {
    var i = Math.floor(Math.random() * 62);
    pass+= chars.charAt(i);
  }
  
	pwd_field.val(pass);
}

function addFavorites()
{
	if(jQuery.browser.msie)	window.external.AddFavorite(HTTP,'Private Sook');
	else if(jQuery.browser.mozilla) window.sidebar.addPanel(HTTP,'http://www.privatesook.com','');
	else {
		alert_r(FAVORITES_NOT_ALLOWED_TXT);
	}
}

var timeout;

$(document).ready(function(){			
	$("li a[@group]").click(function(){																																													
		var group = $(this).attr("group");
		parent(group, "");

		return false;
	});	
	$("li a[@group]").mouseout(function(){
		var group = $(this).attr("group");
		parent(group, "none");
		
		$("li div[@own='parent']").mouseover(function(){
			var ref = $(this).attr("ref");
			parent(ref, "");
		});
	});

	//mouseover for 'parent' div
	$("li div[@own='parent'], li div[@own='parent'] a").mouseover(function(){		
		var ref = $(this).attr("ref");
		parent(ref, "");
		
		clearTimeout(timeout);
	});	
	//mouseout for 'parent' div
	$("li div[@own='parent']").mouseout(function(){		
		var ref = $(this).attr("ref");
		var display = $("#result-" + ref).css("display");
		
		if(display == undefined) display = "none";		
		if(display == "none") parent(ref, "none");
		else parent(ref, "");

		timeout = setTimeout("parent('" + ref + "', 'none')", 100);
	});
	
	//link in the 'parent' div
	$("li div[@own='parent'] a").click(function(){
		var letter = $(this).attr("letter");
		var ref = $(this).attr("ref");
		loadContent(letter, ref);
		
		if($(this).attr("href") == "#") return false;
	});
	
	$("li div[@own='child'], li div[@own='child'] a").mouseover(function(){
		var ref = $(this).attr("ref");				
		parent(ref, "");
		child(ref, "");
		
		clearTimeout(timeout);
	});

	$("li div[@own='child']").mouseout(function(){
		var ref = $(this).attr("ref");
		parent(ref, "none");
	});
	
	/*
	** MySook Profile
	** custom loads
	*/

	$("input.chk-cloth").click(function(){
		var chk = $(this).attr('checked');
		if(chk == undefined) chk = false;
		
		if(chk == true) current_count_cloth = current_count_cloth + 1;
		else current_count_cloth = current_count_cloth - 1;
	});
	
	$("input.opt-vacation").click(function(){
		var chk = $(this).attr('checked');
		if(chk == undefined) chk = false;
		
		if(chk == true) current_count_vacation = current_count_vacation + 1;
		else current_count_vacation = current_count_vacation - 1;
	});

	$("input.chk-vacation").click(function(){
		var checked = $(this).is(":checked");
		var rel = $(this).attr("rel");
		
		var elem_f = $("#" + rel);
		var elems = elem_f.find("input").attr("disabled", !checked);
		elems.attr("disabled", !this.checked);
		
		//uncheck the other
		if($(this).val() == 1)
		{
			$("#user_profile_vacation_other").attr("checked", false);
		}
		else
		{
			$("#user_profile_vacation_france").attr("checked", false);
		}
	});

	$("input.chk-week").click(function(){
		var checked = $(this).is(":checked");
		var rel = $(this).attr("rel");
		
		var elem_f = $("#" + rel);
		var elems = elem_f.find("input").attr("disabled", !checked);
		elems.attr("disabled", !this.checked);
	});


	$("input.chk-type-house").click(function(){
		var val = $(this).attr("value");
		var checked = $(this).attr("checked");
		
		if(checked == undefined) checked = false;
		
		if(val == "27")
		{
			if(checked == false)	$("input.opt-house").attr("disabled", "disabled");
			else
			{
					$("input.opt-house").attr("disabled", "");
					$("input.chk-type-house[@value=28]").attr("checked", false);
			}
		}
		else if(val == "28")
		{
			if(checked == true)
			{
				$("input.chk-type-house[@value=27]").attr("checked", false);
				$("input.opt-house").attr("disabled", "disabled");
			}
		}
	});

	/*
	**
	** End MySook Profile
	**
	*/
	
});

function parent(id_name, show)
{
	if(show == "none")
	{
		$("#content-" + id_name).css("display", show);
		if($("#result-" + id_name)) $("#result-" + id_name).css("display", show);
	}
	else
	{
		$("#content-" + id_name).css("display", "");
	}
}

function child(id_name, show)
{
	$("#result-" + id_name).css("display", show);
}

function loadContent(letter, ref)
{
	$.ajax({
		type: "POST",
		data: "letter=" + letter,
		url: HTTP + "index.php?module=home&action=get_" + ref,
		success: function(result){
			child(ref, "none");
			$("#result-" + ref).html(result);
			if(result != "")
			{
				child(ref, "");
			}
		}
	});
}

function alert_r(string)
{
	var ret, tarea = document.createElement('textarea');
	string = str_replace(string, '<br />', '\r\n');
	tarea.innerHTML = string;
	ret = tarea.value;
	
	alert(ret);
}

function str_replace(haystack, needle, replacement) {
    var temp = haystack.split(needle);
    return temp.join(replacement);
}
