// JavaScript Document

var isIE = (navigator.appName == "Microsoft Internet Explorer");
var isIE6 = (navigator.appName == "Microsoft Internet Explorer" && navigator.appVersion.indexOf("MSIE 6.0") != -1);

function randomBigNumber() {
	return new Date().getSeconds() + new Date().getMilliseconds() + Math.random();
}

function isVoid(obj) {
	if (obj != null && typeof obj != 'undefined' && obj != "") return false;
	return true;
}

String.prototype.isWhite = function() {
  if (!isVoid(this)) {
	var value = this.replace(/^\s+/m,'').replace(/\s+$/m,'');
    return (value == '');
  }
  return true;
}

String.prototype.trim = function() {
  if (!isVoid(this)) {
    var value = this.replace(/^\s+/m,'').replace(/\s+$/m,'');
    return value;
  }	
  return null;
}

Array.prototype.haveItem = function(item) {
  for (var i = 0; i < this.length; i++) {
    if (this[i] == item) return true;
  }
  return false;
}

Array.prototype.diffOnce = function(baseArray, checkArray) {
  var colletion = new Array();
  for (var i = 0; i < baseArray.length; i++)
  	if (baseArray.haveItem(checkArray[i])) colletion.push(checkArray[i]);
	
  return colletion;
}

function $radio(radioGrp) {
	for (var i = 0; i< radioGrp.length; i++)
	    if (radioGrp[i].checked) return radioGrp[i].value;
}

function selectOption(campo,valor) {
	for (var i = 0; i < campo.length; i++) {
	    if (campo.options[i].value == valor) campo.options[i].selected = true;
	}
}

function $(id) { 
  try {	return document.getElementById(id);	} 
  catch (e) {	window.status = 'Erro: ' + e;	}
}

function locateParent(evtTarget, query) {
	obj = evtTarget;
	while (obj && obj.tagName != "body") {
		if (obj.id && obj.id == query) return true;
		obj = obj.offsetParent;
	}
	return false;
}

function addStyle(browserLimitation, url) {
	if (browserLimitation == "FF" && isIE()) return false;
	if (browserLimitation == "IE" && !isIE()) return false;
	
	var s = document.createElement("link");
	s.type = "text/css";
	s.rel = "stylesheet";
	
	if (isIE()) s.href = url;
	else s.href = url;
}

function somenteNum(fld,event) {
	var strCheck = '0123456789';
	var whichCode = event.keyCode?event.keyCode:(event.which?event.which:event.charCode);
	if (whichCode == 13) return true;  // Enter
	if (whichCode == 8) return true;  // Delete
	if (whichCode == 9) return true;  // TAB
	key = String.fromCharCode(whichCode);  // Pega valor de keycode
	if (strCheck.indexOf(key) == -1) return false;  // Nao é um valor valido
	return true;
}

function getKey (event) {
	return event?(event.keyCode?event.keyCode:(event.which?event.which:event.charCode)):null;
}