﻿// 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 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=800, 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 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;
}