// JavaScript Document

/*
// ********************************************
// Copyright (c) 2001/2009 by Marcelo Soler
// GRAMAestudio.com - Cinexia, Corp.
// www.marcelosoler.com
// Date:			2006-10-10 | 2009-04-14
// Project:		Barnaba & Cía. SRL
// Module: 		Pages
// Codename: 	2009 Revamp
// Script: 		before.php
// Version: 	3.1.0
// ********************************************
*/

// Show/Hide element by ID
function popUpObj(objectID) {
	thisObj = document.getElementById(objectID).style 
	if (thisObj.display == "block") { 
		thisObj.display = "none"
	} else {
		thisObj.display = "block"
	}
}

// Form validation
// Alert messages
// Warn users on required fields
function check_valid(thisform){
var isvalid = true;
	if(thisform.name.value.length < 4 || thisform.name.value == "Escriba su nombre"){
		// Name must be at least 4 chars long
		alert("Por favor, ingrese su nombre");
		isvalid = false
		thisform.name.focus();
	}
	if(isvalid){
		if (	thisform.email.value.indexOf("@")==-1 || 
				thisform.email.value.indexOf(".")==-1 ||  
				thisform.email.value.indexOf(" ")!=-1 || 
				thisform.email.value.length < 6){
			// email format must be valid
			alert("Por favor, ingrese su dirección de email con un formato válido");
			isvalid = false
			thisform.email.focus();
    	}
	}			
	if(isvalid){
		if(thisform.message.value.length < 4){
		// Message must be at least 4 chars long
		alert("Por favor, escriba su mensaje o consulta");
		isvalid = false
		thisform.message.focus();
		}
	}
return isvalid;
}

// Form validator v.1beta
function validateThis() {
// validateThis (field name, form, process command, , comparison value,  => 5 args by field
//					  [field name, form, process command, form, comparison value])
	var	i,				// Counter
			p,				// indexOf
			q,				// indexOf
			r,				// indexOf
			s,				// indexOf
			nm,			// Field name
			test,			// Test var
			num,			// Number
			minim,		// Min value
			maxim,		// Max value
			foc,			// Where we do focus
			errors='',	// Errors string
			args = validateThis.arguments;
			
	for (i = 0; i < (args.length-4); i += 5) { 
		test = args[i+2];											// Field kind
		val= findObject(args[i]);								// Argument object (field)
		if (val) { 													// If field exists
			nm = 'El campo "' + args[i+4] + '"';			// Field label
			if ((val = val.value) !="") {					// If field not empty
				if(val == args[i+3]) {							// Not default
					errors += '- '+ nm +' debe completarse obligatoriamente.\n';
				}
				if (test.indexOf('isemail')!=-1) {			// Field isEmail and > xx.xxx
					p = val.indexOf('@');
					q = val.indexOf('.');
					r = val.indexOf(' ');
					if (p < 1 
						 	|| p == (val.length-1)
							|| q < 1 
							|| q == (val.length-1)
							|| r > 0
							|| val.length < 6) {								// Not a valid email address
						errors += '- '+ nm +' debe contener una dirección de email válida.\n';
					}
				} else if (test == 'N') { 						// Field is a 'N'umber
					num = parseFloat(val);						// Parse val value to float
					if (isNaN(val)) {							// Not a number
						errors += '- '+ nm +' debe contener un número.\n';
					}
					if (test.indexOf('inRange') != -1) {  // inRange required
						p = test.indexOf(':');					// Split
						minim = test.substring(8, p);			// Min value
						maxim = test.substring(p + 1);		// Max value
						if (num < minim || maxim < num) {	// Out of range
							errors += '- '+ nm +' debe contener un número entre '+ minim +' y '+ maxim +'.\n';
						}
					}
				}
			} else if (test.charAt(0) == 'R')	{				// Field R(equired) ie 'RisEmail'
				errors += '- '+ nm +' debe completarse obligatoriamente.\n';
			}
			if (errors) {
				alert('Atención:\n'+errors);
				document.returnValue = (errors == '');
				break;
			}
		} 
	}
	document.returnValue = (errors == '');
}

//
function findObject (n, d) {
  var p,i,x;
  if(!d) d = document;
  if((p = n.indexOf("?")) > 0 && parent.frames.length) { // Must not occur...
	  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 = findObj(n,d.layers[i].document);
  }
  if(!x && d.getElementById) {
	  x = d.getElementById(n);
  }
  return x;
}
// Resize "content" up to window's size
function setContentHeight() {
	if (resize) {
		// Fixed for IE
		var winW = 0, winH = 0;
		if (parseInt(navigator.appVersion) > 3) {
			document.getElementById("content").style.width = "565px";
			document.getElementById("goUp").style.width = "582px";
  			if( typeof( window.innerWidth ) == 'number' ) {
				//Not IE
    			//winW = window.innerWidth;
    			winH = window.innerHeight;
  			} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    			//IE 6+ in 'standards compliant mode'
    			//winW = document.documentElement.clientWidth;
    			winH = document.documentElement.clientHeight;
				document.getElementById("content").style.width = "570px";
				document.getElementById("goUp").style.width = "587px";
  			} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    			//IE 4 compatible
    			//winW = document.body.clientWidth;
    			winH = document.body.clientHeight;
  			}
			hei = winH - 240;
			document.getElementById("content").style.overflow = "auto";
			document.getElementById("content").style.height = hei+"px";
		}
	} else {
		/*document.getElementById("content").style.height = "auto";*/
		document.getElementById("content").style.width = "550px";
		document.getElementById("goUp").style.width = "550px";
	}
}

function setContentWidth() {
	if (parseInt(navigator.appVersion) > 3) {
		document.getElementById("section").style.width = "968px";
		document.getElementById("content").style.width = "968px";
		document.getElementById("footer").style.width = "968px";
	}
}


function allowResize(resizer) {
	resize = resizer;
	return true;
}

//window.onresize = setContentHeight;

//setTimeout('setContentHeight();', 0);
//setInterval('setContentHeight();', 5);

var resize = false;
