/**
 *
 * @fileoverview General purpose library
 * The library is composed of 9 modules:
 * -conf
 * -core
 * -debug
 * -form
 * -misc
 * -moz
 * -tag
 * -validator
 * -xml
 *
 * @filename owjslib.js
 * @requires no dependency
 * @created 2006-04-11
 * @original author Fabio Serra
 * @copyright Kemen s.r.l.
 * @license Mozilla Public License Version 1.1
 * @version 0.4.5.1  *write same version number in ow.conf.VERSION*
 * @$LastChangedDate:: 2010-07-08#$
 * $LastChangedRevision: 2347 $
 * $LastChangedBy: faser $
*/

if(typeof(ow) == 'undefined') {var ow = {}};

/***********************************************
Conf  - Configure some behaviour of the library
************************************************/
ow.conf = {};

ow.conf.VERSION = "0.4.5.1";
ow.conf.debugEnabled = false;

/***********************************************
Core  - General and most used functions
************************************************/
ow.core = {};

/*:::::::::::::Array:::::::::::::*/
/**
 * Determines the index of the first element in which a specified value occurs
 * @param {array} array
 * @param {string} string
 * @return {int} index of the element, -1 if not found
 */
ow.core.arrayFind =function(array, string) {
	var index = -1;
	for(var i=0; i<array.length; i++){
		if(array[i] == string){
			index = i;
			break;
		};
	};
	return index;
};


/**
 * Uppercase the first letter after the minus sign.
 * Useful to convert css property to be usable with javascript
 * @param {string} str
 * @return {string} the string camelized
 * @author from prototype.js
 */
ow.core.camelize = function(str) {
	var oStringList = str.split('-');
    if (oStringList.length == 1) {return oStringList[0]};

    var camelizedString = str.indexOf('-') == 0
      ? oStringList[0].charAt(0).toUpperCase() + oStringList[0].substring(1)
      : oStringList[0];

    for (var i=1, len=oStringList.length; i<len; i++) {
      var s = oStringList[i];
      camelizedString += s.charAt(0).toUpperCase() + s.substring(1);
    };
    return camelizedString;
};


/**
 * Get the value of an attribute
 * @param {Dom Element} el
 * @param {String} attr
 * @param {Any} defaultValue (Optional) alternative value to return if the attribute does not exists
 * @return {String|Obj|null} null or an alternative value if the attribute does not exist
 */
ow.core.getAttribute = function(el, attr, defaultValue){
	if (el.getAttribute(attr, 2)) {
		return el.getAttribute(attr);
	}
	else {
		return defaultValue !== undefined ? defaultValue : null
	}
};


/*:::::::::::::List::::::::::::::*/

/**
 * Concatenates a list or elements to a list
 *
 * @param {string} list  A list or a variable that contains one
 * @param {string} value An element or a list of elements
 * @param {string} delimiter [optional] Character(s) that separate list elements. The default value is comma
 * @return {string} A copy of the list, with value appended.
 */
ow.core.listAppend = function(list, value, delimiter) {
	if(!delimiter){delimiter = ",";};
	if(ow.core.trim(list) === "") {
		return "" + value;
	}else{
		return "" + list + delimiter + value;
	};
};
/*:::::::::::::String::::::::::::*/

/**
 * Remove tags from a string
 *
 * @param {string} str
 * @return {string} the string without tags
 */
ow.core.stripTags = function(str) {
	return str.toString().replace(/(<([^>]+)>)/ig,"");
};

/**
 * Trim space
 * @param {string} str
 * @return {string }the trimmed string
 */
ow.core.trim = function(str) {
 	return str.toString().replace(/\s+$|^\s+/g,"");
};

/**
 * Converts the alphabetic characters in a string to uppercase
 * @param {string} str
 * @return {string}string converted to uppercase.
 */
ow.core.uCase = function(str) {
	return String(str).toUpperCase();
};

/**
 * Shortens a string without cutting words in half.
 *
 * @param {string}  str      	The string to modify.
 * @param {integer} words   	The number of words to display.
 * @param {bool}	ellipsis 	Add ellipsis at the end of the string
 * @type string
 */
ow.core.getWords = function(str, words, ellipsis) {
	var theString = ow.core.trim(str);
	// remove space before commas and double spaces
	theString = theString.replace(/ ,/g, ",").replace(/  /g, " ");
	var arString = theString.split(" ");
	var len = arString.length;
	if(len > words) {
		theString = "";
		for(var i=0; i<len; i++) {
			if(ow.core.trim(arString[i])){
				theString += arString[i];
				if(theString.split(" ").length > words) {
					if(ellipsis) {theString += "...";};
					break;
				}else{
					theString += " ";
				};
			};
		};
	};
	return theString;
};


/*:::::::::::::Window::::::::::::*/
/**
 * Get the value of a url param
 * @param {string} name the name of param
 * @param {bool} parentLocation [optional]  if the query string should be returned form the parent url
 * @param {bool} caseSensitive [optional] default false
 * @return {string} the value of the url param url decoded
 */
ow.core.getUrlParam = function(paramName, parentLocation, caseSensitive) {
	var res = "";
	var queryString = "";
	var sensitive = false;
	if(caseSensitive) {
		sensitive = true;
	}

	if(parentLocation) {
		queryString = self.parent.location.search;
	}else{
		queryString = document.location.search;
	};

	if (!sensitive) {
		paramName = paramName.toLowerCase();
	}

	queryString = decodeURI(queryString);

	if(queryString.length >= 0){
		if(queryString.charAt(0) == "?"){queryString = queryString.substring(1);}
		var sep = (queryString.indexOf("&amp;") >= 0) ? "&amp;" : "&";
		queryString = queryString.split(sep);
		for(var i=0; i<queryString.length; i++){
			var tmpArray = queryString[i].split("=");
			var key = tmpArray[0]
			if (!sensitive) {
				key = key.toLowerCase();
			}
			if(key == paramName) {
				res = tmpArray[1];
				break;
			};
		};
	};
	return res;
};


/**
 *
 * Create a overlay div to be used as a modal window.
 *
 * @param {string} content 		The content messages to display
 * @param {string} outerStyle 	The CCS properties for the outer div.
 * 								Pass at least the background-image style for the correct overaly image url
 * @param {string} innerStyle 	The CSS custom properties for the inner div
 * @param {boolean}reset		Don't use any default CSS style
 * @return {HTMLDivElement} 	the created div
 */
ow.core.overlay = function(content, outerStyle, innerStyle, reset) {
	var styleToApply = [];
	styleToApply[0] = "visibility:visible;position:absolute;left:0px;top:0px;width:100%;height:100%;" +
						"text-align:center;background-image:url(overlay.gif);z-index:1001;";
	styleToApply[1] = "width:300px;margin:100px auto;background-color:#fff;border:1px solid #000;"+
						"padding:15px;text-align:center;";

	if(!outerStyle) {outerStyle = "";}
	if(!innerStyle) {innerStyle = "";}

	if(reset == true) {
		styleToApply[0] = outerStyle;
		styleToApply[1] = innerStyle;
	}else{
		//The property with the same name should be overwritten by the last ones
		styleToApply[0] += outerStyle;
		styleToApply[1] += innerStyle;
	}
	var divs = [];
	//Outer Div
	divs[0] = document.createElement("div");
	//Inner Div
	divs[1] = document.createElement("div");

	//Text to Display
	divs[1].innerHTML = content;
	//Apply Styles
	var tmp, propVal;
	for(var i=0; i< styleToApply.length; i++) {
		propVal = styleToApply[i].split(";");
		for(var j=0; j<propVal.length;j++) {
			tmp = propVal[j].split(":");
			if(tmp.length != 2) {
				break;
			}else{
				divs[i].style[ow.core.camelize(ow.core.trim(tmp[0]))] = tmp[1];
			};
		};
	};

	var theBody = document.getElementsByTagName("body").item(0);
	/*Force Style Body for IE */
	theBody.style.height = "100%";
	theBody.style.margin = 0;
	theBody.style.padding = 0;

	divs[0].appendChild(divs[1]);
	return theBody.appendChild(divs[0]);
};

/**
 * Open a new browser windows. Default is without features
 * @param {string} 	url
 * 					the url of the page to load
 * @param {string}	winName
 * 					a window name
 * @param {int}		winWidth
 * 					window width
 * @param {int}		winHeight
 * 					window height
 * @param {string}	winFeatures
 * 					a list of features separated by coma. Pass only the feature name
 * 					(eg: toolbar,scrollbars). Special features admited: centerscreen
 * @return {object} a reference to the new window
 */
ow.core.openWin = function(url, winName, winWidth, winHeight, winFeatures) {
	if(!url)		{url = "";}
	if(!winName)	{winName = "NewWindow";}
	if(!winWidth)	{winWidth = 450;}
	if(!winHeight)	{winHeight = 320;}
	if(!winFeatures){
		winFeatures = "resizable=1";
	}else{
		var params = winFeatures.split(",");
		for(var i=0; i<params.length; i++) {
			params[i] = ow.core.trim(params[i]);
		}
		//Center the window on the screen
		var centerscreen = ow.core.arrayFind(params, "centerscreen");
		if(centerscreen > -1) {
			//Fudge factors for window decoration space.
			var winWidthFudge = winWidth + 32;
			var winHeightFudge = winHeight + 96;
			var wLeft = (screen.width - winWidthFudge) / 2;
			var wTop = (screen.height - winHeightFudge) / 2;
			var strLeft = "left=" + wLeft;
			var strTop 	= "top=" + wTop;
			params.push(strTop);
			params.push(strLeft);
			winFeatures = params.join(",");

		};
	};

	var gui = "width=" + winWidth + ",height=" + winHeight + "," + winFeatures;
	var win = window.open(url, winName, gui);
	win.focus();
	return win;
};

/*:::::::::::::Date::::::::::::::*/

ow.core.EPOCH = new Date("1 January 1970 00:00:00");

/**
 * Convert a string in a date object
 * @param {string} str
 * @return {date} a date
 */
ow.core.toDate = function(str) {
	var theDate;
	if(typeof(str) == "date") {
		theDate = str;
	}else{
		theDate = new Date(Date.parse(str));
		if(theDate == "Invalid Date") {
			//Return the Epoch
			theDate = ow.core.EPOCH;
		};
	};
	return theDate;
};

/*:::::::::::::DOM:::::::::::::::*/

/**
 * Get the node value of the first element
 * @param {Object} domDoc
 * @param {string} tagName
 * @deprecated use ow.xml.getElementValue
 */
ow.core.getElementValue = function(domDoc, tagName) {
	return ow.xml.getElementValue(domDoc, tagName);
};

/**
 * Add a row in a html table
 *
 * @param {string} tableID
 * @param {array} cellsContent the content of the cells
 */
ow.core.addTableRow = function(tableID, cellsContent) {
	var table = document.getElementById(tableID);
	var row = table.insertRow(table.rows.length);
	var cell = "";
	for(var i=0; i< cellsContent.length; i++) {
		cell = row.insertCell(row.cells.length);
		cell.innerHTML = cellsContent[i];
	};
};


/**
 * Takes a list of tag names and returns an array that contains all elements with these tag names in the order they appear in the source code.
 * See: http://www.quirksmode.org/dom/getElementsByTagNames.html
 *
 * @param {String} list List of tag names
 * @param {Object} obj Object from where to start
 */
ow.core.getElementsByTagNames = function (list, obj) {
	if (!obj) var obj = document;
	var tagNames = list.split(',');
	var resultArray = new Array();
	for (var i=0;i<tagNames.length;i++) {
		var tags = obj.getElementsByTagName(tagNames[i]);
		for (var j=0;j<tags.length;j++) {
			resultArray.push(tags[j]);
		};
	};
	var testNode = resultArray[0];
	if (!testNode) {
		return [];
	};
	if (testNode.sourceIndex) {
		resultArray.sort(function (a,b) {
				return a.sourceIndex - b.sourceIndex;
		});
	}
	else if (testNode.compareDocumentPosition) {
		resultArray.sort(function (a,b) {
				return 3 - (a.compareDocumentPosition(b) & 6);
		});
	};
	return resultArray;
};


/*:::::::::::::Number::::::::::::*/
/**
 * TOFIX bug for negative number!!
 * Convert a string in a number. If the string can't be converted return 0
 * @param {string} str
 * @return {number} a number
 */
ow.core.toNumber = function(str) {
	var num;
	if(!str || str == "") {
		num = 0;
	}else if(typeof(str) == 'number'){
		num = str;
	} else {
		num = parseFloat((str.replace(/[^0-9\.,]/g, "").replace(",",".")));
	};

	if(isNaN(num)) {num = 0;};
	return num;
};


/*:::::::::::Formatting::::::::::*/
/*:::::::::::::Others::::::::::::*/

/**
 * @param a the first value
 * @param b the second value
 * @param {bool} asc ascending or descending comparision
 * @param {string} type the comparision type [string, number, date]
 * @return {int}
 */
ow.core.compare = function(a, b, asc, type) {
	if(typeof(asc) == "undefined"){asc = true;}
	if(typeof(type) == "undefined"){type = "string";}
	var cast = ow.core.uCase;

	switch(type) {
		case "number":
			cast = ow.core.toNumber;
			break;
		case "date":
			cast = ow.core.toDate;
			break;
	};

	if (cast(a) < cast(b)) {
		return asc ? -1 : 1;
	} else if (cast(a) > cast(b)) {
		return asc ? 1 : -1;
	}else{
		return 0;
	};
};


/**
 * Execute a function after the window is completly loaded
 * @param {Function} f the function name
 */
ow.core.addWindowOnLoad = function(f) {
	var _onload = window.onload;
	if (typeof window.onload != 'function') {
    	window.onload = f;
    } else {
    	window.onload = function() {
			_onload();
			f();
        };
    };
};


/**
 * Fix for the getElementsByName not working for elements created via JS in Internet Explorer
 *
 * @param {String} tag
 * @param {String} name
 */
ow.core.getElementsByName_ie = function(tag, name){
	var elem = document.getElementsByTagName(tag);
	var arr = new Array();
	for (i = 0, iarr = 0; i < elem.length; i++) {
		att = elem[i].getAttribute("name");
		if (att == name) {
			arr[iarr] = elem[i];
			iarr++;
		}
	}
	return arr;
};

/**
 * Return the size (number of elements) of an object
 * @param {Object} obj
 */

ow.core.getObjectSize = function(obj){
	var size = 0, key;
	for (key in obj) {
		if (obj.hasOwnProperty(key))
			size++;
	}
	return size;
};

/**
 * Check if the browser is Internet Explorer
 * @return {boolean} true or false
 */
ow.core.isIE = function(){
	var isIE = false;
	if (navigator.appName&&navigator.appName=='Microsoft Internet Explorer') {
		isIE = true;
	};
	return isIE;
};
/**
 * Check if the browser is Gecko based
 * @return {boolean} true or false
 */
ow.core.isMoz = function() {
	var isMoz = false;
	if(navigator.product) {
		if(navigator.product == "Gecko"){
			isMoz = true;
		};
	};
	return isMoz;
};

/**
 * Load an externa javascript or css file
 * @param {String} path The path and the name of the file to load
 * @param {String} type 'css' or 'js'. Default: js
 */
ow.core.loadExternalFile = function(path, type){
	if (!type) {
		type = 'js'
	};
	switch (type) {
		case 'js':
			var fileRef = document.createElement('script');
			fileRef.setAttribute("type", "text/javascript");
			fileRef.setAttribute("src", path);
			break;
		case 'css':
			var fileRef = document.createElement("link")
			fileRef.setAttribute("rel", "stylesheet")
			fileRef.setAttribute("type", "text/css")
			fileRef.setAttribute("href", filename)
			break;
	}
	if (typeof fileRef != "undefined")
		document.getElementsByTagName("head")[0].appendChild(fileRef);
};


/**
 * Change the display status of an html element
 * @param {string} elId
 */
ow.core.toogle = function (elId) {
	var el = document.getElementById(elId);
	if (el.style.display != 'none') {
		el.style.display = 'none';
	}else {
		el.style.display = '';
	};
};

/*******************************************
Form  -
********************************************/
ow.form = {};

/**
 * Set checkbox checked with value list passed
 * @param {string} checkboxName
 * @param {string} lstValues list of values to check
 */
ow.form.setCheckboxValues = function(checkboxName, lstValues){
	if(ow.core.isIE()) {
		var arrayCheckboxes = ow.core.getElementsByName_ie('input', checkboxName);
	}
	else {
		var arrayCheckboxes = document.getElementsByName(checkboxName);
	}

	var n = arrayCheckboxes.length;
	var arrayValues = [];

	if ( lstValues!= '') {
		arrayValues = lstValues.split(',');
	};

  	for ( var index = 0; index < n; index++ ){
		// Faccio un loop sulla lista passata e faccio check dei checkbox
	  	if (lstValues!= '' && ow.core.arrayFind(arrayValues, arrayCheckboxes[index].value) != -1) {
			arrayCheckboxes[index].checked = true;
		} else {
			arrayCheckboxes[index].checked = false;
		};
  	};
};
/**
 * Return the list of checked attribute for the checkboxName passed
 * @param {string} checkboxName
 * @param {string} attributeName (optional)
 * @return {string} list of checked values
 */
ow.form.getCheckboxValues = function(checkboxName, attributeName){
	if(ow.core.isIE()) {
		var arrayCheckboxes = ow.core.getElementsByName_ie('input', checkboxName);
	}
	else {
		var arrayCheckboxes = document.getElementsByName(checkboxName);
	}
	var n = arrayCheckboxes.length;

	var lstValues = "";
	if (!attributeName) {
		attributeName = 'value';
	};
	for (var index = 0; index < n; index++) {
		if (arrayCheckboxes[index].checked == true && arrayCheckboxes[index].getAttribute(attributeName) != '') {
			if (lstValues != '') {
				lstValues = lstValues + ',' + arrayCheckboxes[index].getAttribute(attributeName);
			}
			else {
				lstValues = arrayCheckboxes[index].getAttribute(attributeName);
			}
		}
	};
	return lstValues;
};

/**
 *
 * @param {Object} radioName
 * @param {Object} radioValue
 */
ow.form.checkRadioByValue = function(radioName, radioValue) {
	var inputs = document.getElementsByTagName("input");
	var founded = false;
	if(inputs) {
    	for(var i=0; i<inputs.length; ++i) {
      		if (inputs[i].type == "radio" & inputs[i].name == radioName) {
        		if(inputs[i].value == radioValue) {
        			inputs[i].checked = true;
					founded = true;
        		};
			};
    	};
  	}
	return founded;
};
/**
 * Return the list of selected attribute for the selectName passed
 * @param {string} selectName or select element
 * @param {string} attributeName (optional)
 * @return {string} list of selected values
 */
ow.form.getSelectValues = function (selectName, attributeName){
	if (typeof(selectName) == 'string') {	
		if (ow.core.isIE()) {
			var arraySelect = ow.core.getElementsByName_ie('select', selectName);
		}
		else {
			var arraySelect = document.getElementsByName(selectName);
		}
	}
	else {
		arraySelect=[selectName];
	}
	var n = arraySelect.length;
	var lstValues = "";
	if(!attributeName){
		attributeName = 'value';
	};
  	for ( var index = 0; index < n; index++ ){
		var m = arraySelect[index].options.length;

		for ( var optIndex = 0 ; optIndex < m; optIndex++ ) {
			var thisOption = arraySelect[index].options[optIndex];
			if (thisOption.selected == true && thisOption.getAttribute(attributeName) != '') {
				if (lstValues != ''){
					lstValues = lstValues + ',' + thisOption.getAttribute(attributeName);
				} else {
					lstValues = thisOption.getAttribute(attributeName);
				};
			};
		};
  	};
	return 	lstValues;
};

/**
 * Set selects' options with value list passed as (un)selected
 * @param {string} selectName
 * @param {string} lstValues list of values to select
 */
ow.form.setSelectValues = function(selectName, lstValues){
	if(ow.core.isIE()) {
		var arraySelects = ow.core.getElementsByName_ie('select', selectName);
	}
	else {
		var arraySelects = document.getElementsByName(selectName);
	}

	var n = arraySelects.length;
	var arrayValues = [];

	if ( lstValues!= '') {
		arrayValues = lstValues.split(',');
	};

  	for ( var index = 0; index < n; index++ ){

		for (var selectIndex = 0; selectIndex < arraySelects[index].options.length; selectIndex++) {
			if (lstValues!= '' && ow.core.arrayFind(arrayValues, arraySelects[index].options[selectIndex].value) != -1) {
				arraySelects[index].options[selectIndex].selected = true;
			} else {
				arraySelects[index].options[selectIndex].selected = false;
			};
		};

  	};
};

/**
 * Returns true if a checkbox or a radio button is checked, false otherwise
 * @param {HTML element collection} el The checkbox or the radio button elements
 */
ow.form.isChecked = function (el) {
	for (var i = 0; i < el.length; i++)
		if (el[i].checked) {
			return true;
		};
	return false;
};

/**
 * Enable or disable submit buttons
 *
 * @param {String/HTML Element} form	Element where to search the submit
 * @param {Boolean} Optional Enable or disable them? Default = true
 * @return void
 */
ow.form.disableSubmit = function(form){
	var aInputs = form.getElementsByTagName('input');
	if (aInputs.length) {
		for (var i = 0; i < aInputs.length; i++) {
			if (aInputs[i].type == 'submit') {

				aInputs[i].disabled = arguments[1] !== undefined ? arguments[1] : true;
			};
		};
	};
};

/**
 * Generate a request string using the form elements 
 * For example: element.name=element.value&element1.name=element1.value etc.
 * @param {Object} form
 */

ow.form.generateRequest = function(form){
	var oForm = form, oElement, oName, oValue, oDisabled, hasSubmit = false, data = [], item = 0, i, len, j, jlen, opt;
	
	for (i = 0, len = oForm.elements.length; i < len; ++i) {
		oElement = oForm.elements[i];
		oDisabled = oElement.disabled;
		oName = oElement.name;
		
		// Do not consinder fields that are disabled or
		// do not have a name attribute value.
		if (!oDisabled && oName) {
			oName = encodeURIComponent(oName) + '=';
			oValue = encodeURIComponent(oElement.value);
			
			switch (oElement.type) {
				// Safari, Opera, FF all default opt.value from .text if
				// value attribute not specified in markup
				case 'select-one':
					if (oElement.selectedIndex > -1) {
						opt = oElement.options[oElement.selectedIndex];
						data[item++] = oName +
						encodeURIComponent((opt.attributes.value && opt.attributes.value.specified) ? opt.value : opt.text);
					}
					break;
				case 'select-multiple':
					if (oElement.selectedIndex > -1) {
						for (j = oElement.selectedIndex, jlen = oElement.options.length; j < jlen; ++j) {
							opt = oElement.options[j];
							if (opt.selected) {
								data[item++] = oName +
								encodeURIComponent((opt.attributes.value && opt.attributes.value.specified) ? opt.value : opt.text);
							}
						}
					}
					break;
				case 'radio':
				case 'checkbox':
					if (oElement.checked) {
						data[item++] = oName + oValue;
					}
					break;
				case 'file':
				case undefined:
				case 'reset':
				case 'button':
					break;
				case 'submit':
					if (hasSubmit === false) {
						if (this._hasSubmitListener && this._submitElementValue) {
							data[item++] = this._submitElementValue;
						}
						hasSubmit = true;
					}
					break;
				default:
					data[item++] = oName + oValue;
			}
		}
	}
	return data.toString().replace(/,/g,'&');
}

/*******************************************
Tag  - Every function that works using custom attributes (ow:)
// TODO: the following functions does not follow the guidelines of this library - gp @29/01/09
********************************************/
ow.tag = {};

/**
 * Find every a href with custom attribute ow:showImage for
 * preloading the images and add onclick event for display the
 * image in a popup window or inside the page
 * @taginfo ow:showImage= [popup | page]
 * @usage: 	<a href="big.jpg" ow:showImage="popup" title="Image Big"><img src="small.jpg"/></a>
 * 			<a href="big.jpg" ow:showImage="page" title="Image Big" target="the_div_id"><img src="small.jpg"/></a>
 */
ow.tag.showImage = function() {

	//Search for tag with ow:showImage attributes
	var allTags = document.getElementsByTagName("a");
	var href = "";
	for(var i=0; i<allTags.length;i++) {
		if(allTags[i].getAttribute("ow:showImage")){
			href = allTags[i].getAttribute("href");
			allTags[i].theImage =  new Image();
			allTags[i].theImage.src = href;
			if(allTags[i].getAttribute("ow:showImage") == "popup") {
				allTags[i].onclick = openImage;
			}else if(allTags[i].getAttribute("ow:showImage") == "page") {
				allTags[i].onclick = viewImage;
			};
		};
	};

	function openImage() {
		var params = "centerscreen";
		var winWidth  = 618;
		var winHeight = 480;
		var winTitle = this.getAttribute("title");
		var winName  = this.getAttribute("target");
		if(!winName || winName == "_blank") {
			winName = "";
		};
		var theSource = this.theImage.src;
		var fixDimension = 5; //Reduce windows dimension for Internet Explorer
		if(this.theImage.width > 0) {
			winWidth 	= this.theImage.width - fixDimension;
			winHeight 	= this.theImage.height - fixDimension;
		};

		var strImage = '<div align="center"><img src="'+ theSource + '" border="0" hspace="0" vspace="0" align="middle"></div>';
		var strBaseWindow = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">'+
							'<html><head><style type="text/css">body{border: 0px;margin: 0px;padding:0px;}</style><title>'+ winTitle +'</title>'+
							'</head><body onload="self.focus();" onblur="self.close()">'+ strImage +'</body></html>';

		var win = ow.core.openWin(null, winName, winWidth, winHeight, params);
		var tmp = win.document;
		tmp.write(strBaseWindow);
		tmp.close();
		win.focus();
		return false;
	};

/*
 * Show the bigger image inside the element identified by the id written in the a href
 * target attribute
*/
/**
 *
 */
function viewImage() {
		var target = this.getAttribute("target");
		var imageSrc = this.getAttribute("href");
		var idImg = "owImageContainer";
		var elTarget = document.getElementById(target);
		if(elTarget) {
			//Check if the tag image already exist
			if(document.getElementById(idImg)) {
				document.getElementById(idImg).setAttribute("src",imageSrc);
			}else{
				var strImage = '<img src="'+ imageSrc + '" border="0" id="'+ idImg + '">';
				elTarget.innerHTML = strImage;
			};
		};
		return false;
	};
};



/*******************************************
Validator  -
********************************************/
ow.validator = {};

/**
 * Check if an email is well formed
 * @param {string} str
 * @return {boolean} true or false
 */
ow.validator.isEmail = function(str) {
	var re = new RegExp("^[\\w\\.=-]+@[\\w\\.-]+\\.[\\w\\.-]{2,4}$");
	if(re.test(str)) {
		return true;
	}else{
		return false;
	};
};


/*******************************************
Debug  -
********************************************/
ow.debug = {};

/**
 * Get all properties of an object sorted by name
 *
 * @param {object} obj
 * @return {string} a string with the property name and his value
 */
ow.debug.dumpProp = function(obj) {
	var str = "";
	var sorted = [];
	for(var p in obj) {
		sorted.push(p);
	};
	sorted.sort();
	for(var i=0; i <sorted.length; i++) {
		str += sorted[i] + ': ' + obj[i] + '\n';
	};
	return str;
};

/**
 * Calculate the elapsed time
 * @constructor
 */
ow.debug.Timer = function() {
	this.timeStart = new Date();

	/**
	 * Return the time in seconds elapsed from the object creation
	 * @type number
	 */
	this.getElapsedTime = function() {
		var timeStop = new Date();
		var elapsedTime = (timeStop  - this.timeStart)/1000;
		return elapsedTime;
	};
};

/*******************************************
XML - Specific funtion to work with XML
*******************************************/
ow.xml = {};


ow.xml.domParser = function(str){
	//Internet Explorer
	try {
  		var xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
  		xmlDoc.async="false";
  		xmlDoc.loadXML(str);
  	}catch(e){
  		//Firefox, Mozilla, Opera, etc.
  		try {
    		var parser=new DOMParser();
    		var xmlDoc=parser.parseFromString(str,"text/xml");
    	}catch(e) {
    		//rethrow
    		throw(e);
    	};
  	};

  	return xmlDoc;
};



/**
 * Get the children elements that have the nodeValue matching the argument value
 *
 * @param {Object} doc
 * @param {string} parentElement
 * @param {string} childElement
 * @param {string} value
 * @return {array} an array with all children xml elements
 */
ow.xml.getElementByNodeValue = function(doc, parentElement, childElement , value) {
	var res = [];
	var el = doc.getElementsByTagName(parentElement);
	var elChild;
	for(var i=0;i<el.length;i++) {
		elChild = el[i].getElementsByTagName(childElement);
		for(var j=0;j<elChild.length;j++) {
			if(elChild[j].firstChild.nodeValue == value){
				res.push(el[i]);
				break;
			};

		};
	};
	return res;
};

/**
 * Get the node value of the first element
 * @param {Object} domDoc
 * @param {string} tagName
 * @return{string || false} the content of the node
 */
ow.xml.getElementValue = function(domDoc, tagName) {
	if(!domDoc) {return false;}
	var el = domDoc.getElementsByTagName(tagName).item(0);
	if(el && el.hasChildNodes()) {
		return el.firstChild.nodeValue;
	}else{
		return false;
	};
};


/********************************************
Moz  - Firefox specific functions
********************************************/
ow.moz = {};

/********************************************
Misc  -
********************************************/
ow.misc = {};

/********************************************
Console  - Wrapper around firebug console
********************************************/
ow.console = {};

/**
 * Write to the firebug console or to a simple debug panel in Internet Explorer
 * @param {Object} obj an object or a string
 */
ow.console.log = function(obj){
	if(!ow.conf.debugEnabled || !console) {return;};
	console.log(obj);
};

/**
 * Writes a message to the firebug console (when enabled)
 * with the visual "info" icon
 * @param {Object} obj an object or a string
 */
ow.console.info = function(obj){
	if(!ow.conf.debugEnabled || !console) {return;};
	console.info(obj);
};

/**
 * Writes a message to the firebug console (when enabled)
 * with the visual "warning" icon
 * @param {Object} obj an object or a string
 */
ow.console.warn = function(obj){
	if(!ow.conf.debugEnabled || !console) {return;};
	console.warn(obj);
};

/**
 * Writes a message to the firebug console (when enabled)
 * with the visual "error" icon
 * @param {Object} obj an object or a string
 */
ow.console.error = function(obj){
	if(!ow.conf.debugEnabled || !console) {return;}
	console.error(obj);
};
