﻿// JScript File

    function AddToFavorites(title, url) 
    { 
        //title = "Liberty Seguros";
        //url = "http://localhost/LibertySeguros.Portal/Default.aspx";
        if (window.sidebar) { 
            // Mozilla Firefox Bookmark		
            window.sidebar.addPanel(title, url,"");	
        } 
        else if( window.external ) 
        { 
            // IE Favorite		
            window.external.AddFavorite( url, title); 
        }	
        else if(window.opera && window.print) 
        { 
            // Opera Hotlist
            return true; 
        } 
    }

	function SelectedValueChanged(objId)
	{
		var objDDL = document.getElementById(objId);
		var objHF = document.getElementById(objId + 'SelectedValue');
		
		objHF.value = objDDL.options[objDDL.selectedIndex].value;
	}

	function UpdateDropDownList(selectedValue, values, object, firstBlank)
	{
		UpdateDropDownList(selectedValue, values, object, firstBlank, "0");
	}

	function UpdateDropDownList(selectedValue, values, object, firstBlank, selectedValue2)
	{
		while(object.options.length > 0)
		{
			object.remove(0);
		}

		//	firstBlank - deverá conter true se quisermos que o 1º item da dropdown fique vazia e false caso contrário
		if(firstBlank)
		{
			var option = document.createElement("option");
			option.value = "";
			option.text = "";

			AddOption(object, option);
		}

		//	values[x][0] - deverá conter o valor que se vai comparar com o selectedValue
		//	values[x][1] - deverá conter o valor que vai para o DataValueField da DropDownList em object
		//	values[x][2] - deverá conter o valor que vai para o DataTextField da DropDownList em object
		for(i=0; i<values.length; i++)
		{
			if(values[i][0] == selectedValue)
			{
				var option = document.createElement("option");
				option.value = values[i][1];
				option.text = values[i][2];
				
				if(option.value == selectedValue2)
					option.selected = true;

				AddOption(object, option);
			}
		}
	}
	
	function AddOption(object, option)
	{
		try
		{
			object.add(option,null); // standards compliant
		}
		catch(ex)
		{
			object.add(option); // IE only
		}
	}
	var currShow;
	
	function showElement(elem)
	{
	    var col = elem.getElementsByTagName("input");
//	    var elemidx = 0;
//	    while(elemidx < col.length)
//	    {
//	        col[elemidx].value = "";
//	        ++elemidx;
//	    }
	    if(currShow != null)
	    {
	        currShow.style.display ="none";
	    }
	    currShow = elem;
	    elem.style.display ="block";
    
	}
	
	function hideElement(elem)
	{
	    currShow = null;
	    elem.style.display ="none";
	}
	
	function resetForm()
	{
	    aspnetForm.reset();
	}
		
	function keepMessage(elem)
	{
	    elem.innerText+=String.fromCharCode(window.event.keyCode);
	    window.event.returnValue = false;
	    return false;
	}
	
	function setNameParam(url, paramName, elem, defValue, ArraylinkElem)
	{
	    
	    if(elem == null)
	        return false;
	    
	    if(elem.value == defValue)
	        return true;
	    
	    var newUrl= (url.split('?'))[0];
        var s1 = (url.split('?'))[1]; 
        var find = -1;
        if (s1.length>0) 
        { 
            var s2 = s1.split('&'); 
            if (s2.length>0) 
            { 
                for (var i=0; i<s2.length; i++) 
                {   
                    var p=s2[i].split('=');
                    
                    if(p[0] == paramName && p[1] !=defValue )
                    {
                        p[1] = elem.value;
                        find = i;
                    }
                }
                newUrl +="?"+s2[0];
                for (var i=1; i<s2.length; i++) 
                {   
                    if(find != i)
                        newUrl += "&"+s2[i];
                }
                if(find != -1)
                {
                    newUrl += "&"+p;
                }
                else
                {
                    newUrl += "&"+paramName +"="+elem.value;
                }
            }
        }
        for(var idxA =0; idxA < ArraylinkElem.length; ++idxA)
        {
            ArraylinkElem[idxA].href = newUrl;
        }
        window.location = newUrl;
	    return false;
	}
	
	
	function ValidDecimal(input)
	{
        var num = input.value.replace(/\s/g,'');
        num = num.replace(',','.');
        if(!isNaN(num))
        {
            return;
        }
        else
        {
            input.value = input.value.replace(/[^0-9,.]/g,'');
            //input.value = input.value.substring(0,input.value.length-1);
        }
    }

