﻿var isIE = (document.all) ? true : false;
var isDOM = (document.getElementById && !document.all) ? true : false;
function FormatValue(campo,tammax,teclapres) 
{
	var tecla = teclapres.keyCode;
	vr = campo.value;
	vr = vr.replace( "/", "" );
	vr = vr.replace( "/", "" );
	vr = vr.replace( ",", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	tam = vr.length;

	if (tam < tammax && tecla != 8){ tam = vr.length + 1 ; }

	if (tecla == 8 ){	tam = tam - 1 ; }
		
	if ( tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 ){
		if ( tam <= 2 ){ 
			campo.value = vr ; }
		if ( (tam > 2) && (tam <= 5) ){
			campo.value = vr.substr( 0, tam - 2 ) + ',' + vr.substr( tam - 2, tam ) ; }
		if ( (tam >= 6) && (tam <= 8) ){
			campo.value = vr.substr( 0, tam - 5 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ; }
		if ( (tam >= 9) && (tam <= 11) ){
			campo.value = vr.substr( 0, tam - 8 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ; }
		if ( (tam >= 12) && (tam <= 14) ){
			campo.value = vr.substr( 0, tam - 11 ) + '.' + vr.substr( tam - 11, 3 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ; }
		if ( (tam >= 15) && (tam <= 17) ){
			campo.value = vr.substr( 0, tam - 14 ) + '.' + vr.substr( tam - 14, 3 ) + '.' + vr.substr( tam - 11, 3 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ;}
	}
}
function FromatInt(KeyCode)
{
	if (KeyCode >=48 && KeyCode <= 57)
		return true;
	else event.keyCode=false;
}
function GetSelectedItemCombo(combo, text)
{
    if(text)
        return combo.options[combo.selectedIndex].text;
    return combo.options[combo.selectedIndex].value;
}
function SelectItemCombo(combo, valor)
{
    if(valor == -1)
    {
       combo.options[0].selected = true; 
       return true;
    }
    for( i=0 ; i<=combo.options.length-1 ; i++ )
    {
        if ( combo.options[i].value == valor )
        {
            combo.options[i].selected = true;
            return true;
        }
    }
    return false;
}
function OpenPopUp(url, title, width, height) {
    window.open(url,"Inscrição", "menubar=1,resizable=0,status=1,width=560,height=600"); 
}
function MM_openBrWindow(theURL, winName, features) {
    window.open(theURL, winName, features);
}
function trim(stringToTrim) 
{
	return stringToTrim.replace( /^\s+|\s+$/g,"" );
}
String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}
String.prototype.Right = function( t )
{
	var rt = this;
	if( rt.length < t )
		return rt;
	return rt.substr( rt.length-t, t );
}
String.prototype.LTrim = function(c) 
{
    if( !c )
        c = ' ';
	var rt = this;
	while(rt.substring(0,1) == c)
	{
		rt = rt.substring(1, rt.length);
	}
	return rt;
}
function mascara(src, 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);
    }
}
function ChangeImage(imagepath, name, description) {

    document.getElementById("ctl00_ContentPlaceHolder1_imgMain").src = imagepath;
    //document.getElementById("picTitle").innerHTML = name;
    //document.getElementById("picDesc").innerHTML = description;
}
function CreateIframePopImage(returnField, type, folder) {
    ShowDivAll(354);
    var ifrm = document.createElement("iframe");
    ifrm.setAttribute("name", "upLoadImg");
    ifrm.setAttribute("id", "upLoadImg");
    ifrm.setAttribute("src", "iFrameUpLoadImg.aspx?type=" + type + "&returnField=" + returnField + "&folder=" + folder);
    ifrm.style.width = "354px";
    ifrm.style.height = "83px";
    ifrm.frameborder = "0";
    ifrm.frameborder = 'no';
    document.getElementById('divContent').innerHTML = '';
    document.getElementById('divContent').appendChild(ifrm);
}
function ShowDivAll(width) {
    var theWidth, theHeight;
    if (window.innerWidth)
        theWidth = window.innerWidth;
    else if (document.documentElement && document.documentElement.clientWidth)
        theWidth = document.documentElement.clientWidth;
    else if (document.body)
        theWidth = document.body.clientWidth;

    if (window.innerHeight)
        theHeight = window.innerHeight;
    else if (document.documentElement && document.documentElement.clientHeight)
        theHeight = document.documentElement.clientHeight;
    else if (document.body)
        theHeight = document.body.clientHeight;

    document.getElementById('divAll').style.height = theHeight + 'px';
    document.getElementById('divAll').style.width = theWidth + 'px';
    document.getElementById('divContent').style.left = (theWidth / 2) - width / 2 + 'px';

    document.getElementById('divContent').style.top = "120px";
    document.getElementById('divAll').style.display = '';
    document.getElementById('divContent').style.display = '';
}
function HideDivAll() {
    document.getElementById('divAll').style.display = 'none';
    document.getElementById('divContent').style.display = 'none';
}
function ReturnPicture(field, imgName) {
    document.getElementById(field).value = imgName;
    document.getElementById("divContent").removeChild(document.getElementById("divContent").firstChild);
    HideDivAll();
}


/*
    <script type="text/javascript" language="javascript">

    function Verify() {
        if (document.getElementById("ctl00_ContentPlaceHolder1_rbSingle").checked) {
            ShowGroupSingle(1);
            ShowPartner();
        }
        else
            ShowGroupSingle(2);
        
    }
    function SaveName() {
        var spanName = document.getElementById("spListName");
        var spanFunc = document.getElementById("spListFunc");
        var name = document.getElementById("txtNameGroup");
        var mini = document.getElementById("txtMinisterialFunctionGroup");
        var hdList = document.getElementById("ctl00_ContentPlaceHolder1_hdList");
        var hdCount = document.getElementById("ctl00_ContentPlaceHolder1_hdCount");
        
        if (name.value.trim() == "")
            alert("Digite o nome do Participante!");
        else {
            spanName.innerHTML = spanName.innerHTML + name.value + "<br />";
            spanFunc.innerHTML = spanFunc.innerHTML + (mini.value.trim() == "" ? " - " : mini.value) + "<br />";
            
            hdList.value = hdList.value + name.value + "|" + mini.value + ";";
            hdCount.value = hdCount.value + 1;
            
            if (document.getElementById("tbList").style.display == "none") {
                document.getElementById("tbList").style.display = "block";
                document.getElementById("tbList").style.visibility = "visible";
            }
            name.value = '';
            mini.value = '';
        }
    }
    function ShowPartner() {
        if (document.getElementById("ctl00_ContentPlaceHolder1_chkPartner").checked) {
            document.getElementById("tbPartner").style.display = "block";
            document.getElementById("tbPartner").style.visibility = "visible";
        }
        else {
            document.getElementById("tbPartner").style.display = "none";
            document.getElementById("tbPartner").style.visibility = "hidden";
        }
    }
    function ShowGroupSingle(enrolType) {
        document.getElementById("tbPartner").style.display = "none";
        document.getElementById("tbPartner").style.visibility = "hidden";
        if (enrolType == 1) {
            document.getElementById("tbSingle").style.display = "block";
            document.getElementById("tbSingle").style.visibility = "visible";
            document.getElementById("tbGroup").style.display = "none";
            document.getElementById("tbGroup").style.visibility = "hidden";
            if (document.getElementById("ctl00_ContentPlaceHolder1_chkPartner").checked) {
                document.getElementById("tbPartner").style.display = "block";
                document.getElementById("tbPartner").style.visibility = "visible";    
            }
         }
        else {
            document.getElementById("tbSingle").style.display = "none";
            document.getElementById("tbSingle").style.visibility = "hidden";
            document.getElementById("tbGroup").style.display = "block";
            document.getElementById("tbGroup").style.visibility = "visible";
        }
    }
    setTimeout('Verify();', 500);
</script>*/