﻿// JScript File
function selectNextControl(control, nextControl, e, len)
{ 
      var fCtrl = document.getElementById(control); 
      var tCtrl = document.getElementById(nextControl); 
      
      if ((typeof fCtrl == 'object') && (typeof tCtrl == 'object'))
      { 
            if ((e.keyCode >= 48) && (e.keyCode <= 57))
            { 
                if (fCtrl.value.length >= len)
                {
                    tCtrl.focus();
                }
            }
      } 
} 

function changeBackColor(idControl)
{
    var ctrlBackEval = document.getElementById(idControl);
    
    if (ctrlBackEval != null)
        ctrlBackEval.className = "selItem";
}

function resetBackColor(idControl)
{
    var ctrlBackEval = document.getElementById(idControl);
    
    if (ctrlBackEval != null)
        ctrlBackEval.className = "";
}

function checkInt(e)
{
    if ((e.keyCode >= 48) && (e.keyCode <= 57))
        return true;
    else
        return false;
}

function gotoPage(page)
{
    //alert(page);
    window.location.href=page;
    return false;
}

function isInteger(e, idElement)
{
	var key;
	var keychar;
	var obj = document.getElementById(idElement);

	if (window.event)
		key = window.event.keyCode;
	else if (e)
		key = e.which;
	else
		return true;
		
	keychar = String.fromCharCode(key);
	keychar = keychar.toLowerCase();

	// control keys
	if ((key==null) || (key==0) || (key==8) || 
		(key==9) || (key==13) || (key==27) )
		return true;
	else if ((("0123456789").indexOf(keychar) > -1))
		return true;
	else
		return false;
}

function checkRequeriedFields(control1, control2, control3)
{
    var object1 = document.getElementById(control1);
    var object2 = document.getElementById(control2);
    var object3 = document.getElementById(control3);
    var retorno = false;
    
    if(object1 != null)
    {
	    if (object1.value != '')
	    {
	        if (object2.value != '')
	        {
	            if (object3.value != '')
	            {
	                retorno = true;
	            }
	            else
	            {
	                object3.focus();
	            }
	        }
	        else
	        {
	            object2.focus();
	        }
	    }
	    else
	    {
	        object1.focus();
	    }
    }
    
    return retorno;
}

function EvaluateRequiredField(idControl, idReqAdvert, idLabelAdvert, valueAdvert, valueRequired)
{
    var usrCtl = document.getElementById(idControl);
    var usrAdv = document.getElementById(idReqAdvert);
    var usrAdvMsg = document.getElementById(idLabelAdvert);
    
    usrAdv.innerText = '';
        
    var ret = true;
    
    if (usrCtl.value == '')
    {
        usrAdv.innerText = valueAdvert;
        usrAdvMsg.innerText = valueRequired;
        usrCtl.focus();
        ret = false;
    }
    
    return ret;
}

function EvaluateRequiredFields(idControl1, idReqAdvert1, idControl2, idReqAdvert2, idControl3, idReqAdvert3, idControl4, idReqAdvert4, idControl5, idReqAdvert5, idLabelAdvert, valueAdvert, valueRequired)
{
    var usrAdvMsg = document.getElementById(idLabelAdvert);
    usrAdvMsg.innerText = '';
    
    var ret = true;
    
    ret = (ret) & (EvaluateRequiredField(idControl5, idReqAdvert5, idLabelAdvert, valueAdvert, valueRequired));
    ret = (ret) & (EvaluateRequiredField(idControl4, idReqAdvert4, idLabelAdvert, valueAdvert, valueRequired));
    ret = (ret) & (EvaluateRequiredField(idControl3, idReqAdvert3, idLabelAdvert, valueAdvert, valueRequired));
    ret = (ret) & (EvaluateRequiredField(idControl2, idReqAdvert2, idLabelAdvert, valueAdvert, valueRequired));
    ret = (ret) & (EvaluateRequiredField(idControl1, idReqAdvert1, idLabelAdvert, valueAdvert, valueRequired));
    
    if (ret == 0)
        return false;
    else 
        return ret;
}

function clickEnableCallForward(radControlEnable, control1, control2)
{
    var radControl = document.getElementById(radControlEnable);  
    var object1 = document.getElementById(control1);  
    var object2 = document.getElementById(control2);  
    
    if(radControl.checked)
    {
	    object1.style.display = 'inline';
	    object2.style.display = 'inline';
    }
    else
    {
        object1.style.display = 'none';
	    object2.style.display = 'none';
    }    
}

function changeCssClass(idControl1, idControl2, cssClass)
{
    var ctrl1 = document.getElementById(idControl1);
    var ctrl2 = document.getElementById(idControl2);
    
    ctrl1.className = cssClass;
    ctrl2.className = cssClass;
}

function disabledControls(idControl1, idControl2)
{
    var ctrl1 = document.getElementById(idControl1);
    var ctrl2 = document.getElementById(idControl2);
    
    if (ctrl1 != null)
        ctrl1.disabled = true;
    
    if (ctrl2 != null)
        ctrl2.disabled = true;
}

function showProcessing(idButton1, idButton2, idTextBox, message)
{
    var button1 = document.getElementById(idButton1);
    var button2 = document.getElementById(idButton2);
    var txtbox = document.getElementById(idTextBox);

    if (button1 != null)
        button1.style.display = 'none';
        
    if (button2 != null)
        button2.style.display = 'none';
    
    if (txtbox != null)    
        txtbox.innerText = message;
        
    return true;
}

function clickButton(e, buttonid)
{ 
      var bt = document.getElementById(buttonid); 
      if (typeof bt == 'object')
      { 
            if(navigator.appName.indexOf("Netscape")>(-1))
            { 
                  if (e.keyCode == 13)
                  { 
                        bt.click(); 
                        return false; 
                  } 
            } 
            else if (navigator.appName.indexOf("Microsoft Internet Explorer")>(-1))
            { 
                  if (event.keyCode == 13)
                  { 
                        bt.click(); 
                        return false; 
                  } 
            }
            else
            {
                  if (event.keyCode == 13)
                  { 
                        bt.click(); 
                        return false; 
                  } 
            }
      } 
}

function openPage(page)
{
    window.open(page,'mywindow', 'height=425, width=700, status=0, toolbar=0, menubar=0, location=1, resizable=1, scrollbars=1')
    return false;
}

function openPage2(page)
{
    window.open(page,'mywindow', 'height=800, width=700, status=0, toolbar=0, menubar=0, location=1, resizable=1, scrollbars=1')
    return false;
}

function gotoPage(page)
{
    window.location.href=page;
    return false;
}

function MM_preloadImages() 
{ //v3.0
    var d=document; 
    
    if(d.images)
    { 
        if(!d.MM_p)
        {
            d.MM_p=new Array();
        }
        
        var i,j=d.MM_p.length,a=MM_preloadImages.arguments; 
        
        for(i=0; i<a.length; i++)
        {
            if (a[i].indexOf("#")!=0)
            { 
                d.MM_p[j]=new Image; 
                d.MM_p[j++].src=a[i];
            }
        }
    }       
}

function MM_findObj(n, d) 
{ 
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImgRestore() 
{ 
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_swapImage() 
{ 
    var i,j=0,x,a=MM_swapImage.arguments; 
    document.MM_sr=new Array; 

    for(i=0;i<(a.length-2);i+=3)
    {    
        if ((x=MM_findObj(a[i]))!=null)
        {
            document.MM_sr[j++]=x; 
            if(!x.oSrc) 
                x.oSrc=x.src; 
                
            x.src=a[i+2];
        }
    }    
}

function EvaluateSelectedCountry(idComboBox, idCountry, idControlHide1, idControlHide2, idControlHide3)
{
    var comboBox = document.getElementById(idComboBox);
    var control1 = document.getElementById(idControlHide1);
    var control2 = document.getElementById(idControlHide2);
    var control3 = document.getElementById(idControlHide3);
    
    if (comboBox != null)
    {
        control1.style.display = 'none';
        if (control1 != null)
        {
            if (comboBox.value == idCountry)
                control1.style.display = 'inline';
        }
        
        control2.style.display = 'none';
        if (control2 != null)
        {
            if (comboBox.value == idCountry)
                control2.style.display = 'inline';
        }
        
        control3.style.display = 'none';
        if (control3 != null)
        {
            if (comboBox.value == idCountry)
                control3.style.display = 'inline';
        }
    }
        
    return true;
}

function evaluateTotalByChecked(idCheckbox, idTextboxShowAmount, pNewValue)
{
    var chkControl = document.getElementById(idCheckbox);
    var textBoxShowAmount = document.getElementById(idTextboxShowAmount);
    
    var l_TotalAmount = Math.abs(pNewValue);
    var l_Value1 = Math.abs(textBoxShowAmount.value);
    
    var l_Total;    
    if(chkControl.checked)
    {
        l_Total = l_Value1 + l_TotalAmount;
        l_Total = Math.round(l_Total * 100)/100;
        
    }
    else
    {
        l_Total = l_Value1 - l_TotalAmount;
        l_Total = Math.round(l_Total * 100)/100;
    }
    
    textBoxShowAmount.value = l_Total;
}

function evaluateBackColor(idControl, idCheckbox)
{
    var ctrlBackEval = document.getElementById(idControl);
    var ctrlCheckBox = document.getElementById(idCheckbox);
    
    if (ctrlCheckBox.checked)
    {
        ctrlBackEval.className = "selItem";
    }
    else
    {
        ctrlBackEval.className = "";
    }
}

function evaluateCheckBoxAndDisabledControls(idCheckbox, idControl1, idControl2)
{
    var ctrlCheckBox = document.getElementById(idCheckbox);
    var ctrl1 = document.getElementById(idControl1);
    var ctrl2 = document.getElementById(idControl2);
    
    if (ctrlCheckBox != null)
    {
        if (ctrl1 != null)
            ctrl1.disabled = !ctrlCheckBox.checked;
        
        if (ctrl2 != null)
            ctrl2.disabled = !ctrlCheckBox.checked;
    }
}

function uncheckItem(idCheckBox)
{
    var ctrlCheckBox = document.getElementById(idCheckBox);
    if (ctrlCheckBox != null)
    {
        ctrlCheckBox.checked = false;
    }
}

function HideControlsByDelay(idControl1, idControl2, idLabel, pText)
{
    var objLabel = document.getElementById(idLabel);
    var objControl1 = document.getElementById(idControl1);
    var objControl2 = document.getElementById(idControl2);
    
    if (objControl1 != null)
        objControl1.style.display = 'none';
        
    if (objControl2 != null)
        objControl2.style.display = 'none';
        
    if (objLabel != null)
        objLabel.value = pText;
}

function DisableControlsByComboValue(idControlCombo, pValue, idControl1, idControl2, idControlInv1, idControlInv2)
{
    var objControlCombo = document.getElementById(idControlCombo);
    var objControl1 = document.getElementById(idControl1);
    var objControl2 = document.getElementById(idControl2);
    var objControlInv1 = document.getElementById(idControlInv1);
    var objControlInv2 = document.getElementById(idControlInv2);
    
    if (objControlCombo != null)
    {
        if (objControl1 != null) 
            objControl1.disabled = (objControlCombo.value == pValue);
            
        if (objControl2 != null)
            objControl2.disabled = (objControlCombo.value == pValue);
            
        if (objControlInv1 != null)
            objControlInv1.disabled = (objControlCombo.value != pValue);
            
        if (objControlInv2 != null)
            objControlInv2.disabled = (objControlCombo.value != pValue);
    }
}

function DisableControlsByComboValue2(idControlCombo, pValue, idControl1, idControl2, idControlInv1, idControlChk)
{
    var objControlCombo = document.getElementById(idControlCombo);
    var objControl1 = document.getElementById(idControl1);
    var objControl2 = document.getElementById(idControl2);
    var objControlInv1 = document.getElementById(idControlInv1);
    var objControlChk = document.getElementById(idControlChk);
    
    if (objControlCombo != null)
    {
        if (objControl1 != null) 
            objControl1.disabled = (objControlCombo.value == pValue);
            
        if (objControl2 != null)
            objControl2.disabled = (objControlCombo.value == pValue);
            
        if (objControlInv1 != null)
        {
            if (objControlChk != null)
            {
                objControlInv1.disabled = objControlChk.checked;
            }
            else
            {
                objControlInv1.disabled = (objControlCombo.value != pValue);
            }            
        }
    }
}

function evaluateRegionItems(idControlRegion, idControlCountry, idControlItems, valAllCountriesValue, selectedValue)
{
    var objControlRegion = document.getElementById(idControlRegion);
    var objControlCountry = document.getElementById(idControlCountry);
    var objControlControlItems = document.getElementById(idControlItems);
 
    if ((objControlRegion != null) && (objControlCountry != null) && (objControlControlItems != null))
    {
        var l_IdRegion = objControlRegion.value;
        var l_AllValues = objControlControlItems.value;
        
        objControlCountry.length = 0;
        objControlCountry.length = objControlCountry.length + 1;
        objControlCountry.options[objControlCountry.length - 1].text = valAllCountriesValue;
        objControlCountry.options[objControlCountry.length - 1].value = "-1";
                    
        var l_ValuesArray = l_AllValues.split(";");
        for(i=0;i<l_ValuesArray.length;i++)
        {
            var l_ValuesArray2 = l_ValuesArray[i].split("@");
            if (l_ValuesArray2.length > 1)
            {
                if (l_ValuesArray2[0] == objControlRegion.value)
                {
                    var l_ValuesArray3 = l_ValuesArray2[1].split("#");
                    for (j=0; j<l_ValuesArray3.length; j++)
                    {
                        var l_ValuesArray4 = l_ValuesArray3[j].split("*");
                        if (l_ValuesArray4.length > 1)
                        {
                            objControlCountry.length = objControlCountry.length + 1;
                            
                            objControlCountry.options[objControlCountry.length - 1].text = l_ValuesArray4[0];
                            objControlCountry.options[objControlCountry.length - 1].value = l_ValuesArray4[1];
                        }
                    }
                    
                    break;
                }
            }        
        }
        
        if (selectedValue.length > 0)
        {
            objControlCountry.value = selectedValue;
        }
    }
}

function clickButton(e, buttonid)
{ 
    var bt = document.getElementById(buttonid); 
    if (typeof bt == 'object')
    { 
        if(navigator.appName.indexOf("Netscape")>(-1))
        { 
              if (e.keyCode == 13){ 
                    bt.click(); 
                    return false; 
              } 
        } 
        else if (navigator.appName.indexOf("Microsoft Internet Explorer")>(-1))
        { 
              if (event.keyCode == 13){ 
                    bt.click(); 
                    return false; 
              } 
        } 
        else
        {
            if (event.keyCode == 13)
            { 
                    bt.click(); 
                    return false; 
            } 
        }        
    } 
}

function disabledControls(idControl1, idControl2, idControl3, idControl4, idControl5, idControl6, idControl7, idControl8, idControl9, idControl10)
{ 
    var objControl1 = document.getElementById(idControl1);
    if (objControl1 != null)
        objControl1.disabled = true;
        
    var objControl2 = document.getElementById(idControl2);
    if (objControl2 != null)
        objControl2.disabled = true;
        
    var objControl3 = document.getElementById(idControl3);
    if (objControl3 != null)
        objControl3.disabled = true;
    
    var objControl4 = document.getElementById(idControl4);
    if (objControl4 != null)
        objControl4.disabled = true;
        
    var objControl5 = document.getElementById(idControl5);
    if (objControl5 != null)
        objControl5.disabled = true;
        
    var objControl6 = document.getElementById(idControl6);
    if (objControl6 != null)
        objControl6.disabled = true;
        
    var objControl7 = document.getElementById(idControl7);
    if (objControl7 != null)
        objControl7.disabled = true;
        
    var objControl8 = document.getElementById(idControl8);
    if (objControl8 != null)
        objControl8.disabled = true;
        
    var objControl9 = document.getElementById(idControl9);
    if (objControl9 != null)
        objControl9.disabled = true;
        
    var objControl10 = document.getElementById(idControl10);
    if (objControl10 != null)
        objControl10.disabled = true;
}

function hideControlWhenChecked(idCheckControl, idEvalControl, idConditionControl)
{
    var objCheckControl = document.getElementById(idCheckControl);
    var objEvalControl = document.getElementById(idEvalControl);
    var objConditionControl = document.getElementById(idConditionControl);
    
    if ((objConditionControl != null) && (objConditionControl.value == "1"))
    { 
        if ((objCheckControl != null) && (objEvalControl != null))
        {
            if (objCheckControl.checked)
            {
                objEvalControl.style.display = 'inline';
            }
            else
            {
                objEvalControl.style.display = 'none';
            }
        }
    }
}

function hideControls(idControl1, idControl2, idControl3)
{
    var objControl1 = document.getElementById(idControl1);
    if (objControl1 != null)
        objControl1.style.display = 'none';
    
    var objControl2 = document.getElementById(idControl2);
    if (objControl2 != null)
        objControl2.style.display = 'none';
        
    var objControl3 = document.getElementById(idControl3);
    if (objControl3 != null)
        objControl3.style.display = 'none';
}

function evaluateAndHideControls(idEvalControl1, idEvalControl2, idEvalControl3, idEvalControl4, idEvalControl5, idControl1, idControl2, idControl3)
{
    var objEvalControl1 = document.getElementById(idEvalControl1);
    var objEvalControl2 = document.getElementById(idEvalControl2);
    var objEvalControl3 = document.getElementById(idEvalControl3);
    var objEvalControl4 = document.getElementById(idEvalControl4);
    var objEvalControl5 = document.getElementById(idEvalControl5);
    
    var l_Return = false;
    if ((objEvalControl1 != null) && (objEvalControl2 != null) && (objEvalControl3 != null) && (objEvalControl4 != null) && (objEvalControl5 != null))
    {
        if ((objEvalControl1.value.length > 0) && (objEvalControl1.value != "0")
        &&  (objEvalControl2.value.length > 0) && (objEvalControl2.value != "0")
        &&  (objEvalControl3.value.length > 0) && (objEvalControl3.value != "0")
        &&  (objEvalControl4.value.length > 0) && (objEvalControl4.value != "0")
        &&  (objEvalControl5.value.length > 0) && (objEvalControl5.value != "0"))
        {    
            var objControl1 = document.getElementById(idControl1);
            if (objControl1 != null)
                objControl1.style.display = 'none';
            
            var objControl2 = document.getElementById(idControl2);
            if (objControl2 != null)
                objControl2.style.display = 'none';
                
            var objControl3 = document.getElementById(idControl3);
            if (objControl3 != null)
                objControl3.style.display = 'none';
                
            l_Return = true;
        }
    }
    
    return l_Return;
}

function showControls(idControl1, idControl2, idControl3)
{
    var objControl1 = document.getElementById(idControl1);
    if (objControl1 != null)
        objControl1.style.display = 'inline';
    
    var objControl2 = document.getElementById(idControl2);
    if (objControl2 != null)
        objControl2.style.display = 'inline';
    
    var objControl3 = document.getElementById(idControl3);
    if (objControl3 != null)
        objControl3.style.display = 'inline';
}

function showControlsAndDisabledCheckBoxFunction(idControl1, idControl2, idControl3, idControlAux1)
{
    var objControl1 = document.getElementById(idControl1);
    if (objControl1 != null)
        objControl1.style.display = 'inline';
    
    var objControl2 = document.getElementById(idControl2);
    if (objControl2 != null)
        objControl2.style.display = 'inline';
    
    var objControl3 = document.getElementById(idControl3);
    if (objControl3 != null)
        objControl3.style.display = 'inline';
        
    var objControlAux1 = document.getElementById(idControlAux1);
    if (objControlAux1 != null)
        objControlAux1.value = "0";
}

function copyValues(idGlobalControl, idButton1, idSource1, idDestination1, idSource2, idDestination2, idSource3, idDestination3, idSource4, idDestination4, idSource5, idDestination5, idSource6, idDestination6)
{
    var objControlGlobal = document.getElementById(idGlobalControl);
    if (objControlGlobal != null)
    {
        var objButton1 = document.getElementById(idButton1);
        if (objButton1 != null)
        {
            if (objControlGlobal.checked)
            {
                objButton1.disabled = true;
            }
            else
            {
                objButton1.disabled = false;
            }
        }
    
        var objControlSource1 = document.getElementById(idSource1);
        var objControlDestination1 = document.getElementById(idDestination1);
        if ((objControlSource1 != null) && (objControlDestination1 != null))
        {
            if (objControlGlobal.checked)
            {
                objControlDestination1.value = objControlSource1.value;
                objControlDestination1.readOnly = true;
            }
            else
            {
                objControlDestination1.value = '';
                objControlDestination1.readOnly = false;
            }
        }
        
        var objControlSource2 = document.getElementById(idSource2);
        var objControlDestination2 = document.getElementById(idDestination2);
        if ((objControlSource2 != null) && (objControlDestination2 != null))
        {
            if (objControlGlobal.checked)
            {
                objControlDestination2.value = objControlSource2.value;
                objControlDestination2.readOnly = true;
            }
            else
            {
                objControlDestination2.value = '';
                objControlDestination2.readOnly = false;
            }
        }
        
        var objControlSource3 = document.getElementById(idSource3);
        var objControlDestination3 = document.getElementById(idDestination3);
        if ((objControlSource3 != null) && (objControlDestination3 != null))
        {
            if (objControlGlobal.checked)
            {
                objControlDestination3.value = objControlSource3.value;
                objControlDestination3.readOnly = true;
            }
            else
            {
                objControlDestination3.value = '';
                objControlDestination3.readOnly = false;
            }
        }
        
        var objControlSource4 = document.getElementById(idSource4);
        var objControlDestination4 = document.getElementById(idDestination4);
        if ((objControlSource4 != null) && (objControlDestination4 != null))
        {
            if (objControlGlobal.checked)
            {
                objControlDestination4.value = objControlSource4.value;
                objControlDestination4.readOnly = true;
            }
            else
            {
                objControlDestination4.value = '';
                objControlDestination4.readOnly = false;
            }
        }
        
        var objControlSource5 = document.getElementById(idSource5);
        var objControlDestination5 = document.getElementById(idDestination5);
        if ((objControlSource5 != null) && (objControlDestination5 != null))
        {
            if (objControlGlobal.checked)
            {
                objControlDestination5.value = objControlSource5.value;
                objControlDestination5.readOnly = true;
            }
            else
            {
                objControlDestination5.value = '';
                objControlDestination5.readOnly = false;
            }
        }        
        
        var objControlSource6 = document.getElementById(idSource6);
        var objControlDestination6 = document.getElementById(idDestination6);
        if ((objControlSource6 != null) && (objControlDestination6 != null))
        {
            if (objControlGlobal.checked)
            {
                objControlDestination6.value = objControlSource6.value;
                objControlDestination6.disabled = true;
            }
            else
            {
                objControlDestination6.value = '198';
                objControlDestination6.disabled = false;
            }
        }  
    }
    
    
}
