/*
function logOff()
{
	if (confirm("Are you sure you want to log off the system?"))
		location.href='/lars/managerLogin.do?operation=logoff';
}
*/

function canDelete(message)
{
	if (confirm(message + "\nConfirm delete ?"))
		return (true)
	else
		return (false)
}

/***********************************************************************
	This method makes one selection in the text box passed as parameter,
	from START position to the END position.
	IN:
		INPUT: the field text
		START: the position to start the text selection
		END: the position to end the text selection

	OUT: VOID, but makes the selection in the text box passed as parameter.
*/
function setSelectionRange(input, start, end) {
		var range = input.createTextRange();
		range.collapse(true);
		range.moveStart("character", start);
		range.moveEnd("character", end - start);
		range.select();
}			

function FormatNumber(num,decimalNum,bolLeadingZero,bolParens,bolCommas)
/**********************************************************************
	IN:
		NUM - the number to format
		decimalNum - the number of decimal places to format the number to
		bolLeadingZero - true / false - display a leading zero for
										numbers between -1 and 1
		bolParens - true / false - use parenthesis around negative numbers
		bolCommas - put commas as number separators.
 
	RETVAL:
		The formatted number!
 **********************************************************************/
{ 
	if (isNaN(parseInt(num))) return 0;

	var tmpNum = num;
	var iSign = num < 0 ? -1 : 1;		// Get sign of number
	
	// Adjust number so only the specified number of numbers after
	// the decimal point are shown.
	tmpNum *= Math.pow(10, decimalNum);
	tmpNum = Math.round(Math.abs(tmpNum))
	tmpNum /= Math.pow(10, decimalNum);
	tmpNum *= iSign;					// Readjust for sign
	
	// Create a string object to do our formatting on
	var tmpNumStr = new String(tmpNum);
	
	var iComma = tmpNumStr.indexOf(".");
	
	if ((tmpNumStr.length - iComma) == 2 && iComma != -1)
		tmpNumStr = tmpNumStr + "0";
		
	if (iComma == -1) {
		tmpNumStr = tmpNumStr + "."
		for (i=0; i < decimalNum; i++)
			tmpNumStr = tmpNumStr + "0";
	} else {
		for (i=(tmpNumStr.length-iComma); i < decimalNum; i++)
			tmpNumStr = tmpNumStr + "0";
	}

	// See if we need to strip out the leading zero or not.
	if (!bolLeadingZero && num < 1 && num > -1 && num != 0)
		if (num > 0)
			tmpNumStr = tmpNumStr.substring(1,tmpNumStr.length);
		else
			tmpNumStr = "-" + tmpNumStr.substring(2,tmpNumStr.length);

	if (num < 0) tmpNumStr = tmpNumStr.substring(1,tmpNumStr.length);

	// See if we need to put in the commas
	if (bolCommas && (num >= 1000 || num <= -1000))
	{
		var iStart = tmpNumStr.indexOf(".");
		
		if (iStart < 0)
			iStart = tmpNumStr.length;

		iStart -= 3;
		while (iStart >= 1) {
			tmpNumStr = tmpNumStr.substring(0,iStart) + "," + tmpNumStr.substring(iStart, tmpNumStr.length)
			iStart -= 3;
		}
	}

	// See if we need to use parenthesis
	if (num < 0){
		if (tmpNumStr == ''){
			tmpNumStr = 0;
		}else{
			if (bolParens)
				tmpNumStr = "(" + tmpNumStr + ")";
			else
				tmpNumStr = "-" + tmpNumStr;
		}
	}

	return tmpNumStr;		// Return our formatted string!
}

function formatDecimalWhithoutPointsAndCommas(noFormat) {
	/* 
	 * RECEIVE AN INTEGER LIKE 123456789 AND RETURNS IT LIKE 1,234,567.89 
	 * noFormat param needs to be of type number because the signal will be tested.
	 * So the function also returns -1,234,567.89 when receive an integer like -123456789
	 */

	var positive = true;

	if (noFormat < 0) {
		positive = false;
		noFormat = noFormat * -1;
	}

	noFormat = noFormat + '';
	
	var decimal = noFormat.substring(noFormat.length - 2, noFormat.length);
	noFormat = noFormat.substring(0,noFormat.length - 2) + '.' + decimal;

	var inteiro = noFormat.substring(0, noFormat.indexOf('.'));
	var comma = '';
	for (i = 1; i <= inteiro.length; i++) {
		if (i*3 <= inteiro.length) {
			if (comma == '') {
				comma = inteiro.substring(inteiro.length - i*3, inteiro.length - i*3 + 3);
			} else {
				comma = inteiro.substring(inteiro.length - i*3, inteiro.length - i*3 + 3).concat(',' + comma);
			}
		} else {
			if (inteiro.length % 3 != 0) {
				if (comma == '') {
					comma = inteiro.substring(inteiro.length - i*3, inteiro.length - i*3 + 3);
				} else {
					comma = inteiro.substring(inteiro.length - i*3, inteiro.length - i*3 + 3).concat(',' + comma);
				}
			}
			i = inteiro.length;
		}
	}

	if (positive) {
		return comma.concat('.' + decimal);
	} else {
		return '-' + comma.concat('.' + decimal);
	}
	
}

function unformatNumber(valor){
	
	var valor = "" + valor;
	
	if ((valor == "") || (valor == null) || (valor == 'undefined')) { return "0"; }
    resposta = "";

	for (i = 0; i < valor.length; i++) {
		if ((valor.charAt(i) != "(") && (valor.charAt(i) != ")") && (valor.charAt(i) != ","))
            resposta += valor.charAt(i);
    }
	if (valor.charAt(0) == "(") resposta = "-" + resposta;
							 
	return resposta;
}

// These array variables define the navigation structure of the site
var rootprefix = "";
var firstentryhome = 0;
var beforebreadcrumb = "";
var level1 = new Array();
var level2 = new Array();
var level3 = new Array();
var level4 = new Array();

// Helper Functions.  DO NOT TOUCH
function addlevel1(label, link) { level1[level1.length] = [label,link]; }
function addlevel2(label, link) { level2[level2.length] = [label,link]; }
function addlevel3(label, link) { level3[level3.length] = [label,link]; }
function addlevel4(label, link) { level4[level4.length] = [label,link]; }

// Other Global Variables
var uri;
var uridocroot;
var urielements = new Array();

//
// Navigation Functions
//

// buildlevel4
// dir - the current directory hierarchy to search and build
function buildlevel4(dir) {

	var i;
	
	document.write("<tr>\n<td><img src=\"images/spacer.gif\" alt=\" \" longdesc=\"images/spacer.txt\" width=\"10\" height=\"1\" border=\"0\"/></td>\n<td>\n<table width=\"150\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n<td colspan=\"2\">\n<img src=\"images/spacer.gif\" alt=\" \" longdesc=\"images/spacer.txt\" width=\"1\" height=\"3\" border=\"0\"/></td>\n</tr>\n");
	
	// Search the level 4 array for this level of navigation
	for (i=0; i < level4.length; i++)
	{
		// Check if this level 4 navigation element belongs under the level 3
		if( level4[i][1].indexOf(dir) == 0)
		{
		  if (level4[i][1] == uridocroot)
		  {
		  	document.write("<tr>\n<td><img src=\"images/spacer.gif\" alt=\" \" longdesc=\"images/spacer.txt\" width=\"10\" height=\"1\" border=\"0\"/></td>\n<td>\n");
		  	document.write("<div class=\"lnavDivHang\">\n<a href=\""+level3[i][1]+"\" class=\"lnavLinkRed\">" + level3[i][0] + "</a>\n</div>\n</td>\n</tr>");
		  } else {
			document.write("<tr>\n<td><img src=\"images/spacer.gif\" alt=\" \" longdesc=\"images/spacer.txt\" width=\"10\" height=\"1\" border=\"0\"/></td>\n<td>\n");
			document.write("<div class=\"lnavDivHang\">\n<a href=\""+level4[i][1]+"\" class=\"lnavLink\">"+ level4[i][0] + "</a>\n</div>\n</td>\n</tr>\n");
		  }
		}
	}
	document.write("<tr>\n<td colspan=\"2\"><img src=\"images/spacer.gif\" alt=\" \" longdesc=\"images/spacer.txt\" width=\"1\" height=\"3\" border=\"0\"/>\n</td>\n</tr>\n</table>\n</td>\n</tr>");

}

// buildlevel3
// dir - the current directory hierarchy to search and build
function buildlevel3(dir) {

	var i;
	
	document.write("<tr>\n<td><img src=\"images/spacer.gif\" alt=\" \" longdesc=\"images/spacer.txt\" width=\"25\" height=\"1\" border=\"0\"/></td>\n<td>\n<table width=\"150\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n<td colspan=\"2\"><img src=\"images/spacer.gif\" alt=\" \" longdesc=\"images/spacer.txt\" width=\"1\" height=\"3\" border=\"0\"/></td>\n</tr>");
	
	// Search the level 3 array for this level of navigation
	for (i=0; i < level3.length; i++)
	{
		// Check if this level 3 navigation element belongs under the level 2
		if( level3[i][1].indexOf(dir) == 0)
		{
		  // Extract the relative part of this navigation link
		  var navuri = level3[i][1].substr(0,level3[i][1].lastIndexOf("/"));

		  // Break down the rest of the link for this navigation
		  var therest = level3[i][1].substr((dir.length)+1,level3[i][1].length);
		  var togo = therest.split("/");
		  
		  if (level3[i][1] == uridocroot)
		  {
			document.write("<tr>\n<td><img src=\"images/spacer.gif\" alt=\" \" longdesc=\"images/spacer.txt\" width=\"10\" height=\"1\" border=\"0\"/></td>\n<td>\n");
		  	document.write("<div class=\"lnavDivHang\">\n<a href=\""+level3[i][1]+"\" class=\"lnavLinkRed\">" + level3[i][0] + "</a>\n</div>\n</td>\n</tr>\n");
		  	
			if( togo.length > 1 )
			{
		  	  // Show the next level down
			  buildlevel4(navuri);
            		}
		  } else {

			document.write("<tr>\n<td><img src=\"images/spacer.gif\" alt=\" \" longdesc=\"images/spacer.txt\" width=\"10\" height=\"1\" border=\"0\"/></td>\n<td>\n");
			document.write("<div class=\"lnavDivHang\">\n<a href=\""+level3[i][1]+"\" class=\"lnavLink\">"+ level3[i][0] + "</a>\n</div>\n</td>\n</tr>\n");

			// Look to see if we need to build the 4th level navigation for this element
			if( (uridocroot.indexOf(navuri) == 0) && (togo.length > 1) )
			{
				buildlevel4(navuri);
			}

		  }
		}
	}
	document.write("<tr>\n<td colspan=\"2\"><img src=\"images/spacer.gif\" alt=\" \" longdesc=\"images/spacer.txt\" width=\"1\" height=\"3\" border=\"0\"/></td>\n</tr>\n</table>\n</td>\n</tr>\n");
	
}

// buildlevel2
// dir - the current directory hierarchy to search and build
function buildlevel2(dir) {

	var i;

	document.write("<tr>\n<td colspan=\"2\">\n<table width=\"185\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n<td colspan=\"2\">\n<img src=\"images/spacer.gif\" alt=\" \" longdesc=\"images/spacer.txt\" width=\"1\" height=\"1\" border=\"0\"/>\n</td>\n</tr>\n");
	// Search the level 2 array for this level of navigation
	for (i=0; i < level2.length; i++)
	{
		// Extract the relative part of this navigation link
		var navuri = level2[i][1].substr(0,level2[i][1].lastIndexOf("/"));

		// Break down the rest of the link for this navigation
		var therest = level2[i][1].substr((dir.length)+1,level2[i][1].length);
		var togo = therest.split("/");

		// Check if this level 2 navigation element belongs under the current top level
		if(level2[i][1].indexOf(dir) == 0)
		{

		  // Does this entry match the current URI? If so, then show different HTML
		  if (level2[i][1] == uridocroot)
		  {
		  	document.write("<tr>\n<td><img src=\"images/spacer.gif\" alt=\" \" longdesc=\"images/spacer.txt\" width=\"25\" height=\"1\" border=\"0\"/></td>\n<td>\n");
		  	document.write("<div class=\"lnavDivHang\">\n<a href=\""+level2[i][1]+"\" class=\"lnavLinkRed\">" + level2[i][0] + "</a>\n</div>\n</td>\n</tr>");

			if( togo.length > 1 )
			{
			  // Show the next level down
			  buildlevel3(navuri);
			}

		  } else {
		  	document.write("<tr>\n<td width=\"25\"><img src=\"images/spacer.gif\" alt=\" \" longdesc=\"images/spacer.txt\" width=\"25\" height=\"1\" border=\"0\"/></td>\n<td width=\"160\">\n");
			document.write("<div class=\"lnavDivHang\">\n<a href=\""+level2[i][1]+"\" class=\"lnavLink\">"+ level2[i][0] + "</a>\n</div>\n</td>\n</tr>");

			// Look to see if we need to build the 2nd level navigation for this element
			if( (uridocroot.indexOf(navuri) == 0) && (togo.length > 1) )
			{
			  // Show the next level down
			  buildlevel3(navuri);
			}

		  }
		}
	}
	document.write("<tr>\n<td colspan=\"2\"><img src=\"images/spacer.gif\" alt=\" \" longdesc=\"images/spacer.txt\" width=\"1\" height=\"1\" border=\"0\"/>\n</td>\n</tr>\n</table>\n</td>\n</tr>\n");
}

// buildnavigation - Main Navigation Build Function
// l - the current page URL
function buildnavigation(l) {

	// Get the current URL and break it down
	var ldirs = l.split("/");
	var fullrootprefix = "/" + rootprefix + "/";
	var pre = rootprefix.split("/");
	var siteprefix = "http://"+ldirs[2]+"/"+rootprefix+"/";
	uri = l.substr(siteprefix.length,l.length);
	uridocroot = "/" + rootprefix + "/" + uri;
	urielements = uri.split("/");

	document.write("<table width=\"185\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n");

	// Loop through all of the top level navigation elements	
	for (i=0; i < level1.length; i++)
	{
		    
	  // Break down the rest of the link for this navigation
	  var therest = level1[i][1].substr(fullrootprefix.length,level1[i][1].length);
	  var togo = therest.split("/");

  	  // Extract the relative part of this navigation link
  	  var navuri = level1[i][1].substr(0,level1[i][1].lastIndexOf("/"));
      
      	  // Check if this page matches the current Level 1 navigation entry
      	  if (level1[i][1] == uridocroot)
	  {
		document.write("<tr class=\"bgmenucolor05\">\n<td colspan=\"2\"><img src=\"images/spacer.gif\" alt=\" \" longdesc=\"images/spacer.txt\" width=\"185\" height=\"1\" border=\"0\"/></td>\n</tr>\n");
		document.write("<tr class=\"bgmenucolor06\">\n<td><img src=\"images/lnav_arrow_grey.gif\" alt=\" \" width=\"20\" height=\"17\" border=\"0\" align=\"middle\"/>\n</td>\n<td>");
		document.write("<div class=\"lnavDivHang\">\n<a href=\""+level1[i][1]+"\" class=\"lnavLink\">" + level1[i][0] + "</a>\n</div>\n</td>\n</tr>\n");

		if( togo.length > 1 )
		{
		  // Show the next level down
		  buildlevel2(navuri);
		}

	  } else {

		// Look to see if we need to build the 2nd level navigation for this element
		if( (uridocroot.indexOf(navuri) == 0) && (togo.length > 1) )
		{
		  document.write("<tr class=\"bgmenucolor05\">\n<td colspan=\"2\"><img src=\"images/spacer.gif\" alt=\" \" longdesc=\"images/spacer.txt\" width=\"185\" height=\"1\" border=\"0\"/></td>\n</tr>\n");
		  document.write("<tr class=\"bgmenucolor06\">\n<td><img src=\"images/lnav_arrow_grey.gif\" alt=\" \" width=\"20\" height=\"17\" border=\"0\" align=\"middle\"/>\n</td>\n<td>");
		  document.write("<div class=\"lnavDivHang\">\n<a href=\""+level1[i][1]+"\" class=\"lnavLink\">" + level1[i][0] + "</a>\n</div>\n</td>\n</tr>\n");

		  // Show the next level down
		  buildlevel2(navuri);

		} else {
		  document.write("<tr class=\"bgmenucolor05\">\n<td colspan=\"2\"><img src=\"images/spacer.gif\" alt=\" \" longdesc=\"images/spacer.txt\" width=\"185\" height=\"1\" border=\"0\"/></td>\n</tr>\n");
		  document.write("<tr>\n<td valign=\"top\"><img src=\"images/lnav_arrow_red.gif\" alt=\" \" width=\"20\" height=\"17\" border=\"0\" align=\"middle\"/>\n</td>\n<td>");
		  document.write("<div class=\"lnavDivHang\">\n<a href=\""+level1[i][1]+"\" class=\"lnavLink\">"+level1[i][0] + "</a>\n</div>\n</td>\n</tr>");
		}
		
	  }	  	
    	}
	document.write("</table>\n");
}

// buildbread4
// dir - the current directory hierarchy to search and build
function buildbread4(dir) {

	var i;
	
	// Search the level 4 array for this level of navigation
	for (i=0; i < level4.length; i++)
	{
		// Check if this level 4 navigation element belongs under the level 3
		if( level4[i][1].indexOf(dir) == 0)
		{
		  if (level4[i][1] == uridocroot)
		  {
		  	document.write(" &gt; <a href=\""+level3[i][1]+"\" class=\"breadCrumb\">" + level3[i][0] + "</a>");
		  } 
		}
	}

}

// buildbread3
// dir - the current directory hierarchy to search and build
function buildbread3(dir) {

	var i;
	
	// Search the level 3 array for this level of navigation
	for (i=0; i < level3.length; i++)
	{
		// Check if this level 3 navigation element belongs under the level 2
		if( level3[i][1].indexOf(dir) == 0)
		{
		  // Extract the relative part of this navigation link
		  var navuri = level3[i][1].substr(0,level3[i][1].lastIndexOf("/"));

		  // Break down the rest of the link for this navigation
		  var therest = level3[i][1].substr((dir.length)+1,level3[i][1].length);
		  var togo = therest.split("/");
		  
		  if (level3[i][1] == uridocroot)
		  {
		  	document.write(" &gt; <a href=\""+level3[i][1]+"\" class=\"breadCrumb\">" + level3[i][0] + "</a>");
		
		  } else {

			// Look to see if we need to build the 4th level navigation for this element
			if( (uridocroot.indexOf(navuri) == 0) && (togo.length > 1) )
			{
				document.write(" &gt; <a href=\""+level3[i][1]+"\" class=\"breadCrumbLink\">"+ level3[i][0] + "</a>");
				
				// Show the next level down
				buildbread4(navuri);
			}

		  }
		}
	}
	
}

// buildbread2
// dir - the current directory hierarchy to search and build
function buildbread2(dir) {

	var i;

	// Search the level 2 array for this level of navigation
	for (i=0; i < level2.length; i++)
	{
		// Extract the relative part of this navigation link
		var navuri = level2[i][1].substr(0,level2[i][1].lastIndexOf("/"));

		// Break down the rest of the link for this navigation
		var therest = level2[i][1].substr((dir.length)+1,level2[i][1].length);
		var togo = therest.split("/");

		// Check if this level 2 navigation element belongs under the current top level
		if(level2[i][1].indexOf(dir) == 0)
		{

		  // Does this entry match the current URI? If so, then show different HTML
		  if (level2[i][1] == uridocroot)
		  {
		  	document.write(" &gt; <a href=\""+level2[i][1]+"\" class=\"breadCrumb\">" + level2[i][0] + "</a>");

		  } else {

			// Look to see if we need to build the 2nd level navigation for this element
			if( (uridocroot.indexOf(navuri) == 0) && (togo.length > 1) )
			{
			  document.write(" &gt; <a href=\""+level2[i][1]+"\" class=\"breadCrumbLink\">"+ level2[i][0] + "</a>");
			  
			  // Show the next level down
			  buildbread3(navuri);
			}

		  }
		}
	}

}

// buildbreadcrumb - Main Breadcrumb Build Function
// l - the current page URL
function buildbreadcrumb(l) {

	// Get the current URL and break it down
	var ldirs = l.split("/");
	var fullrootprefix = "/" + rootprefix + "/";
	var pre = rootprefix.split("/");
	var siteprefix = "http://"+ldirs[2]+"/"+rootprefix+"/";
	uri = l.substr(siteprefix.length,l.length);
	uridocroot = "/" + rootprefix + "/" + uri;
	urielements = uri.split("/");

	// See if a breadcrumb cookie exists 
	var breadcrumblink = getQueryVariable('breadcrumb');

	// if the cookie wasn't found, then use the navigation array to build the breadcrumb
	if (!breadcrumblink) { 

		// Show any HTML before the breadcrumb
		document.write(beforebreadcrumb);

		// Loop through all of the top level navigation elements	
		for (i=0; i < level1.length; i++)
		{

		  // Break down the rest of the link for this navigation
		  var therest = level1[i][1].substr(fullrootprefix.length,level1[i][1].length);
		  var togo = therest.split("/");

		  // Extract the relative part of this navigation link
		  var navuri = level1[i][1].substr(0,level1[i][1].lastIndexOf("/"));

		  // Check if this page matches the current Level 1 navigation entry
		  if (level1[i][1] == uridocroot)
		  {
			document.write(" &gt; <a href=\""+level1[i][1]+"\" class=\"breadCrumb\">" + level1[i][0] + "</a>");

		  } else {

			// Look to see if we need to build the 2nd level navigation for this element
			if( (uridocroot.indexOf(navuri) == 0) && (togo.length > 1) )
			{
			  document.write(" &gt; <a href=\""+level1[i][1]+"\" class=\"breadCrumbLink\">" + level1[i][0] + "</a>");

			  // Show the next level down
			  buildbread2(navuri);

			} 

		  }	  	
		}
	} else {

		// Show the breadcrumb link pass to this page
		document.write(unescape(breadcrumblink));
	}
}


// URL - this is a string containing the URL of the document to open 
// name - this is a string containing the name of the new window. 
// w - This sets the width of the new window in pixels. 
// h - This sets the height of the new window in pixels. 
// features - this is an optional string 
// (see: http://www.devguru.com/technologies/ecmascript/quickref/win_open.html)

function newWindow(mypage,myname,w,h,features) {
  if(screen.width){
  var winl = (screen.width-w)/2;
  var wint = (screen.height-h)/2;
  }else{winl = 0;wint =0;}
  if (winl < 0) winl = 0;
  if (wint < 0) wint = 0;
  var settings = 'height=' + h + ',';
  settings += 'width=' + w + ',';
  settings += 'top=' + wint + ',';
  settings += 'left=' + winl + ',';
  settings += features;
  win = window.open(mypage,myname,settings);
  win.window.focus();
} 

<!--
// name - name of the cookie
// value - value of the cookie
// [expires] - expiration date of the cookie (defaults to end of current session)
// [path] - path for which the cookie is valid (defaults to path of calling document)
// [domain] - domain for which the cookie is valid (defaults to domain of calling document)
// [secure] - Boolean value indicating if the cookie transmission requires a secure transmission
// * an argument defaults when it is assigned null as a placeholder
// * a null placeholder is not required for trailing omitted arguments

function setCookie(name, value, expires, path, domain, secure) {
var curCookie = name + "=" + escape(value) +
((expires) ? "; expires=" + expires.toGMTString() : "") +
((path) ? "; path=" + path : "") +
((domain) ? "; domain=" + domain : "") +
((secure) ? "; secure" : "");

document.cookie = curCookie;
}

// name - name of the desired cookie
// * return string containing value of specified cookie or null if cookie does not exist

function getCookie(name) {
var dc = document.cookie;
var prefix = name + "=";
var begin = dc.indexOf("; " + prefix);

if (begin == -1) {
begin = dc.indexOf(prefix);
if (begin != 0) return null;
} else
begin += 2;
var end = document.cookie.indexOf(";", begin);
if (end == -1)
end = dc.length;
return unescape(dc.substring(begin + prefix.length, end));
}

// name - name of the cookie
// [path] - path of the cookie (must be same as path used to create cookie)
// [domain] - domain of the cookie (must be same as domain used to create cookie)
// * path and domain default if assigned null or omitted if no explicit argument proceeds

function deleteCookie(name, path, domain) {
if (getCookie(name)) {
document.cookie = name + "=" + 
((path) ? "; path=" + path : "") +
((domain) ? "; domain=" + domain : "") +
"; expires=Thu, 01-Jan-70 00:00:01 GMT";
}
}


function isCookieInDomain(_cookieDomainName,_domain) {
   var d = getCookie(_cookieDomainName);

   return ( -1 != _domain.indexOf(d)) ? 1 : 0;
}


function resetCookie(_refname, _domainname) {
   // See if referrer cookie already exists 
   var referrer = getCookie(_refname);

   // if the cookie wasn't found, then set the cookie
   if (referrer) { 
     if( !isCookieInDomain(_domainname, document.domain)) {
       setCookie(_refname, document.referrer);
       setCookie(_domainname, document.domain);
     } 

   } else {
     setCookie(_refname, document.referrer);
     setCookie(_domainname, document.domain);
   }
}

//resetCookie();

function svcContactForm(_refname, _svltUrl, _form) {
   _form.pageref.value = getCookie(_refname);
   _form.domain.value = document.domain;
   //eval(_form+".submit()");
   _form.submit();
}


// name - name of the referrer cookie string

function setReferrer(name) {
// See if referrer cookie already exists 
var referrer = getCookie(name);

// if the cookie wasn't found, then set the cookie
if (!referrer) { 
referrer = document.referrer;
setCookie(name, referrer);
}
}

// variable - name of the query string variable to return

function getQueryVariable(variable) {
  var query = window.location.search.substring(1);
  var vars = query.split("&");

  for (var i=0;i<vars.length;i++) {
    var pair = vars[i].split("=");
    if (pair[0] == variable) {
      return pair[1];
    } else {
      return "";
    } //end if
  } //end for
}//end function


function showMsg(msg)
{
	spnMsg.innerHTML = msg;
	show('message');
}

function show(pDiv)
{
	posy = rtnPosY();
	posx = rtnPosX();
	eval(pDiv + ".style.display	= 'block'");
	eval(pDiv + ".style.top			= posy");
	eval(pDiv + ".style.left		= posx+7");
}

function hideDiv(pDiv)
{
	eval(pDiv + ".style.display	= 'none'");
	eval(pDiv + ".style.width		= '1px'");
	eval(pDiv + ".style.heigth		= '1px'");
	eval(pDiv + ".style.top		= '1px'");
}

function rtnPosY(e)
{
	var posy = 0;
	if (!e) var e = window.event;
	if (e.pageX || e.pageY)
	{
		posy = e.pageY;
	}
	else if (e.clientX || e.clientY)
	{
		posy = e.clientY + document.body.scrollTop;
	}
	return posy;
}		

function rtnPosX(e)
{
	var posx = 0;
	if (!e) var e = window.event;
	if (e.pageX || e.pageY)
	{
		posx = e.pageX;
	}
	else if (e.clientX || e.clientY)
	{
		posx = e.clientX + document.body.scrollLeft;
	}
	return posx;
}

/*
	Nome da fun??o: montaCombo
	Objetivo: Utilizada para montar um combo seguindo o valor escolhido por uma outro comboBox
	Parametros:
		arrayName -> array onde cont?m a lista de itens que faram parte do combo Filho
		opt_pai -> nome do objeto Pai dentro do form
		opt_filho -> nome do objeto Filho dentro do form
		vr_padrao_pai -> Valor padr?o do campo pai
		vr_padrao_filho -> Valor padr?o do campo filho
		nm_pai -> Nome dado ao campo Pai
		nm_filho -> Nome dado ao campo Filho

	Exemplos:

		// O Array deve ser montado da seguinte maneira
		// 'IdFilho-IdPai-DsFilho'
		// Separando os campos por ";" e as linhas por ","
		arrayProjeto = new Array('1-1-Teste 1' , '2-1-Teste 2', '3-2-Teste 3');
		// Nesse caso teremos um array onde o Pai de c?digo 1 ter? 2 filhos (1 e 2) e o pai de c?digo 2 ter? apenas 1 filho (3).

		<select name="dpdCliente" onchange="montaCombo(arrayProjeto, document.frmDados.dpdCliente, document.frmDados.dpdProjeto, '1', '3', 'cliente', 'projeto');">
			<option value="1">Teste 1</option>
			<option value="2">Teste 2</option>
		</select>

		<select name="dpdProjeto" onchange="montaCombo(arrayDemanda, document.frmDados.dpdProjeto, document.frmDados.dpdDemanda, '', '', 'projeto', 'demanda')">
			<option value="0">Escolha um cliente primeiro</option>
		</select>
*/

function montaCombo(arrayName, opt_pai, opt_filho, vr_padrao_pai, vr_padrao_filho, nm_pai, nm_filho, aux_chave)
{
	var tempArray 	 = new Array();
	if (opt_pai.toString() == '[object]' || opt_pai.toString() == '[object HTMLSelectElement]') {
		if ( opt_pai.options.selectedIndex == 0 && vr_padrao_pai == '') { 
			var IdPai = "XXX"; 
		} else if (vr_padrao_pai != '') {
			var IdPai = vr_padrao_pai;
		} else { 
			var IdPai = opt_pai.options[opt_pai.selectedIndex].value; 
		}
	}
	else
	{
		var IdPai = "";
		splPai = opt_pai.split(';');
		for (var i=0; i < splPai.length; i++)
		{
			if (eval("" + splPai[i] + ".options.selectedIndex") == 0 ) { IdPai += "XXX"; }
			else { IdPai += eval(splPai[i] + ".options[" + splPai[i] + ".selectedIndex].value"); }
		}
	}

	if (aux_chave != '' && aux_chave != null) {
		IdPai += aux_chave;
	}

	var previousEnd = opt_filho.selectedIndex;

		filhoList = opt_filho.options;
		filhoList.length = 1;

	if (IdPai != 'XXX') {
	
		var n = 0;
		for (var loop=0; loop < arrayName.length; loop++) {
			var linha = arrayName[loop];
			var spl = linha.split(';');
			if (spl[1] == IdPai) {
				tempArray[loop] = spl[0] + ";" + spl[2];
			}
		}
		tempArray.sort();
		count = 1;
		for (var n in tempArray)
		{
			filhoList[count] = new Option(tempArray[count-1]);

			valor = tempArray[count-1].split(";")

			filhoList[count].value = valor[0];
			filhoList[count].text  = valor[1];

			if(valor[0] == vr_padrao_filho) previousEnd = count;
			count++;
		}

		if (count == 1 )
		{
			filhoList[0] = new Option("No records");
			filhoList[0].value = tempArray[""];
		}
		else
		{
			filhoList[0] = new Option("Choose the " + nm_filho);
			filhoList[0].value = tempArray[""];
		}

		if(IdPai == vr_padrao_pai)
		{
			if ( (filhoList.length != 0) && (previousEnd != -1))
				filhoList.selectedIndex = previousEnd;
			else
				filhoList.selectedIndex = 0;
		}
		else
		{
			filhoList.selectedIndex = 0;
		}
	}
	else
	{
		filhoList[0] = new Option("Choose the " + nm_pai + " first");
		filhoList[0].value = tempArray[""];
		filhoList.selectedIndex = 0;
	}
}


function showLayer(layer) {
	browser=navigator.appName;
	if (browser == "Netscape") {
		document.layers[layer].visibility = "show";
	}
	else if (browser == "Microsoft Internet Explorer") {
		document.all[layer].style.visibility = "visible";
	}
}

// Fun??o que fecha as layers
function hideLayer(layer) {
	browser = navigator.appName;
	if (browser == "Netscape") {
		document.layers[layer].visibility = "hide";
	}
	else if (browser == "Microsoft Internet Explorer") {
		document.all[layer].style.visibility = "hidden";
	}
}

function fillWithChar(campo, tamanho, ch, direcao){
	intTamStr = campo.length;
	var strText = campo;
	if(intTamStr<=tamanho){
		var intTam = parseInt(tamanho) - intTamStr;
			for(i=0;i<intTam;i++){
		    	if(direcao=='E')
					strText = ch+strText;
				else
					strText = strText+ch;
			}
	}
	return strText;
}

function isValidValueOnSelect(obj) {
	if (obj.selectedIndex != 0)
		return true;
	else
		return false;
}
function trim(str)
{
   return str.replace(/^\s*|\s*$/g,"");
}

/**
 * DHTML date validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */
// Declaring valid date character, minimum year and maximum year

	var dtCh= "/";
	var minYear=1900;
	var maxYear=2100;

function isInteger(s)
{
	var i;
	for (i = 0; i < s.length; i++)
	{
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag)
{
	var i;
	var returnString = "";
	// Search through string's characters one by one.
	// If character is not in bag, append to returnString.
	for (i = 0; i < s.length; i++)
	{
        	var c = s.charAt(i);
        	if (bag.indexOf(c) == -1) returnString += c;
    	}
	return returnString;
}

function daysInFebruary (year) {
	// February has 29 days in any year evenly divisible by four,
	// EXCEPT for centurial years which are not also divisible by 400.
	return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}

function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
	}
   	return this
}

function isDate(dtStr)
{
	var daysInMonth = DaysArray(12)
	var pos1		= dtStr.indexOf(dtCh)
	var pos2		= dtStr.indexOf(dtCh,pos1+1)
	var strDay		= dtStr.substring(pos1+1,pos2)
	var strMonth	= dtStr.substring(0,pos1)
	var strYear		= dtStr.substring(pos2+1)
	strYr			= strYear

	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++)
	{
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month	= parseInt(strMonth)
	day	= parseInt(strDay)
	year	= parseInt(strYr)
	if (pos1==-1 || pos2==-1) {
		alert("Date format should be : mm/dd/yyyy")
		return false
	}
	if (strMonth.length<1 || month<1 || month>12) {
		alert("Invalid month")
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]) {
		alert("Invalid day")
		return false
	}
	if (strYear.length != 4 || year == 0 || year < minYear || year > maxYear) {
		alert("Invalid year, enter a year between " + minYear + " and " + maxYear)
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false) {
		alert("Invalid Date")
		return false
	}
	return true
}

function fMaskDate(src)
{
	if (((event.keyCode) > 47) && ((event.keyCode) < 58))
	{
		mask = '##/##/####';

		var i = src.value.length;
		var saida = mask.substring(0,1);
		var texto = mask.substring(i);
		if (texto.substring(0,1) != saida)  src.value += texto.substring(0,1);
			
		return(true)
	}
	else return(false)
}

function dateVerifier(field) {
	var date = field.value.split("/");
	var er = /^\d{2}\/\d{2}\/\d{4}$/;
	if (!er.test(field.value)) {
		return false;
	} else if (!(date[0] >= 1 && date[0] <= 12)) {				
		return false;
	} else if (!(date[1] >= 1 && date[1] <= 31)) {
		return false;
	} else if (!(date[2] >= 1900 && date[2] <= 2100)) {
		return false;
	} 
	return true;
}

function moneyVerifier(field) {
	var er = /^(\d{0,3},)*\d{1,3}\.\d{2}$/;
	if (!er.test(field.value)) {
		return false;
	}
	er = /^,/;
	if (er.test(field.value)) {
		return false;
	}
	return true;
}

/*
	----------------------------------------------------------------------------- 
	FUN??O DE FORMATA??O NUM?RICA
	----------------------------------------------------------------------------- 
*/
var DECIMAL		= '.';
var SEPARATOR	= ',';

function tirarZerosEsquerda(STR)
{
	var int		= '0123456789';
	var sAux	= '';
	var i		= 0;

	STR = new String(STR);
	while (i < STR.length)
	{
		pChar = STR.charAt(i);
		if (int.indexOf(pChar) != -1) sAux += STR.charAt(i);
		i++;
	}

	STR		= new String(sAux);
	sAux	= '';
	i		= 0;

	while (i < STR.length)
	{
		if (STR.charAt(i) != '0')
		{
			sAux = STR.substring(i,STR.length)
			i = STR.length;
		}
		i++;
	}
	return  sAux;
}

function keyPressNumber(txtName)
{
    if ((txtName == "") || (txtName == null))
		return false;

    num = "1234567890-";

	if (num.indexOf(txtName) >= 0) return true;
    else return false;
}

function Formatador(campo,tammax,teclapres, casas)
{
	var tecla = teclapres.keyCode; 	// tecla digitada

	if (tecla == 46) return false; // Bloqueia a tecla DELETE
	vr 	= campo.value;	// Define na vari?vel "vr" o conte?do atual do campo solicitado

	// Verifica se foi a tecla digitada foi a de "-" (menos)
	if (tecla == 109 || tecla == 189)
	{
		campo.value = setMinus(vr);	// Define o campo com o sinal de menos
		return false; // retorna false, pois a string "-" n?o ser? inserida
	}

	iMinus	= vr.indexOf('(');			// Verifica se o n?mero atual ? negativo
	vr 		= tirarZerosEsquerda(vr);	// Limpa a string, deixando apenas os n?meros validos
	tam 	= vr.length;				// Seta o tamanho da string na vari?vel

	if (tecla == 8)	{ tam--; }			// Se foi digitada a tecla de backspace diminimos 1 (hum) ao tamanho da string atual
	if (tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105)	{ tam++; }			// Se foi digitada uma tecla diferente do backspace aumentamos 1 (hum) ao tamanho da string atual
	if (tam > tammax) return false;		// Se o tamanho da string ultrapassar o limite definido na fun??o retorna false e n?o permite a digita??o da tecla

	// Se a tecla digitada for um numero ou BACKSPACE realiza a formata??o da string
	if (tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105)
	{
		// Verifica se o n?mero de casas decimais ? maior de 0 e se o tamanho da string ? menor ou igual o n?mero de casas decimais
		if (casas > 0 && tam <= casas)
		{
			// Verifica se o tamanho da string ? igual a quantidade de casas decimais definida
			if (tam == casas) sTmp = '0' + DECIMAL + vr;
			// Verifica se o tamanho da string ? menor que a quantidade de casas decimais definida
			else if (tam < casas)
			{
				sTmp = '0' + DECIMAL;
				for(j=casas; j > tam; j--) 	// Realiza o Loop para inserir a quantidade de zeros ap?s o DECIMAL antes de inserir o n?mero digitado at? o momento
					sTmp += '0';			// Insere zero
				sTmp += vr; 				// Insere o valor ap?s colocar todos os zeros necess?rios
			}
		}
		else	// Caso o tamanho da string seja maior que a quantidade de casas decimais definida
		{
			decimal = vr.substring(tam-casas,tam);	// Define o conte?do valor decimal da string

			inteiro = '';			// Vari?vel inicial do valor inteiro
			i 		= casas + 1;	// Ponto inicial para o Loop que insere os separadores no valor inteiro, definido pelo pr?ximo valor ap?s o conte?do decimal
			count 	= 0;			// Vari?vel usada para inserir o SEPARADOR no valor inteiro
			while (i <= tam)		// Realiza o Loop pelo conte?do inteiro do valor definido
			{
				// Insere o SEPARADOR ao termos um valor inteiro divisil por 3
				if (count==3)
				{
					inteiro = SEPARATOR + inteiro;
					count = 0;	// Zera o valor da vari?vel usada para inserir o SEPARADOR
				}
				pChar 	= vr.substring(tam-i,tam-i+1);	// Caracter atual (do loop)
				inteiro = pChar + inteiro;				// Acrescenta o caractere a vari?vel inteira
				count++;								// Aumenta 1 (um) a vari?vel count
				i++;									// Aumenta 1 (um) a vari?vel i
			}
			if (casas > 0)	sTmp = (inteiro + DECIMAL + decimal);	// Se o n?mero de casas decimais seja maior que zero define o conteudo com o DECIMAL
			else			sTmp = inteiro;							// Se o n?mero de casas decimais seja igual a zero o conte?do final ? igual ao conte?do da vari?vel Inteiro

			if (tecla == 8) sTmp += ' ';	// Se a tecla digitada for o BACKSPACE inserimos um espa?o vazio ao final da string montada pois ele ser? deletado pela a??o do backspace.
		}
		if (iMinus != -1) sTmp = setMinus(sTmp);	// Verifica se o valor inicial era negativo, caso seja insere a formata??o para n?mero negativo
		campo.value = sTmp;							// Define o campo com a String formatada
	}
}

function setMinus(valor)
{
	if (valor.indexOf('(') == -1) // Verifica se o n?mero n?o ? negativo
		return '(' + valor; // Se n?o for negativo, insere o sinal de "-" no in?cio da string
	else // Caso o n?mero j? seja negativo
		return valor.substring(1,valor.length-1); // Retira o sinal de negativo
}

function setFormatMinus(valor)
{
	if (valor.indexOf('(') != -1 && valor.indexOf(')') == -1) // Verifica se o n?mero ? negativo
		return valor.substring(0,valor.length) + ')'; // Se for negativo, insere parent?ses no in?cio e no fim da string
	else	// Caso contr?rio retorna o valor atual do campo
		return valor;
}

function refreshCampo(obj)
{
	obj.value = obj.value;
}

function showWaitMsg() {
	var obj = document.getElementById('dvWait');
	if (obj != null) {
		obj.style.display = 'block';
	}
}
function hideWaitMsg() {
	var obj = document.getElementById('dvWait');
	if (obj != null) {
		obj.style.display = 'none';
	}
}
