
//***********************************************************************
// 	indexOf function fix for Internet Explorer
//***********************************************************************

if (!Array.indexOf) {
	Array.prototype.indexOf = function(obj) {
		for(var i=0; i<this.length; i++) {
			if (this[i]==obj) {
				return i;
			}
		}
		return -1;
	}
}


//***********************************************************************
//	- Posem el focus al primer camp del formulari
//	- Canviem el color del border quan el camp agafa el focus o quan el perd
//***********************************************************************

$(document).ready(function() {	
	$(':input:visible:enabled:first').focus();
	
	$('input, textarea, select').focus(function(){
		$(this).css('border', '1px solid #D69728');
	});
	
	$('input, textarea, select').blur(function(){
		$(this).css('border', '1px solid #999999');
	});
});


function OpenWindow(url, w, h)
{
	var l = parseInt((screen.width - w)/2);
	var t = parseInt((screen.height - h)/2);
	var n = parseInt(Math.random() * 1000);
	var nw = window.open(url, "NewWindow" + n, "width=" + w + "px,height=" + h + "px,left=" + l + "px,top=" + t + "px");
	
	return nw;
}

function OpenWindowWScroll(url, w, h)
{
	var l = parseInt((screen.width - w)/2);
	var t = parseInt((screen.height - h)/2);
	var n = parseInt(Math.random() * 1000);
	var nw = window.open(url, "NewWindow" + n, "width=" + w + "px,height=" + h + "px,left=" + l + "px,top=" + t + "px,scrollbars=1");
}

function popup(url,name) 
{
 var width  = 500;
 var height = 300;
 var left   = (screen.width  - width)/2;
 var top    = (screen.height - height)/2;
 var params = 'width='+width+', height='+height;
 params += ', top='+top+', left='+left;
 params += ', directories=no';
 params += ', location=no';
 params += ', menubar=no';
 params += ', resizable=no';
 params += ', scrollbars=no';
 params += ', status=no';
 params += ', toolbar=no';
 newwin=window.open(url,name, params);
 if (window.focus) {newwin.focus()}
 return false;
}


function RefreshImage(valImageId) {
	var objImage = document.images[valImageId];
	if (objImage == undefined) {
		return;
	}
	var now = new Date();
	objImage.src = objImage.src.split('?')[0] + '?x=' + now.toUTCString();
}