var X = 0;

var Y = 0;

function makeArray(IntarrSize) {

  for (var n = 0; n < IntarrSize; n++)
    this[n] = "";

  return this;

}

var script = {

    $doc : function ( divId )
    {
              return document.getElementById(divId);
    } ,

    camposForm : function(oForm)
    {
		       var aParams = new Array();

    	       for (var i=0 ; i < oForm.length; i++)
               {
                   var sParam = oForm[i].id;
			       sParam += "=";
			       sParam += oForm[i].value;
			       aParams.push(sParam);
		        }
		        return aParams.join("&");
	} ,

	isEmail: function (argvalue)
    {

             if (argvalue.indexOf(" ") != -1)
                return false;
             else
                 if (argvalue.indexOf("@") == -1)
                    return false;
                 else
                     if (argvalue.indexOf("@") == 0)
                        return false;
                     else
                         if (argvalue.indexOf("@") == (argvalue.length-1))
                            return false;

             // arrayString = argvalue.split("@"); (works only in netscape3 and above.)

             var retSize = this.customSplit(argvalue , '@' , 'arrayString');

             if (arrayString[1].indexOf('.') == -1)
                return false;
             else
                 if (arrayString[1].indexOf(".") == 0)
                    return false;
                 else
                     if (arrayString[1].charAt(arrayString[1].length-1) == '.')
                     {
                        return false;
                     }

             return true;

    } ,

    customSplit : function (strvalue, separator, arrayName)
    {
                var n = 0;

                if (separator.length != 0)
                {
                   while (strvalue.indexOf(separator) != -1)
                   {
                         eval("arr"+n+" = strvalue.substring(0, strvalue.indexOf(separator));");
                         strvalue = strvalue.substring(strvalue.indexOf(separator)+separator.length,
                         strvalue.length+1);
                         n++;
                   }
                   eval('arr' + n + ' = strvalue;');
                   arraySize = n+1;
                }

                else
                {
                    for (var x = 0; x < strvalue.length; x++)
                    {
                        eval('arr' + n + ' = "' + strvalue.substring( x , x + 1 ) + '";');
                        n++;
                    }
                    arraySize = n;
                }

                eval(arrayName + ' = new makeArray(arraySize);');

                for (var i = 0; i < arraySize; i++)
                {
                    eval(arrayName + '[' + i + '] = arr' + i + ';');
                }

                return arraySize;
     } ,

    darkened : function ( param )
	{
             var divId = 'escurecer';

             if ( param == 'true' )
             {

                funcao = 'script.$doc(\'mensagem_final\').style.visibility = \'visible\'';

                this.$doc(divId).style.visibility = 'visible';

                efeitos.mostra ( divId , 0 , funcao);
             }
    } ,

    mostrar : function ( param )
    {
            this.$doc( param ).style.visibility = 'visible';
    } ,
    
    esconder : function ( param )
    {
            this.$doc( param ).style.visibility = 'hidden';
    } ,
    movimentoMouse : function (evento) {

	               evento = evento || window.event;

	               mousePos = script.coordenacaoMouse(evento);

	               X = mousePos.x;

	               Y = mousePos.y;
    } ,

    coordenacaoMouse : function (evento)
    {
	                 if (evento.pageX || evento.pageY)
                     {
		                return {x:evento.pageX, y:evento.pageY};
	                 }
                     return {
		                    x:evento.clientX + document.documentElement.scrollLeft ,
		                    y:evento.clientY + document.documentElement.scrollTop
	                 };
    }


}

var efeitos = {

	corFundo: function(tabela , id , cor){
		var elem = document.getElementById(tabela);
		elem.rows[id].style.background=cor;
	},

	mostra: function( divId , valor , funcao )
    {

        var elem = script.$doc( divId );

        if (!valor || valor == undefined) valor = 0;

    	if (valor < 70) {

			valor += 10;

            alpha = valor / 100;

            elem.style.MozOpacity = alpha;

            elem.style.filter = 'alpha(opacity=' + valor + ')';

            elem.style.opacity = alpha;

            setTimeout('efeitos.mostra("' + divId + '" , ' + valor + ' , "' + funcao + '")' , 20);

		}
		else
		{
            setTimeout ( funcao , 250 );
        }


	} ,

	limpar: function()
    {
           script.$doc('escurecer').style.visibility = 'hidden';
           script.$doc('escurecer').style.filter = 0;
           script.$doc('escurecer').style.opacity = 0;
           script.$doc('mensagem_final').innerHTML = '';
           script.$doc('mensagem_final').style.visibility = 'hidden';

	}



}

/**
 *
 * Pegando X Y do mouse
 *
 */
document.onmousemove = script.movimentoMouse;

