var v_browserDetector = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0; i<data.length; i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
v_browserDetector.init();

/*
*	Dimensions and Offset getters
*/

function f_getTagDimensions ( v_tag ) {

	var v_tag, v_dimensions = [];
	
	v_tag = typeof ( v_tag ) == 'string' ? _d_g ( v_tag ) : v_tag;
	
	v_dimensions['v_height'] = v_tag.offsetHeight;
	v_dimensions['v_width'] = v_tag.offsetWidth;
	v_dimensions['v_x'] = 0;
	v_dimensions['v_y'] = 0;
	
	if ( v_tag.offsetParent ) {
	
		v_dimensions['v_x'] = v_tag.offsetLeft;
		v_dimensions['v_y'] = v_tag.offsetTop;
		
		while ( v_tag = v_tag.offsetParent ) {
		
			v_dimensions['v_x'] += v_tag.offsetLeft;
			v_dimensions['v_y'] += v_tag.offsetTop;
			
		}
		
	}
	
	return v_dimensions;

}

/*
*	Standard functions
*/

function f__isEmail(_0){
	var o=/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	//var o=/^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
	
	return(o.test(_0));
}
/*
function f_isEmail ( v_emailString ) {
	
	return false;
	
}
*/
function f_isEmpty ( v_tag ) {
	
	var v_ref;
	
	v_ref = typeof ( v_tag ) == 'string' ? _d_g ( v_tag ) : v_tag;
	
	return ( v_ref.value == '' ) ? true : false;
	
}
function f_areEmpty ( v_array ) {
	
	var v_i;
	
	for ( v_i = 0; v_i < v_array.length; v_i ++ ) {
		
		if ( _d_g ( v_array[v_i] ).value.length == 0 ) {
			
			return true;	
			
		}
		
	}
	
	return false;
	
}
function f_urlencode ( v_text ) {
	
	var v_newText = v_text;
	
	v_newText = v_newText.replace ( /&/gi, '%26' );
	
	return v_newText;
	
}
function f_urlencodeArray ( v_array ) {
	
	var v_output = '';
	
	for ( var v_i in v_array ) {
		
		v_output += v_i + '=' + f_urlencode ( v_array[v_i] ) + '&';	
		
	}
	
	return v_output;
	
}

/*
*	Setting form defaults
*/

var v_formElementDefaults = [];

function f_initializeFormDefault ( v_formElementID, v_defaultValue, v_defaultStyles ) {
	
	var v_ref = typeof ( v_formElementID ) == 'string' ? _d_g ( v_formElementID ) : v_formElementID;
	
	if ( v_ref ) {
		
		if ( !v_formElementDefaults[v_formElementID] ) {
			
			v_formElementDefaults[v_formElementID] = [];
			
		}
		
		if ( !v_defaultValue ) {
			
			v_defaultValue = '';	
			
		}
		
		v_formElementDefaults[v_formElementID]['v_defaultNode'] = v_ref;
		v_formElementDefaults[v_formElementID]['v_defaultValue'] = v_defaultValue;
		v_formElementDefaults[v_formElementID]['v_styles'] = [];
		v_formElementDefaults[v_formElementID]['v_type'] = v_ref.type;
		
		if ( v_ref.type == 'password' ) {
			
			v_formElementDefaults[v_formElementID]['v_otherNode'] = _d_c ( 'input' );
			v_formElementDefaults[v_formElementID]['v_otherNode'].id = v_formElementID + '2';
			v_formElementDefaults[v_formElementID]['v_otherNode'].style.width = v_formElementDefaults[v_formElementID]['v_defaultNode'].style.width;
			v_formElementDefaults[v_formElementID]['v_otherNode'].style.color = '#333';
			v_formElementDefaults[v_formElementID]['v_otherNode'].style.fontStyle = 'italic';
			v_formElementDefaults[v_formElementID]['v_defaultNode'].style.display = 'none';
			v_ref.parentNode.appendChild ( v_formElementDefaults[v_formElementID]['v_otherNode'] );
			v_formElementDefaults[v_formElementID]['v_otherNode'].value = v_defaultValue;
			
			v_formElementDefaults[v_formElementID]['v_otherNode'].onfocus = function () {
				
				v_formElementDefaults[v_formElementID]['v_otherNode'].style.display = 'none';
				v_formElementDefaults[v_formElementID]['v_defaultNode'].style.display = 'inline';
				v_formElementDefaults[v_formElementID]['v_defaultNode'].focus ();
				
			}
			
		}
	
		if ( !v_defaultStyles ) {
			
			v_formElementDefaults[v_formElementID]['v_styles']['color'] = '#333';
			v_formElementDefaults[v_formElementID]['v_styles']['fontStyle'] = 'italic';
			
		}
		else {
			
			for ( v_i in v_defaultStyles ) {
				
				v_formElementDefaults[v_formElementID]['v_styles'][v_i] = v_defaultStyles[v_i];
				
			}
			
		}
		
		v_ref.onfocus = function () {
			
			f_toggleFormDefault ( this, true );
			
		}
		
		v_ref.onblur = function () {
			
			f_toggleFormDefault ( this, false );
			
		}
		
		f_toggleFormDefault ( v_ref, false );
		
	}
	
}
function f_toggleFormDefault ( v_formElement, v_toggle ) {
	
	var v_i;
	
	if ( v_formElement && v_formElementDefaults[v_formElement.id] ) {
		
		if ( v_formElementDefaults[v_formElement.id]['v_defaultValue'] && v_formElementDefaults[v_formElement.id]['v_styles'] ) {
		
			if ( v_toggle ) {
				
				if ( v_formElement.value == v_formElementDefaults[v_formElement.id]['v_defaultValue'] ) {
					
					for ( v_i in v_formElementDefaults[v_formElement.id]['v_styles'] ) {
						
						v_formElement.style[v_i] = 	'';
					
					}
				
					v_formElement.value = '';
					
				}
				
			}
			else {
			
				if ( v_formElement.value == '' || v_formElement.value == v_formElementDefaults[v_formElement.id]['v_defaultValue'] ) {
					
					if ( v_formElement.type == 'password' ) {
						
						v_formElementDefaults[v_formElement.id]['v_otherNode'].style.display = 'inline';
						v_formElementDefaults[v_formElement.id]['v_defaultNode'].style.display = 'none';
						
					}
					else {
						
						v_formElement.value = v_formElementDefaults[v_formElement.id]['v_defaultValue'];
				
						for ( v_i in v_formElementDefaults[v_formElement.id]['v_styles'] ) {
						
							v_formElement.style[v_i] = 	v_formElementDefaults[v_formElement.id]['v_styles'][v_i];
					
						}
						
					}
					
				}
				
			}
			
		}
		
	}
	
}

/*
*	Shortcuts
*/

function _d_g(x){return document.getElementById(x);}
function _a(x){alert (x);}
function _c(x){return confirm(x);}
function _d_c(x){return document.createElement(x);}

/*
*	Ajax functions
*/

var v_XMLHttpFactories=[function(){return new XMLHttpRequest()},function(){return new ActiveXObject('Msxml2.XMLHTTP')},function(){return new ActiveXObject('Msxml3.XMLHTTP')},function(){return new ActiveXObject('Microsoft.XMLHTTP')}];
function f_sendRequest ( v_url, v_callback, v_postData ) {
	
	var v_httpRequest = f_createXMLHTTPObject ();
	
	if ( !v_httpRequest ) { return; }
	
	var v_method = ( v_postData ) ? "POST" : "GET";
	
	v_httpRequest.open ( v_method, v_url, true );
	
	v_httpRequest.setRequestHeader ( 'User-Agent','XMLHTTP/1.0' );
	
	if( v_postData ) {
		
		v_httpRequest.setRequestHeader( 'Content-type','application/x-www-form-urlencoded' );
		
	}
		
	v_httpRequest.onreadystatechange = function () {
		
		if( v_httpRequest.readyState != 4 ) { return; }
		
		if( v_httpRequest.status != 200 && v_httpRequest.status != 304 ) {
			
			return;
			
		}
		
		eval ( v_callback + '( v_httpRequest );' );
		
	}
	
	if ( v_httpRequest.readyState == 4 ) { return; }
	
	v_httpRequest.send ( v_postData );
	
}
function f_createXMLHTTPObject () {
	
	var v_xmlhttp = false;
	
	for ( var v_i = 0; v_i < v_XMLHttpFactories.length; v_i ++ ) {
		
		try {
			
			v_xmlhttp = v_XMLHttpFactories[v_i] ();
			
		}
		catch ( v_e ) {
			
			continue;
			
		}
		
		break;
		
	}
	
	return v_xmlhttp;
	
}

/*
*	Cookie functions
*/

function f_createCookie ( v_name, v_value, v_days ) {
	
	var v_date, v_expires;
	
	if ( v_days ) {
		
		v_date = new Date();
		v_date.setTime ( v_date.getTime () + ( v_days * 24 * 60 * 60 * 1000 ) );
		v_expires = '; expires=' + v_date.toGMTString ();
	}
	else {
		
		v_expires = '';
		
	}
	
	document.cookie = v_name + '=' + v_value + v_expires + '; path=/';
	
}
function f_readCookie ( v_name ) {
	
	var v_nameEQ, v_ca, c, v_i;
	
	v_nameEQ = v_name + '=';
	
	v_ca = document.cookie.split(';');
	
	for ( v_i = 0; v_i < v_ca.length; v_i ++ ) {
		
		v_c = v_ca[v_i];
		
		while ( v_c.charAt ( 0 ) == ' ' ) {
			
			v_c = v_c.substring ( 1, v_c.length );
			
		}
		
		if ( v_c.indexOf ( v_nameEQ ) == 0 ) {
			
			return v_c.substring ( v_nameEQ.length, v_c.length );
			
		}
		
	}
	
	return null;
	
}
function f_eraseCookie ( v_name ) {
	
	f_createCookie ( v_name, '', -1 );
	
}

/*
*	Portalux Functions
*/

function f_convertPortaluxXML2Array ( v_xmlDoc ) {
	
	var v_results = new Array ();
	
	for ( v_i = 0; v_i < v_xmlDoc.childNodes.length; v_i ++ ) {
		
		if ( v_xmlDoc.childNodes[v_i].nodeName == 'v_data' ) {
			
			v_results['v_data'] = new Array ();
			
			var v_dataNode = v_xmlDoc.childNodes[v_i];
			
			for ( v_j = 0; v_j < v_dataNode.childNodes.length; v_j ++ ) {
				
				if ( v_dataNode.childNodes[v_j].nodeName == 'node' ) {
					
					v_newNode = new Array ();
					v_itemNode = v_dataNode.childNodes[v_j];
					
					for ( v_k = 0; v_k < v_itemNode.childNodes.length; v_k ++ ) {
						
						if ( v_itemNode.childNodes[v_k].nodeName == 'node' ) {
							
							v_newNode[v_itemNode.childNodes[v_k].getAttribute ( 'name' )] = v_itemNode.childNodes[v_k].childNodes[0].nodeValue;
							
						}
						
					}
					
					v_results['v_data'].push ( v_newNode );
					
				}
				
			}
			
			
		}
		else if ( v_xmlDoc.childNodes[v_i].nodeName == 'v_photos' ) {
			
			
			
		}
		
	}
	
	return v_results;
	
}