
var pvcPageErrors = new Array();
var pvcPageErrorCount = 0;

//moved from pvcDoSetQoS() by Edward on 2004/09/14
var index = 0;
//moved from pvcDoSetQoS() by Edward on 2004/09/14	end

function pvcDoOnLoad()
{
  //document.getElementById("uiPostPvcVpi").value=0;
  //document.getElementById("uiPostPvcVci").value=33;
  //alert("uiPostPvcVpi=" + document.getElementById("uiPostPvcVpi").value);
  jslSetValue("uiViewPvcVpi","uiPostPvcVpi");
  jslSetValue("uiViewPvcVci","uiPostPvcVci");
}
function pvcIndexOnLoad(arg)
{
  document.getElementById("uiViewWanConn").selectedIndex = parseInt(arg.charAt(6));
}

function isNumeric(s)
{
  var len= s.length;
  var ch;
  if(len==0)
    return false;
  for( i=0; i< len; i++)
  {
    ch= s.charAt(i);
    if( ch > '9' || ch < '0')
    {
      return false;
    }
  }
  return true;
}

function QoSDoOnLoad()
{

  document.getElementById("uiPostPvcPcr").value = parseInt(document.getElementById("uiPostPvcPcr").value)/1024;
  //clark modify on 2005/03/10
  //document.getElementById("uiPostPvcPcr").value = parseInt(document.getElementById("uiPostPvcPcr").value)/1024;
  document.getElementById("uiPostPvcScr").value = parseInt(document.getElementById("uiPostPvcScr").value)/1024;	
 
  switch(document.getElementById("uiPostPvcQoS").value)
  {
    case "CBR":
      jslSetValue("uiViewPvcPcr","uiPostPvcPcr");
	  document.getElementById("uiViewPvcScr").value="";
    break;
    case "VBR":
      jslSetValue("uiViewPvcPcr","uiPostPvcPcr");
      jslSetValue("uiViewPvcScr","uiPostPvcScr");
    break;
    case "UBR":
    default:
	  document.getElementById("uiViewPvcPcr").value="";
	  document.getElementById("uiViewPvcScr").value="";
	break;
  }
  pvcDoSetQoS(document.getElementById("uiPostPvcQoS").value);
  
}
function pvcDoSave()
{
  //alert("enter pvcDoSave !");
  jslSetValue("uiPostPvcVpi","uiViewPvcVpi");
  jslSetValue("uiPostPvcVci","uiViewPvcVci");
}
function QoSDoSave()
{
  var message;

  jslSetValue("uiPostPvcQoS","uiViewQosS");
  switch(document.getElementById("uiPostPvcQoS").value)
  {
    case "CBR":
      jslSetValue("uiPostPvcPcr","uiViewPvcPcr");
    break;
    case "VBR":
      jslSetValue("uiPostPvcPcr","uiViewPvcPcr");
      jslSetValue("uiPostPvcScr","uiViewPvcScr");
    break;
    case "UBR":
    default:
	break;
  }
  	document.getElementById("uiPostPvcPcr").value = parseInt(document.getElementById("uiPostPvcPcr").value)*1024;
  	//clark modify on 2005/03/10
	//document.getElementById("uiPostPvcPcr").value = parseInt(document.getElementById("uiPostPvcPcr").value)*1024;		
	document.getElementById("uiPostPvcScr").value = parseInt(document.getElementById("uiPostPvcScr").value)*1024;	

}

function pvcDoSetQoS(arg)
{
//Edward made index a global variable on 2004/09/14
//  var index = 0;
//Edward made index a global variable on 2004/09/14	end
  switch(arg)
  {
    case "CBR":
      index = 1;
	  jslEnable("uiViewPvcPcr");
	  jslDisable("uiViewPvcScr");
    break;
    case "VBR":
      index = 2;
	  jslEnable("uiViewPvcPcr");
	  jslEnable("uiViewPvcScr");
    break;
    case "UBR":
    default:
      index = 0;
	  jslDisable("uiViewPvcPcr");
	  jslDisable("uiViewPvcScr");
	break;
  }
  document.getElementById("uiViewQosS").selectedIndex=index;
}

/* PVC :VPI:0-255 VCI:0-65535*/
function pvcDoValidatePage()
{
  var message;
  var value;
  var pvcPageErrorCount=0;

  value = document.getElementById("uiViewPvcVpi").value;
  if(valDoValidateInteger(value) == false)
  { 
  	return false;
  	erlDoAddError("bad","uiViewPvcVpi","",value,"VPI only accepts digital input!"); 
  	pvcPageErrorCount++; 
  }
  else if(Number(value) > 255 || Number(value)<0) 
  { 
  	alert("VPI Must between 0 and 255"); 
  	return false; 
  	erlDoAddError("bad","uiViewPvcVpi","",value,"VPI must be in the range 0-255"); 
  	pvcPageErrorCount++ ;
  }


  value = document.getElementById("uiViewPvcVci").value;
  message = valDoValidateInteger(value);
  if(message == false) 
  { 
  	return false; 
  	erlDoAddError("bad","uiViewPvcVci","",value,"VCI only accepts digital input!"); 
  	pvcPageErrorCount++; 
  }
  else if(Number(value) > 65535 || Number(value)<32) 
  { 
  	alert("VCI Must between 32 and 65535"); 
  	return false; 
  	erlDoAddError("bad","uiViewPvcVci","",value,"VCI must be in the range 32-65535"); 
  	pvcPageErrorCount++; 
  }  

  if(pvcPageErrorCount!=0) message="PVC";
  else message="";
  return true;
}


/* QoS: UBR CBR VBR*/

function QoSDoValidatePage()
{
  var message;
//  var value;
  var pvcPageErrorCount=0;
//  value = document.getElementById("uiPostPvcQoS").value;
  switch(index)//index is a global variable which is moved from pvcDoSetQoS() by Edward on 2004/09/14
  {
    case 0:
	 break;
    case 1:
                value = document.getElementById("uiViewPvcPcr").value;
                if(!isNumeric(value))
                {
                	alert("PCR must be Interger");
                	pvcPageErrorCount++; 
                	return false; 
                }
                else if(Number(value) > 63) { alert("PCR must be less than 64"); return false; erlDoAddError("bad","uiViewPvcPcr","",value,"PCR must be less than 64"); pvcPageErrorCount++; }
	 break;

    case 2:
                value = document.getElementById("uiViewPvcPcr").value;
                if(!isNumeric(value))
                {
                	alert("PCR must be Interger");
                	pvcPageErrorCount++; 
                	return false; 
                }
                else if(Number(value) > 63) { alert("PCR must be less than 64"); return false; erlDoAddError("bad","uiViewPvcPcr","",value,"PCR must be less than 64"); pvcPageErrorCount++; }

               value = document.getElementById("uiViewPvcScr").value;
                if(!isNumeric(value))
                {
                	alert("SCR must be Interger");
                	pvcPageErrorCount++; 
                	return false; 
                }
               else if(Number(value) > 63) { alert("SCR must be less than 64"); return false; erlDoAddError("bad","uiViewPvcScr","",value,"SCR must be less than 64"); pvcPageErrorCount++; }
	 break;

     default:
	 break;
  }

  if(pvcPageErrorCount!=0) message="QOS";
  else message="";
  return true;
  
}
	