/************************************************************
Javascript - Funciones
Pagina: functions.js
Desarrollador: J.P.C.
Soporte: webmaster@starcomp.cl
Creado: 02/18/2004
Modificado: N/A
************************************************************
Notes/Comments: Pagina que contiene todas las funciones Javascript 

************************************************************
Updates: N/A
************************************************************/
function reloadPage(init) {  //reloads the window if Nav4 resized
	if (init==true) with (navigator) {
		if ((appName=="Netscape") && (parseInt(appVersion)==4)) {
			document.pgW=innerWidth; 
			document.pgH=innerHeight; 
			onresize=reloadPage; 
		}
	}
	else if (innerWidth!=document.pgW || innerHeight!=document.pgH) {
		location.reload();
	}
}
reloadPage(true);

function input_focus(field) {
	field.className = "inputsSelected";
}

function input_focus_code(field) {
	field.className = "inputsSelectedCode";
}

function input_blur(field) {
	field.className = "inputs";
}

function rollover(current,roll_image) { 
    current.src = roll_image; 
}

function window_status(message) {
	window.status = message;
}

function set_focus(form,field) {
	document[form][field].focus();
}

function choose_value(form,field_name,selectedField) {
	document[form][field_name].value = selectedField;
}

function preload_images() { 
    var args = preload_images.arguments; 
    document.imageArray = new Array(args.length); 

    for(var i=0; i<args.length; i++) { 
        document.imageArray[i] = new Image; 
        document.imageArray[i].src = args[i]; 
    } 
}

function find_DOM(object_id,incl_style) {
	/***************************
	IE 5+ || Netscape 6+
	***************************/
	if (document.getElementById) {
		found_object = document.getElementById(object_id);
	}
	/***************************
	IE 4
	***************************/
	else if (document.all) {
		found_object = document.all[object_id];
	}
	/***************************
	Netscape 4
	***************************/
	else {
		browser_version = parseInt(navigator.appVersion);
		if ((navigator.appName.indexOf('Netscape') != 1 && browser_version == 4)) {
			found_object = document.layers[object_id];
			var nav4 = true;
		}	
	}

	/***************************
	Return object
	***************************/
	if (incl_style == 1 && !nav4) {
		return found_object.style;
	} else {
		return found_object;
	}		
}

function show_hide_help(curr_menu,evt) {
	var this_menu = find_DOM(curr_menu,1);
	var shadow = find_DOM("Shadows",1);
	var x = null;
	var y = null;

	if (this_menu.visibility == "visible") {
		if (find_browser() == 1) { //Only fade out if IE, others kill
			fade_out(curr_menu,100);
			fade_out("Shadows",35);
		} else {
			this_menu.visibility = "hidden";
			shadow.visibility = "hidden";
		}
	} else {
		if (evt.x) { //Get the mouse position
			x = evt.x + 10;
			y = evt.y - 10;
		} else {
			x = evt.pageX + 10;
			y = evt.pageY - 10;
		}
		this_menu.left = x;
		this_menu.top = y;
		shadow.width = this_menu.width;
		shadow.height = this_menu.height;
		shadow.left = x + 2;
		shadow.top = y + 2;
		shadow.background = "#555555";
		shadow.zIndex = 1;
		this_menu.zIndex = 2;
		this_menu.visibility = "visible";
		shadow.visibility = "visible";
		shadow.filter = "alpha(opacity=35)";
	}		
}

function fade_out(curr_menu,opacity) {
	var this_menu = find_DOM(curr_menu,1);

	if (opacity > 0) { //Fade out the menu
		new_opacity = opacity - 10;
		this_menu.filter = "alpha(opacity=" + new_opacity + ")";
		setTimeout("fade_out('" + curr_menu + "','" + new_opacity + "')",1);
	}  else {
		this_menu.visibility = "hidden";
		if (curr_menu == "Shadows") {
			this_menu.filter = "alpha(opacity=35)";
		} else {
			this_menu.filter = "alpha(opacity=100)";
		}
	}
}

function find_browser() {
	var browser = null;
	if (navigator.appName == "Microsoft Internet Explorer") {
		return browser = 1;
	}
	else if (navigator.appName == "Netscape") {
		return browser = 2;	
	} else {
		return browser = 3;
	}
}

function show_hide_menu(curr_menu) {
	var this_menu = find_DOM(curr_menu,1);
	if (this_menu.display == "none") {
		this_menu.display = "block";
	} else {
		this_menu.display = "none";
	}		
}

function show_hide_code(curr_menu) {
	var this_menu = find_DOM(curr_menu,1);
	if (this_menu.display == "block") {
		this_menu.display = "none";
	} else {
		this_menu.display = "block";
	}		
}

function show_hide_code_load(cat,sub_cat) {
	var main_menu = find_DOM('cats',1);
	var category = find_DOM(cat,1);
	var sub_category = find_DOM(sub_cat,1);
	main_menu.display = "block";
	category.display = "block";
	sub_category.display = "block";	
}

function new_window(winURL,winNamer,winWidth,winHeight) { 
    if (winWidth < 1) { 
        winWidth = 400; 
    } 

    if (winHeight < 1) { 
        winHeight = 400; 
    } 

    var winl = (screen.width - winWidth) / 2; 
    var wint = (screen.height - winHeight) / 2; 
    window.open(winURL,winNamer,"width=" + winWidth + ",height=" + winHeight + ",left=" + winl + ",top=" + wint); 
} 

function new_window_scroll(winURL,winNamer,winWidth,winHeight) { 

    if (winWidth < 1) { 
        winWidth = 400; 
    } 

    if (winHeight < 1) { 
        winHeight = 400; 
    } 

    var winl = (screen.width - winWidth) / 2; 
    var wint = (screen.height - winHeight) / 2; 
    window.open(winURL,winNamer,"scrollbars=yes,width=" + winWidth + ",height=" + winHeight + ",left=" + winl + ",top=" + wint); 
}

function confirm_deletion(question,form) {	
	if (confirm(question)) {
		document[form].submit();
		return true;
    	} else {
         	return false;
     }
} 
