/*
	######################################################################################################
	########################################################################################### navigation
	######################################################################################################
*/

function openDoc (iURL) {
	document.location = iURL;
}

function openPrivacyPopUp (iFileName) {
	var fName = iFileName;
	var windowName = "privacy";
	var NS6 = (document.getElementById && navigator.appName.indexOf("Netscape")>=0 )? true: false;
	var width = (NS6) ? 600 : 617 ;
	var height = (NS6) ? 330 : 330 ;
	var scrollbars = "0";
	openPopup(fName,windowName,width,height,scrollbars);
}

function openVideoPopUp (iFileName) {
	var fName = iFileName;
	var windowName = "videos";
	var NS6 = (document.getElementById && navigator.appName.indexOf("Netscape")>=0 )? true: false;
	var width = (NS6) ? 600 : 617 ;
	var height = (NS6) ? 270 : 270 ;
	var height = (NS6) ? 300 : 300 ;
	openPopup(fName,windowName,width,height);
}

function openPopup (fileName,windowName,width,height,scrollbars) {
	ileft=(screen.width-width)/2;
	itop=(screen.height-height)/2;
	params = "toolbar=0,";
	params += "location=0,";
	params += "directories=0,";
	params += "status=0,";
	params += "menubar=0,";
	var scrollbars = (scrollbars) ? scrollbars : "yes" ;
	params += "scrollbars=" + scrollbars + ",";
	params += "resizable=yes,";
	params +="top=" + itop + ",";
	params +="left=" + ileft + ",";
	params += "width=" + width + ","; // Explorer, Navigator 2,3
	params += "height=" + height + ","; // Explorer, Navigator 2,3	
	params += "innerHeight=" + height + ","; // Navigator 4+
	params += "innerWidth=" + width; // Navigator 4+
	win = window.open(fileName, windowName, params);
	win.focus();
}

/*
	######################################################################################################
	######################################################################## object and styles referencing
	######################################################################################################
*/

var NS4 = (navigator.appName.indexOf("Netscape")>=0 && !document.getElementById)? true : false;
var IE4 = (document.all && !document.getElementById)? true : false;
var IE5 = (document.getElementById && document.all)? true : false;
var NS6 = (document.getElementById && navigator.appName.indexOf("Netscape")>=0 )? true: false;
var W3C = (document.getElementById)? true : false;

function getObj (layerName) {
	var layerRef = null;
	layerRef =  (NS4) ? document.layers[layerName] :
				(IE4) ? document.all[layerName] :
				(W3C) ? document.getElementById(layerName) :
				null;
	return layerRef;
}

function getStyle (objName,objRef) {
	var lyrRef = null;
	if (objName != null) {
		lyrRef = getObj(objName);			
	} else {
		lyrRef = objRef;
	}
	return lyrRef ? (NS4 ? lyrRef : lyrRef.style) : null;
}

function tellObj (obj,objName) {
	obj = (obj)  ? obj : getObj(objName);
	alert("object = " + obj);
	oStyle = getStyle('',obj);
	alert("style = " + oStyle);
}

function MM_findObj(n, d) {
	var p,i,x;
	if (!d) d = document;
	if ((p = n.indexOf("?")) > 0 && parent.frames.length) {
		d = parent.frames[n.substring(p + 1)].document;
		n = n.substring(0,p);
	}
	if (!(x = d[n]) && d.all) x = d.all[n];
	for (i = 0; !x && i < d.forms.length; i++) x = d.forms[i][n];
	for (i = 0; !x && d.layers && i < d.layers.length; i++) x = MM_findObj(n,d.layers[i].document);
  	if (!x && d.getElementById) x = d.getElementById(n);
	return x;
}

function MM_showHideLayers() {
	var i,p,v,obj,args = MM_showHideLayers.arguments;
	for (i = 0; i < (args.length - 2); i += 3) {
		if ((obj = MM_findObj(args[i])) != null) {
			v=args[i+2];
			if (obj.style) {
				obj = obj.style;
				v = (v == 'show') ? 'visible' : (v == 'hide') ? 'hidden' : v;
			}
			obj.visibility=v;
		}
	}
}

function switchImage(imgName, imgSrc) {
	var imgObj = MM_findObj(imgName);
	imgObj.src = imgSrc;
}

/*
	######################################################################################################
	########################################################################################## check forms
	######################################################################################################
*/

function checkemail (str) {
	var cond1 = (str.indexOf("@") > 0);
	var cond2 = (str.lastIndexOf(".") > str.indexOf("@"));
	return (cond1 && cond2);
}

function checkpassword (str) {
	if (str == undefined || str.length == 0) {
		return false;
	} else {
		return true;
	}
}

/*
	######################################################################################################
	################################################################################################# URLS
	######################################################################################################
*/

/*
	## TASKS
		1) Aggiunge una coppia nome=valore parametro GET ad una stringa URL
			a) Se l'URL non ha nessun GET, lo aggiunge
			b) Se l'URL ha già dei GET, ma non quello =$paramName, lo aggiunge
			c) Se l'URL ha già quel GET =$paramName, sostituisce $paramValue
			
*/
function addGetParamToUrl (iUrl,iParamName,iParamValue) {
	
	var newQueryString,newUrl;
	
	var queryString = document.location.search;
	
	if (queryString) {		
	
		var duplicateParam = (queryString.indexOf(iParamName) != -1);
		
		if (! duplicateParam) {
			
			newUrl = iUrl + "&" + iParamName + "=" + iParamValue;
			
		} else {
			
			newQueryString = "";
			var explode = String(document.location).split("?");
			var firstHalfUrl = explode[0];
			var sep = "&";
			var exploded = queryString.split(sep);
			for (var i = 0; i < exploded.length; i++) {
				var chunk = exploded[i];
				if (chunk.length == 0) {
					continue;
				}
				var s = chunk.indexOf(iParamName);
				if (s != -1) {
					var newChunk = iParamName + "=" + iParamValue;
					newQueryString += newChunk + "&";
				} else {
					newQueryString += chunk + "&";
				}
			}
			newUrl = firstHalfUrl + newQueryString;
		}
		
	} else {
		
		newUrl = iUrl + "?" + iParamName + "=" + iParamValue;
		
	}
	
	return newUrl;
}