browser = (document.all) ? 'ie': 'ns';

function showErro(szMsg)
{
	alert("Error: " + szMsg);
}

var $ = function(id) 
{
	if(!arguments[1]) return document.getElementById(id);
	else document.getElementById(id).style[arguments[1]] = arguments[2];
}	
function addOptEvent(oElement, szType, oFunction)
{
	if (oElement.addEventListener) 
	{
		oElement.addEventListener (szType,oFunction,false);
	} 
	else if (oElement.attachEvent) 
	{
		oElement.attachEvent ('on'+szType,oFunction)
	} 
	else 
	{
		eval ("oElement."+szType+"= oFunction");
	}
}
function popupWindow (url,target,width,height) 
{
	window.open(url, target,'width='+width+',height='+height+',directories=0,location=0,menubar=0,resizable=1,scrollbars=1,status=0,toolbar=0,marginleft=0,margintop=0,left='+(((screen.width-width)/2)+-10)+',top='+(((screen.height-height)/2)+-30));
}


String.prototype.isValidEmail = function()
{
	var x = this;
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (filter.test(x)) return true; else return false;
}


var checkFormErros = function()
{
	var bErro = 0;
	
	
	for (var i=0;i<aFieldsReq.length;i++)
	{
		if ((aFieldsReq[i].blank != undefined) && (aFieldsReq[i].blank == "N") && (document.getElementById(aFieldsReq[i].field).value == ""))
		{
			aErros[i] = aFieldsReq[i].field;
			bErro = 1;
		}
		else if ((aFieldsReq[i].len != undefined) && (!isNaN(parseInt(aFieldsReq[i].len))) && (document.getElementById(aFieldsReq[i].field).value.length < parseInt(aFieldsReq[i].len)))
		{
			aErros[i] = aFieldsReq[i].field;
			bErro = 1;
		}
		else if ((aFieldsReq[i].func != undefined) && (aFieldsReq[i].func != ""))
		{
			eval ("bFunc = document.getElementById('" + aFieldsReq[i].field + "').value."+aFieldsReq[i].func+"()");
			if (!bFunc)
			{
				aErros[i] = aFieldsReq[i].field;
				bErro = 1;
			}
		}
	}

			return bErro;
	
}

var clearFormFields = function()
{
	for (var i=0;i<aFieldsReq.length;i++)
	{
		if ((document.getElementById("error-"+aFieldsReq[i].field) != null) && (aFieldsReq[numField].erro != undefined))
		{
			document.getElementById("error-"+aFieldsReq[i].field).innerHTML = "";
			document.getElementById("error-"+aFieldsReq[i].field).style.display = "none";
		}
		document.getElementById(aFieldsReq[i].field).style.background = "#FFF";
	}
}

var doFormErros = function()
{
	for (numField in aErros)
	{
		if ((document.getElementById("error-"+aErros[numField]) != null) && (aFieldsReq[numField].erro != undefined))
		{
			document.getElementById("error-"+aErros[numField]).innerHTML = "» " + aFieldsReq[numField].erro;
			document.getElementById("error-"+aErros[numField]).style.display = 'block';
		}
		document.getElementById(aErros[numField]).style.background = "#EEE";
		addOptEvent(document.getElementById(aErros[numField]),"click",clearFormFields);
	}
	aErros = new Array();
	return 1;
}


var getFormElements = function(oForm)
{
	szString = "";
	for (var i=0; i<oForm.elements.length;i++)
	{
		if ((oForm.elements[i].name == undefined) || (oForm.elements[i].name == "")) continue;
		szString += oForm.elements[i].name + "="+oForm.elements[i].value.urlEncode()+"&";
	}
	
	return szString.substr(0,szString.length-1);
}

String.prototype.urlEncode = function() 
{ 
    var hex_chars = "0123456789ABCDEF"; 
    var noEncode = /^([a-zA-Z0-9\_\-\.])$/; 
    var n, strCode, hex1, hex2, strEncode = ""; 

    for(n = 0; n < this.length; n++) { 
        if (noEncode.test(this.charAt(n))) { 
            strEncode += this.charAt(n); 
        } else { 
            strCode = this.charCodeAt(n); 
            hex1 = hex_chars.charAt(Math.floor(strCode / 16)); 
            hex2 = hex_chars.charAt(strCode % 16); 
            strEncode += "%" + (hex1 + hex2); 
        } 
    } 
    return strEncode; 
} 

// url_decode version 1.0 
String.prototype.urlDecode = function() 
{
    var n, strCode, strDecode = ""; 

    for (n = 0; n < this.length; n++) { 
        if (this.charAt(n) == "%") { 
            strCode = this.charAt(n + 1) + this.charAt(n + 2); 
            strDecode += String.fromCharCode(parseInt(strCode, 16)); 
            n += 2; 
        } else { 
            strDecode += this.charAt(n); 
        } 
    } 

    return strDecode; 
}   
