/** Check if an object value's length is less than the length specified and not 0 length **/
function isStrLess(obj, intLength)
{	var intValue = parseInt(intLength);
	var strValue = String(obj.value);
	if (isNaN(intValue))
	{	intValue = 1;
	}
	if ((strValue.length < intValue) && (strValue.length != 0))
	{	return true;
	}
	return false;
}
/** Check if an object value's length is more or equal than the length specified **/
function isStrMore(obj, intLength)
{	var intValue = parseInt(intLength);
	var strValue = String(obj.value);
	if (isNaN(intValue))
	{	intValue = 1;
	}
	if (strValue.length >= intValue)
	{	return true;
	}
	return false;
}
/** Check if an object's value is empty **/
function isEmpty(obj)
{	if ((obj.value == null) || (obj.value == ""))
	{	return true;
	}
	return false;
}
/** Trim away the first few left space characters **/
function trimleft(strString)
{	var strValue = String(strString);
	var strResult = String('');
	var bolSpace = true;
	for (var i=0;i<strValue.length;i++)
	{	if (strValue.charAt(i) != ' ')
		{	bolSpace = false;
		}
		if (bolSpace == false)
		{	strResult = strResult + strValue.charAt(i);
		}
	}
	return strResult;
}
/** Trim away the first few right space characters **/
function trimright(strString)
{	var strValue = String(strString);
	var strResult = String('');
	var bolSpace = true;
	for (var i=(strValue.length-1);i>-1;i--)
	{	if (strValue.charAt(i) != ' ')
		{	bolSpace = false;
		}
		if (bolSpace == false)
		{	strResult = strValue.charAt(i) + strResult;
		}
	}
	return strResult;
}
/** Trim away the first few left and right space characters **/
function trim(strString)
{	var strValue = String(strString);
	var strResult = String('');
	strResult = trimleft(strValue);
	strResult = trimright(strResult);
	return strResult;
}
/** Trim away the first few left ... characters **/
function trimcleft(strString, strChar)
{	var strValue = String(strString);
	var strC = String(strChar);
	var strResult = String('');
	var bolSpace = true;
	for (var i=0;i<strValue.length;i++)
	{	if (strValue.charAt(i) != strC.charAt(0))
		{	bolSpace = false;
		}
		if (bolSpace == false)
		{	strResult = strResult + strValue.charAt(i);
		}
	}
	return strResult;
}

/** Trim away the first few right ... characters **/
function trimcright(strString, strChar)
{	var strValue = String(strString);
	var strC = String(strChar);
	var strResult = String('');
	var bolSpace = true;
	for (var i=(strValue.length-1);i>-1;i--)
	{	if (strValue.charAt(i) != strC.charAt(0))
		{	bolSpace = false;
		}
		if (bolSpace == false)
		{	strResult = strValue.charAt(i) + strResult;
		}
	}
	return strResult;
}
/** Trim away the first few left and right ... characters **/
function trimc(strString, strChar)
{	var strValue = String(strString);
	var strC = String(strChar);
	var strResult = String('');
	strResult = trimcleft(strValue, strC);
	strResult = trimcright(strResult, strC);
	return strResult;
}
/** Replaces all specified character in the value of an object with another character **/
function Replace(obj, strChar1, strChar2)
{	var strString = String(obj.value);
	while (strString.indexOf(strChar1) > 0)
	{	strString = strString.replace(strChar1, strChar2);
	}
	return strString;
}
/** Replaces all specified character in a string with another character **/
function ReplaceStr(str, strChar1, strChar2)
{	var strString = String(str);
	while (strString.indexOf(strChar1) > 0)
	{	strString = strString.replace(strChar1, strChar2);
	}
	return strString;
}
function sReplace(str, strChar1, strChar2)
{	var strString = String(str);
	while (strString.indexOf(strChar1) > 0)
	{	strString = strString.replace(strChar1, strChar2);
	}
	return strString;
}
/** Format the number into the decimal point that you want **/
function formatNumber(num, abs, idx) {
var	formatedNumber; var absNum; var numLen; var dotPos; var extractStr; var tempStr = 0;
	if (num.toString().length < 1) {return "";}
	absNum = Math.floor(parseFloat(num));
	numLen = num.toString().length;
	dotPos = num.toString().indexOf('.') + 1;
	if (dotPos > 0) {
		extractStr = num.toString().substring(dotPos, numLen);
		strLen = extractStr.toString().length;
		strIdx = strLen - 1;
		if (strLen > idx) {
			while (strLen > idx) {
				lastStr = extractStr.toString().substring(strIdx--, strLen--);
				extractStr = extractStr.toString().substring(0, strLen);
				if (lastStr > 4) {
					bfrLen = extractStr.toString().length;
					extractStr = parseInt(extractStr) + 1;
					aftLen = extractStr.toString().length;
					if (aftLen > bfrLen) {
						addedLen = aftLen - bfrLen;
						tempStr = parseInt(tempStr) + parseInt(extractStr.toString().substring(0, addedLen));
						extractStr = extractStr.toString().substring(addedLen, ++bfrLen);
					}
				}
			}
		}
		else {
			loop = idx - strLen;
			for (var i=0; i<loop; i++) {
				extractStr = extractStr + '0';
			}
		}
	}
	else {
		extractStr = '0';
		for (var i=1; i<idx; i++) {
			extractStr = extractStr + '0';
		}
	}
	absNum = parseInt(absNum) + parseInt(tempStr);
	if ((parseFloat(num) < 0) && (num.toString().indexOf('.') > 0) && (num.toString().substring(dotPos, numLen) != "")) {
		absNum = parseFloat(absNum) + 1;
		if (parseInt(absNum) >= 0) {
			absNum = '-' + absNum.toString();
		}
	}
	if (abs > absNum.toString().length) {
		loop = abs - absNum.toString().length;
		for (var i=0; i<loop; i++) {
			absNum = '  ' + absNum.toString();
		}
	}
	formatedNumber = absNum + '.' + extractStr;
	return formatedNumber;
}
/** for checking for the Text area to limit the length of string **/
function checkStr(obj, num) {
	var len = obj.value.length
	if ((len == 1) && (obj.value.substring(0, 1) == " ")) {
		obj.value = ""
		len = 0
	}
	if (len > num) {
		obj.value = obj.value.substring(0, num)
	}
}
/** for limiting the maximum number of characters accepted into a variable. Normally used for textarea **/
function limitMax(obj,num,n){
if(obj.value.length>=num){
obj.value=obj.value.substr(0, num);
}
if(n!=undefined){
nextElement(obj);
}else{}
}
/** for passing the focus to the next element **/
function nextElement(obj)
{	f = obj.form;
num = f.elements.length;
nextnum = 0;
for (i=0;i<num;i++)
{	if (f.elements[i].name==obj.name)
{	nextnum=i+1;
if (nextnum>=num)
{	obj.blur();
return;
}
if (f.elements[nextnum].type!="hidden")
{	i = num;
}
else
{	found=false;
for (t=nextnum;t<num;t++)
{	if (f.elements[t].type!="hidden")
{	nextnum=t;
found=true;
t=num;
}
}
if (found==false)
{ for (c=0;c<nextnum;c++)
{	if (f.elements[c].type!="hidden")
{	nextnum=c;
found=true;
c=num;
}
}
}
}
}
}
f.elements[nextnum].focus();
}
/** Validate e-mail address entered by the user **/
function validEMailFormat(eMailValue) {
var intCount = 0;
var intInnerCount = 0;
var arrTemp = new Array(" ", "'", "\"", "#", "%", "&", ";", "?", ",");
var strMsg = "";
 for (intCount = 0; intCount < arrTemp.length; intCount++) {
  if (eMailValue.indexOf(arrTemp[intCount]) >= 0) {
   for (intInnerCount = 0; intInnerCount < arrTemp.length;
		intInnerCount++) {
    strMsg = strMsg + " " + arrTemp[intInnerCount];
   }
   return false;
  }
 }
 if ((eMailValue.indexOf('@') < 1) || (eMailValue.indexOf('.') < 2) || eMailValue.indexOf('.') > (eMailValue.length-3)) {
  return false;
 }
 /*if ((eMailValue.indexOf('.') - eMailValue.value.indexOf('@')) < 1 ) {
  alert("Invalid E-Mail Format !\nThank You");
  eMailObj.focus();
  return false;
 }*/
 return true;
}
/** find the position of a character or a string within a string **/
function inStr(strString,chrOne,intCount)
{try{
var intCounter=0;
var strValue=String(strString);
if(isNaN(intCount)){intCount = 1;}
if(intCount >= 0) {
for(var i=0; i<strValue.length; i++) {
if(strValue.charAt(i)==chrOne){intCounter++;if(intCounter>=intCount){return i;}}
}
}else{
if(intCount<0){intCount=intCount*-1;}
for(var i=strValue.length; i>=0; i--) {
if(strValue.charAt(i)==chrOne){intCounter++;if(intCounter>=intCount){return i;}}
}
}
}catch(e){}
}
// Validate string to enter only aphanumeric characters
function isValidStr(str) {
  arrTemp = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  for (idx=0; idx<str.length; idx++) {
    if (arrTemp.indexOf(str.substring(idx,idx+1).toUpperCase()) < 0) {
	  return false;
    }
  }
  return true;
}
// uppercase the first character of each letter and lowercase the rest
function initCap(v){
	var splitter = " ";
  var temp = v.split(splitter);
  for (i=0;i<temp.length;i++){
    temp[i] = temp[i].substring(0,1).toUpperCase() + temp[i].substring(1,temp[i].length).toLowerCase()
  }
  v = temp.join(splitter);
  return v;
}
function chkDate(objName, intChange) //intChange=> 0:change value;1:check only;2:return value;3:check value not object 
{	//var strDatestyle = "US"; //United States date style
	var strDatestyle = "EU";  //European date style
	var strDate;
	var strDateArray;
	var strDay;
	var strMonth;
	var strYear;
	var intday;
	var intMonth;
	var intYear;
	var intElementNr;
	var err = 0;
	var datefield = objName;
	var strSeparatorArray = new Array("-"," ","/",".");
	var booFound = false;
	var strMonthArray = new Array(12);
	strMonthArray[0] = "Jan";
	strMonthArray[1] = "Feb";
	strMonthArray[2] = "Mar";
	strMonthArray[3] = "Apr";
	strMonthArray[4] = "May";
	strMonthArray[5] = "Jun";
	strMonthArray[6] = "Jul";
	strMonthArray[7] = "Aug";
	strMonthArray[8] = "Sep";
	strMonthArray[9] = "Oct";
	strMonthArray[10] = "Nov";
	strMonthArray[11] = "Dec";
	if (intChange != 3) {strDate = datefield.value;}
	else {strDate = datefield;}

	//any string present?
	if (strDate.length < 1)
	{	return -1;
	}

	//retrieve or separate the string
	for (intElementNr = 0; intElementNr < strSeparatorArray.length; intElementNr++)
	{	if (strDate.indexOf(strSeparatorArray[intElementNr]) != -1)
		{	strDateArray = strDate.split(strSeparatorArray[intElementNr]);
			if (strDateArray.length != 3)
			{	err = 1;//not complete date
				return err;
			}
			else
			{	strYear = strDateArray[0];
				strMonth = strDateArray[1];
				strDay = strDateArray[2];
			}
			booFound = true;
		}
	}

	//only one continuos string found
	if (booFound == false)
	{	if (strDate.length>5)
		{	strYear = strDate.substr(0,4);
			strMonth = strDate.substr(2, 2);
			strDay = strDate.substr(2);
		}
		else
		{	err = 1;
			return err;//incomplete date
		}
	}

	//if year only 2 characters
	if (strYear.length == 2)
	{	strYear = '20' + strYear;
	}
	else
	{	if (strYear.length != 4)
		{	err = 4;
			return err;
		}
	}
	// US style; date swap
	if (strDatestyle == "US")
	{	strTemp = strDay;
		strDay = strMonth;
		strMonth = strTemp;
	}

	//
	intday = parseInt(strDay, 10);
	if (isNaN(intday))
	{	err = 2;
		return err;//inproper day input
	}

	intMonth = parseInt(strMonth, 10);
	if (isNaN(intMonth))//when month not in number format
	{	for (i = 0;i<12;i++)
		{	if (strMonth.toUpperCase() == strMonthArray[i].toUpperCase())
			{	intMonth = i + 1;
				strMonth = strMonthArray[i];
				i = 12;//?
			}
		}
		if (isNaN(intMonth))//see if any successful conversion to number formated month
		{	err = 3;
			return err;//inproper month input
		}
	}

	intYear = parseInt(strYear, 10);
	if (isNaN(intYear))
	{	err = 4;
		return err;//inproper year input
	}

	//all day, month and year in numeric format at this level

	if (intMonth>12 || intMonth<1)
	{	err = 5;
		return err;//invalid month range
	}

	if ((intMonth == 1 || intMonth == 3 || intMonth == 5 || intMonth == 7 || intMonth == 8 || intMonth == 	10 || intMonth == 12) && (intday > 31 || intday < 1))
	{	err = 6;
		return err;//invalid day range
	}

	if ((intMonth == 4 || intMonth == 6 || intMonth == 9 || intMonth == 11) && (intday > 30 || intday < 	1))
	{	err = 6;
		return err;//invalid day range
	}

	if (intMonth == 2)
	{	if (intday < 1)
		{	err = 6;
			return err;//invalid day range
		}
		if (leapYear(intYear) == true)
		{	if (intday > 29)
			{	err = 6;
				return err;//invalid day range
			}
		}
		else
		{	if (intday > 28)
			{	err = 6;
				return err;//invalid day range
			}
		}
	}

	//done date validating at this level
	
	var temp = String("");
	
	if (intday < 10)
	{	intday = "0" + intday;
	}
	if (strDatestyle == "US")
	{	//temp = strMonthArray[intMonth-1] + "-" + intday+"-" + strYear;
		temp = strYear + "-" + strMonthArray[intMonth-1]+"-" + intday;
	}
	else
	{	temp = strYear + "-" + strMonthArray[intMonth-1] + "-" + intday;
	}
	
	if (intChange == 0)
	{	datefield.value = temp;
		return 0;
	}
	if (intChange == 1)
	{ 	return 0;
	}
	if (intChange == 2)
	{	return temp;
	}
	if (intChange == 3)
	{	return 0;}
}
function dateLessEqual(from, to, intChange) //intChange=> 0:change value;1:check only;2:check value not objeect
{	if (intChange != 2)
	{	var f = chkDate(from, intChange);
		var t = chkDate(to, intChange);
		if ((f == 0) && (t == 0))
		{	if ((Date.parse(Replace(from, "-", " "))) <= (Date.parse(Replace(to, "-", " "))))
			{	return true;
			}
			else
			{	return false;
			}
		}
		return false;
	}
	else
	{	if ((Date.parse(ReplaceStr(from, "-", " "))) <= (Date.parse(ReplaceStr(to, "-", " "))))
		{	return true;
		}
		else
		{	return false;
		}
	}
	
	return false;
}
function wordWrap(){
/******
* wordWrap to firefox for big words
* Creative Commons license * Version: 1.0 - 26/04/2006
* Autor: Micox - N¨¢iron J.C.G - micoxjcg@yahoo.com.br - http://elmicoxcodes.blogspot.com
* Uso: call the function on onload of body element.
* put the class "word-wrap" on elements to wordwrap
*******/
	var larg_total,larg_carac,quant_quebra,pos_quebra;
	var elementos,quem, caracs, texto, display_orig;
	
	elementos = document.getElementsByTagName("span")
	
	for(var i=0; i<elementos.length;i++){
		if(elementos[i].className=="word-wrap"){
			quem = elementos[i];
			
			// remarked by libraryTeam due to causing problem in display
			//quem.innerHTML = String(quem.innerHTML).replace(/ /g,"&#216;")
			texto = String(quem.innerHTML)
			
			quem.innerHTML = " "
			
			display_orig = quem.style.display;
			quem.style.display="block";
			larg_oficial = quem.offsetWidth;
			//alert("oficial: " + larg_oficial)
			//alert("display " + quem.style.display)
			if(!document.all) quem.style.display="table";
			//alert("display " + quem.style.display)
			quem.innerHTML = texto;
			larg_total = quem.offsetWidth;
			//alert("total: " + larg_total)
			
			pos_quebra = 0;
			caracs = texto.length;
			texto = texto.replace(/&#216;/g," ");
			larg_carac = larg_total / caracs;
			if(larg_total>larg_oficial){
				quant_quebra = parseInt(larg_oficial/larg_carac)
				quant_quebra = quant_quebra - (parseInt(quant_quebra/6)) //quanto menor o num, maior a garantia;
				quem.innerHTML = ""
				while(pos_quebra<=caracs){
					quem.innerHTML = quem.innerHTML + texto.substring(pos_quebra,pos_quebra + quant_quebra) + " "
					pos_quebra = pos_quebra + quant_quebra;
				}
			} else{
				quem.innerHTML = texto;
			}//end if do larg_total>larg_oficial
			quem.style.display = display_orig;
		}//end if do word wrap
	}//end for loop dos elementos
}