// JScript source code

function trim(inputString) {
   // Removes leading and trailing spaces from the passed string. Also removes
   // consecutive spaces and replaces it with one space. If something besides
   // a string is passed in (null, custom object, etc.) then return the input.
   if (typeof inputString != "string") { return inputString; }
   var retValue = inputString;
   var ch = retValue.substring(0, 1);
   while (ch == " ") { // Check for spaces at the beginning of the string
      retValue = retValue.substring(1, retValue.length);
      ch = retValue.substring(0, 1);
   }
   ch = retValue.substring(retValue.length-1, retValue.length);
   while (ch == " ") { // Check for spaces at the end of the string
      retValue = retValue.substring(0, retValue.length-1);
      ch = retValue.substring(retValue.length-1, retValue.length);
   }
   /*while (retValue.indexOf("  ") != -1) { // Note that there are two spaces in the string - look for multiple spaces within the string
      retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length); // Again, there are two spaces in each of the strings
   }*/
   return retValue; // Return the trimmed string back to the user
} // Ends the "trim" function

function Left(str, n)
{
	if (n <= 0)
	    return "";
	else if (n > String(str).length)
	    return str;
	else
	    return String(str).substring(0,n);
}

function Right(str, n){
    if (n <= 0)
       return "";
    else if (n > String(str).length)
       return str;
    else {
       var iLen = String(str).length;
       return String(str).substring(iLen, iLen - n);
    }
}

function IsNumeric(sText)

{
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;

 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
   
   }
   

  
function VerificaEmail(email)
{
	var VerEmail = false
	var theRest, validateField, strError, x, hasChar
	var nonValid = new Array()
	nonValid[0] = ","
	nonValid[1] = ";"
	nonValid[2] = ":"
	nonValid[3] = "'"
	nonValid[4] = "("
	nonValid[4] = ")"
	nonValid[5] = "`"
	nonValid[6] = "["
	nonValid[7] = "]"
	nonValid[8] = "#"
	nonValid[9] = "="
	nonValid[10] = " "
	nonValid[11] = "*"
	nonValid[12] = "<"
	nonValid[13] = ">"
	nonValid[14] = "?"
	nonValid[15] = "/"
	nonValid[16] = "|"
	nonValid[17] = "$"
	nonValid[18] = "%"
	nonValid[19] = "{"
	nonValid[20] = "}"
	nonValid[21] = "!"
	nonValid[22] = "^"
	nonValid[23] = "ç"
	nonValid[24] = "Ç"
	nonValid[25] = '"'


	if (trim(email.length) == 0)
	{
		return(false)
	}
	
	if (email.indexOf("@") >= 0 && email.indexOf(".") >= 0)
	{
		theRest = Right(email, email.length	- email.indexOf("@") - 1)
		if ((theRest.indexOf("@") >= 0) || (Right(email, 1) == "@") || (Right(email, 1) == ".") || (Left(email, 1) == ".") || (Left(email, 1) == "@") || (email.length > 255))
		{
			return(false)
		}
		else
		{
			x = email.indexOf("@")
			if (x == email.indexOf(".", x + 1) || x == email.indexOf(".", x - 1))
			{
				return(false)
			}
			else if (email.indexOf("..") >= 0)
			{
				return(false)
			}
			else
			{
				for (n=0; n < nonValid.length; n++)
				{
					if (email.indexOf(nonValid[n]) >= 0)
					{
						return(false)
					}
				}
				
				var CrOK = new Array("a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "@", ".", "-", "_")
				for (n=0; n < email.length; n++)
				{
					//alert(email[n])
					sLetra = email.substr(n, 1)
					if (!IsNumeric(sLetra))
					{
						//return(false)
						invalido = true
						for (i = 0; i < CrOK.length; i++)
						{
							if (sLetra.toLowerCase() == CrOK[i].toLowerCase())
							{
								invalido = false
								i = CrOK.length + 1								
							}		
						}
						if (invalido)
						{
							return(false)
						}
					}
				}
			}
		}
	}
	else
	{
		return(false)
	}
	
	return(true)
}

// JScript source code

function isDate(DateToCheck){
if(DateToCheck==""){return true;}
var m_strDate = FormatDate(DateToCheck);
if(m_strDate==""){
return false;
}
var m_arrDate = m_strDate.split("/");
var m_DAY = m_arrDate[0];
var m_MONTH = m_arrDate[1];
var m_YEAR = m_arrDate[2];
if(m_YEAR.length > 4){return false;}
m_strDate = m_MONTH + "/" + m_DAY + "/" + m_YEAR;
var testDate=new Date(m_strDate);
if(testDate.getMonth()+1==m_MONTH){
return true;
} 
else{
return false;
}
}//end function




function FormatDate(DateToFormat,FormatAs){
if(DateToFormat==""){return"";}
if(!FormatAs){FormatAs="dd/mm/yyyy";}

var strReturnDate;
FormatAs = FormatAs.toLowerCase();
DateToFormat = DateToFormat.toLowerCase();
var arrDate
var arrMonths = new Array("January","February","March","April","May","June","July","August","September","October","November","December");
var strMONTH;
var Separator;

while(DateToFormat.indexOf("st")>-1){
DateToFormat = DateToFormat.replace("st","");
}

while(DateToFormat.indexOf("nd")>-1){
DateToFormat = DateToFormat.replace("nd","");
}

while(DateToFormat.indexOf("rd")>-1){
DateToFormat = DateToFormat.replace("rd","");
}

while(DateToFormat.indexOf("th")>-1){
DateToFormat = DateToFormat.replace("th","");
}

if(DateToFormat.indexOf(".")>-1){
Separator = ".";
}

if(DateToFormat.indexOf("-")>-1){
Separator = "-";
}


if(DateToFormat.indexOf("/")>-1){
Separator = "/";
}

if(DateToFormat.indexOf(" ")>-1){
Separator = " ";
}

arrDate = DateToFormat.split(Separator);
DateToFormat = "";
	for(var iSD = 0;iSD < arrDate.length;iSD++){
		if(arrDate[iSD]!=""){
		DateToFormat += arrDate[iSD] + Separator;
		}
	}
DateToFormat = DateToFormat.substring(0,DateToFormat.length-1);
arrDate = DateToFormat.split(Separator);

if(arrDate.length < 3){
return "";
}

var DAY = arrDate[0];
var MONTH = arrDate[1];
var YEAR = arrDate[2];




if(parseFloat(arrDate[1]) > 12){
DAY = arrDate[1];
MONTH = arrDate[0];
}

if(parseFloat(DAY) && DAY.toString().length==4){
YEAR = arrDate[0];
DAY = arrDate[2];
MONTH = arrDate[1];
}


for(var iSD = 0;iSD < arrMonths.length;iSD++){
var ShortMonth = arrMonths[iSD].substring(0,3).toLowerCase();
var MonthPosition = DateToFormat.indexOf(ShortMonth);
	if(MonthPosition > -1){
	MONTH = iSD + 1;
		if(MonthPosition == 0){
		DAY = arrDate[1];
		YEAR = arrDate[2];
		}
	break;
	}
}

var strTemp = YEAR.toString();
if(strTemp.length==2){

	if(parseFloat(YEAR)>40){
	YEAR = "19" + YEAR;
	}
	else{
	YEAR = "20" + YEAR;
	}

}


	if(parseInt(MONTH)< 10 && MONTH.toString().length < 2){
	MONTH = "0" + MONTH;
	}
	if(parseInt(DAY)< 10 && DAY.toString().length < 2){
	DAY = "0" + DAY;
	}
	switch (FormatAs){
	case "dd/mm/yyyy":
	return DAY + "/" + MONTH + "/" + YEAR;
	case "mm/dd/yyyy":
	return MONTH + "/" + DAY + "/" + YEAR;
	case "dd/mmm/yyyy":
	return DAY + " " + arrMonths[MONTH -1].substring(0,3) + " " + YEAR;
	case "mmm/dd/yyyy":
	return arrMonths[MONTH -1].substring(0,3) + " " + DAY + " " + YEAR;
	case "dd/mmmm/yyyy":
	return DAY + " " + arrMonths[MONTH -1] + " " + YEAR;	
	case "mmmm/dd/yyyy":
	return arrMonths[MONTH -1] + " " + DAY + " " + YEAR;
	}

return DAY + "/" + strMONTH + "/" + YEAR;;

} //End Function

function isObject(a, tipo) {
	var coll = document.getElementsByTagName(tipo)
	var sai = false
	
	if (coll!=null)
	{
		//alert(coll.length)
		var i=0
		while (i < coll.length)
		{
			// (coll(i).id)
			if (coll[i].id == a)
			{				
				sai = true
				break
			}		
			i++  
		}
	}
	return(sai)

}