
	Object.extend(Element, {
	  getElementLeftTopPos: function(element) {
		element = $(element);

		var leftPos = 0, topPos = 0;
		if (element.offsetParent){
			while (element.offsetParent){
				leftPos += element.offsetLeft;
				topPos += element.offsetTop;
				element = element.offsetParent;
			}
		}
		else if (element.x && element.y){
			leftPos += element.x;
			topPos += element.y;
		}

		return [leftPos, topPos];
	  }
	});

	Validator.prototype = Object.extend(Validator.prototype, {
		updateField: function(valid, id, error) {
			if(valid == "false") {
				Element.addClassName($(id), "pos_valerror");
				Element.addClassName($(id), "stl_valerror");

				var ValidationMessageleft = Element.getElementLeftTopPos($(id))[0];
				var ValidationMessagetop = Element.getElementLeftTopPos($(id))[1] + 15;

				$('ValidationMessage').innerHTML = error;

				Element.setStyle($('ValidationMessage'), $H({"position" : "absolute", "top" : ValidationMessagetop+"px", "left" : ValidationMessageleft+"px", visibility : "visible"}));
			}

			if(valid == "true") {
				Element.removeClassName($(id), "pos_valerror");
				Element.removeClassName($(id), "stl_valerror");
				Element.removeClassName($(id), "missing");

				Element.setStyle($('ValidationMessage'), $H({visibility : "hidden"}));
			}
		}
	});

	var Validator = new Validator();
	ajaxEngine.registerRequest('validateHandler','/spin.php');
	ajaxEngine.registerAjaxObject('validator', Validator);

	Object.extend(window, {
		getViewportDimensions: function() {
			var height=0, width=0;

			if (self.innerHeight)// all except IE
				height = self.innerHeight;
			else if (document.documentElement && document.documentElement.clientHeight) // IE 6 Strict Mode
				height = document.documentElement.clientHeight;
			else if (document.body) // other IE's
				height = document.body.clientHeight;


			if (self.innerWidth)// all except IE
				width = self.innerWidth;
			else if (document.documentElement && document.documentElement.clientWidth) // IE 6 Strict Mode
				width = document.documentElement.clientWidth;
			else if (document.body) // other IE's
				width = document.body.clientWidth;

			return [width, height];
		}
	});

	Object.extend(window, {
		viewportDimensions: this.getViewportDimensions()
	});

	function screenResolution() {
		pxPerEm = 16.46;

		logoWidth = Element.getStyle(document.getElementsByClassName('pos_logo')[0].getElementsByTagName('img')[0], "width");
		colTwoWidth = Element.getStyle(document.getElementsByClassName('pos_column_two')[0], "width");

		if(logoWidth.match('em'))
			logoWidth = parseFloat(logoWidth.replace("em", "")) * pxPerEm;
		else
			logoWidth = parseFloat(logoWidth.replace("px", ""));

		if(colTwoWidth.match("em"))
			colTwoWidth = parseFloat(colTwoWidth.replace("em", "")) * pxPerEm;
		else
			colTwoWidth = parseFloat(colTwoWidth.replace("px", ""));

		left = (window.viewportDimensions[0] - (logoWidth + colTwoWidth)) / 2;

		colOneWidthToSet = left + logoWidth;
		colThreeWidthToSet = window.viewportDimensions[0] - (colOneWidthToSet + colTwoWidth);

		Element.setStyle(document.getElementsByClassName('pos_column_one')[0], $H({width : colOneWidthToSet + "px"}));
		Element.setStyle(document.getElementsByClassName('pos_column_three')[0], $H({width : colThreeWidthToSet + "px"}));

		if(window.viewportDimensions[0]<=800)
			changeStyleAndImage();
	}

	/*
	 * changeStyleAndImage
	 *
	 * Replaces the images for the 800x600 and 1024x768 ones and changes the style
	 *
	 */
	function changeStyleAndImage() {
		if(document.getElementsByClassName("pos_foto")[0]){
			images = document.getElementsByClassName("pos_foto")[0].getElementsByTagName("img");
			$A(images).each(function(image){
				image.src = image.src.replace(/1024/g, "800");
				Element.setStyle(image, {"float" : "right", "width" : "13.25em"})
			});
		}
	}
