/***
	This object has sending a data coolection
	of form html
	Author: Luis Pirir
	contact: luispirir@gmail.com
***/

oForms = {

	initializeAjax : function () {
	
		var oHttp = false;

		if ( window.XMLHttpRequest )

			oHttp = new XMLHttpRequest();
		
		else if ( window.ActiveXObject )
		
			oHttp = new ActiveXObject ( 'Microsoft.XMLHTTP' );

		if ( !oHttp ) {

			alert ( "Can't initialize the object" );

			return false;

		}

		return oHttp;

	},

	validate : function (form, url, idDiv) { 
		
		var strMsg = '';

		var oForm = document.getElementById ( form );

		var oElements = oForm.getElementsByTagName ( 'label' );
	
		for (var i = 0; i < oElements.length; i++)
		{

			if (/required/.test(oElements[i].className) && !/email/.test(oElements[i].className))
			{   
						
				if (oElements[i].nextSibling.nextSibling.value == '')
				{
					oElements[i].nextSibling.nextSibling.style.backgroundColor = "#D42C00";
					oElements[i].nextSibling.nextSibling.style.color = "#fff";
					strMsg +=  'Please enter ' + oElements[i].firstChild.nodeValue.toLowerCase() + '\n';
				} else {
						
					oElements[i].nextSibling.nextSibling.style.backgroundColor = "#fff";
					oElements[i].nextSibling.nextSibling.style.color = "#333";

				}

			} else if (/email/.test(oElements[i].className))
				{

					var pattern = new RegExp ('^[a-zA-Z0-9\_-]+\@[a-zA-Z0-9\_-]+\.(com|org|net)$');

					if (!pattern.test(oElements[i].nextSibling.nextSibling.value))
					{
						oElements[i].nextSibling.nextSibling.style.backgroundColor = "#D42C00";
						oElements[i].nextSibling.nextSibling.style.color = "#fff";
						strMsg += 'Please enter a valid e-mail\n';
				
					} else {

						oElements[i].nextSibling.nextSibling.style.backgroundColor = "#fff";
						oElements[i].nextSibling.nextSibling.style.color = "#333";
					
					}

				}

		}

		if ( strMsg )
			
			alert (strMsg);
		
		else 

			oForms.sendForm ( form, url, idDiv );
		

		return false;

	},

	sendForm :  function ( idForm, url, idDiv ) {

		eIndex = url.lastIndexOf('/');

		urlTemp = url.substr(0, eIndex);

		imgTmp = new Image();

		imgTmp.src = urlTemp + '/images/bigrotation.gif';
	
		petition = oForms.initializeAjax();

		var oForm = document.getElementById( idForm );
        var oElements = oForm.getElementsByTagName ( 'label' );
        var strFields = "";
        var sepfields = "";
		
		for (var i = 0; i < oElements.length; i++ ) {
		  
          strFields += sepfields + oElements[i].nextSibling.nextSibling.name + '=' + encodeURI (oElements[i].nextSibling.nextSibling.value);

          sepfields = "&";
		}

		var elDiv = document.getElementById (idDiv);
			
		elDiv.setAttribute('style', 'text-align: center');

		if (elDiv.hasChildNodes())
			
			elDiv.removeChild(oForm);			
			   
		var p = document.createElement('p');

		p.appendChild(document.createTextNode('Please be patient. The message is being sent..'));

		var p2 = document.createElement('p');

		p2.setAttribute('style', 'text-align: center');

		var eImg = document.createElement('img');

		eImg.setAttribute ('src', urlTemp + '/images/bigrotation.gif');
		eImg.setAttribute ('width', '32');
		eImg.setAttribute ('height', '32');
		eImg.setAttribute ('style', 'display: block; margin: auto');

		strFields += '&templateDir=' + urlTemp + '/';

		p2.appendChild (eImg);		

		elDiv.appendChild(p);			   		
		elDiv.appendChild(p2);
		
		petition.open("POST", url, true);
		petition.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=ISO-8859-1');
		petition.onreadystatechange = function () {
		   if (petition.readyState == 4) {

			  elDiv.innerHTML = petition.responseText;

		   }
		 }

		 petition.send (strFields);
	}
}

/**
	Code wich show the viewport dimensions of
	window client
	By Luis Pirir
	Contact luispirir@gmail.com
**/

Client = {

	getViewPortWidth: function () {
		
		return self.innerWidth || ( document.documentElement.clientWidth || document.body.clientWidth );
		
	},
	
	getViewPortHeight: function () {
	
		return self.innerHeight || ( document.documentElement.clientHeight || document.body.clientHeight );
		
	},
	
	getViewPortClientSize: function () {
	
		return [ this.getViewPortWidth(), this.getVierPortHeight() ]			
		
	}
	
}

heightDefault = {

	heightStand : function() { 
		
		return ( Client.getViewPortHeight() - ( document.getElementById('header').offsetHeight + document.getElementById('footer').offsetHeight + document.getElementById('menu_s').offsetHeight + document.getElementById('banner').offsetHeight ) - 30 );
	
	},

	setHeightObject : function() {
	
		element = document.getElementById('container');

		if ( Client.getViewPortHeight() > 480 )
		
			element.style.height = heightDefault.heightStand() + 'px';

	}
	
}

window.onload = function () {

	heightDefault.setHeightObject();

}
