 function changeCheckVal(){
    if(document.frmcreate.chkActive.checked==true){
        document.frmcreate.chkActive.value=1;
        document.frmcreate.txtActive.value=1;
    }else{
        document.frmcreate.chkActive.value=0;
        document.frmcreate.txtActive.value=0;
    }
    //alert(document.frmcreate.chkActive.value)
}

function openWin(url){
		thisPageName=url
		DialogParam="Lookup"
		if(confirm('Adding values to the dropdown boxes on this page will cause it to be reloaded. Any unsaved data will be lost by performing this task.'))
		    window.open(thisPageName, DialogParam,'edge:Raised; center:Yes; help:No; scrollbars:No; resizable:No;status: No; Height=300px; Width=420px;')
    }
    
function IsNumeric(sText){
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;

 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
}


function checkvals(){
    var numValsInArray=10;
    var strError="";
    var errColour="#cc0000"
    var intFirstError=11; //purposefully set this value higher than the total number in the array. This 
    //variable is used to select the first error only so that we can set the focus to the first error field
    
    //set the value of all the div tags back to standard.
    for(x=1;x<numValsInArray+1;x++){
        eval('document.all.div'+x+'.innerHTML="'+elementName[x]+':*"')
    }
    for(i=1;i<numValsInArray+1;i++){
        if(eval('document.frmcreate.txt'+i+'.value==""')){
            strError+="\n"+elementName[i]+" has an invalid entry.";
            eval('document.all.div'+i+'.innerHTML="<font color='+errColour+'><b><b/>'+elementName[i]+':*</font>"')
            if(i<intFirstError){
                intFirstError=i;                
            }
        }
    }
    //now check all of the integer fields. As these are all non required 
    //then we will need to check if there is a value and if so is it numeric.
    for(z=1;z<8;z++){
        if(z==3){
            eval('document.all.divInt'+z+'.innerHTML="'+integerName[z]+':"')
        }else{
            eval('document.all.divInt'+z+'.innerHTML="'+integerName[z]+':<strong>&pound;</strong>"')
        }
    }
    for(y=1;y<8;y++){
        if(eval('document.frmcreate.int'+y+'.value.length')>0){
            boolNum=IsNumeric(eval('document.frmcreate.int'+y+'.value'));
            if(boolNum==false){
                strError+="\n"+integerName[y]+" has an invalid value. Please ensure that it is a number"
                if(y==3){
                    eval('document.all.divInt'+y+'.innerHTML="<font color='+errColour+'><b><b/>'+integerName[y]+':</font>"')
                }else{
                    eval('document.all.divInt'+y+'.innerHTML="<font color='+errColour+'><b><b/>'+integerName[y]+':<strong>&pound;</strong></font>"')
                }
            }
        }
    }    
    
    if(strError.length>0){
        alert(strError)
        if(intFirstError!=11)
            eval('document.frmcreate.txt'+intFirstError+'.focus()');
            
        return false;
    }else{
        len=document.frmcreate.sltFeatures.length;
        strVals=""
        for(i=0;i<len;i++){
            strVals+=document.frmcreate.sltFeatures.options[i].value+","
        }
        document.frmcreate.txtFeatures.value=strVals
        strVals=""
        len=document.frmcreate.sltElig.length;
        for(i=0;i<len;i++){
            strVals+=document.frmcreate.sltElig.options[i].value+","
        }
        document.frmcreate.txtSelectedElig.value=strVals;
        //alert(document.frmcreate.txtSelectedElig.value)
        return true;
    }
    
}

function limitlist(formName,divId,controlName,controlToBuild,xmlDocName){
	//find the value of the selected group
	strControlVal=eval('document.'+formName+'.'+controlName+'.value');
	strChildVal=eval('document.'+formName+'.'+controlToBuild+'.value');

	try {
	    objXML = new ActiveXObject("Msxml2.FreeThreadedDOMDocument");
	    objXSL = new ActiveXObject("Msxml2.FreeThreadedDOMDocument");
	    objTemplate = new ActiveXObject("MSXML2.XSLTemplate");
	    objTransTemplate = new ActiveXObject("MSXML2.XSLTemplate");
	    objXML.async = false;

	    //eval('objXML.loadXML ("areas.asp")');
	    objXML.load("areas.asp");
	    objXSL.async = false;
	    objXSL.load("limitxml.1.xsl");
	    //create instance of xsl template obj
	    objTemplate.stylesheet = objXSL;
	    //create the processor object
	    objProcessor = objTemplate.createProcessor();
	    //pass the processor the xml
	    objProcessor.input = objXML;
	    //add parameters that the xsl file may utilise
	    objProcessor.addParameter("group", strControlVal);
	    //run the transofrmation
	    objProcessor.transform;
	    strXML = objProcessor.output;
	    //load the output into the original object for further manipulation
	    objXML.loadXML(strXML);
	    //Now perform the second transformation
	    objXSLTransform = new ActiveXObject("Msxml2.FreeThreadedDOMDocument")
	    objXSLTransform.async = false;
	    objXSLTransform.load("createCombo.1.xsl");

	    objTransTemplate.stylesheet = objXSLTransform;
	    objTransProcessor = objTransTemplate.createProcessor;
	    objTransProcessor.input = objXML
	    objTransProcessor.addParameter("slt", strChildVal)
	    objTransProcessor.addParameter("cmbName", controlToBuild)
	    objTransProcessor.addParameter("cntrl", "xmlChild")
	    objTransProcessor.addParameter("scriptref", "limitlist();")
	    objTransProcessor.transform;
	    strHTML = objTransProcessor.output;
	    var div  = document.getElementById(divId);
	    div.innerHTML = strHTML;
	}
	catch (err) {
	    try {
	        xml = loadXMLDoc("areas.asp");
	        xsl = loadXMLDoc("limitxml.1.xsl");
	        if (document.implementation && document.implementation.createDocument) {
	            xsltProcessor = new XSLTProcessor();
	            xsltProcessor.importStylesheet(xsl);
	            xsltProcessor.setParameter(null, "group", strControlVal);
	            resultDocument = xsltProcessor.transformToDocument(xml);
	            
	            xsl2 = loadXMLDoc("createCombo.1.xsl");
	            xsltProcessor2 = new XSLTProcessor();
	            xsltProcessor2.importStylesheet(xsl2);
	            xsltProcessor2.setParameter(null, "slt", strChildVal);
	            xsltProcessor2.setParameter(null, "cmbName", controlToBuild);
	            xsltProcessor2.setParameter(null, "cntrl", "xmlChild");
	            xsltProcessor2.setParameter(null, "scriptref", "limitlist();");
	            
	            resultDocument2 = xsltProcessor2.transformToDocument(resultDocument);

	            strHTML = (new XMLSerializer()).serializeToString(resultDocument2);
	            var div  = document.getElementById(divId);
	    	    div.innerHTML = strHTML;
	        }
	    }
	    catch (e) {
	        alert(e);
	    }

	}

}
function loadXMLDoc(dname) {
    if (window.XMLHttpRequest) {
        xhttp = new XMLHttpRequest();
    }
    else {
        xhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    xhttp.open("GET", dname, false);
    xhttp.send("");
    return xhttp.responseXML;
}

function copyToList(from,to){
    fromList = eval('document.frmcreate.' + from);
    toList = eval('document.frmcreate.' + to);
    if (toList.options.length > 0 && toList.options[0].value == 'temp'){
        toList.options.length = 0;
    }
      var sel = false;
      for (i=0;i<fromList.options.length;i++)
      {
        var current = fromList.options[i];
        if (current.selected)
        {
          sel = true;
          if (current.value == 'temp')
          {
            alert ('You cannot move this text!');
            return;
          }
          txt = current.text;
          val = current.value;
          toList.options[toList.length] = new Option(txt,val);
          fromList.options[i] = null;
          i--;
        }
      }
      if (!sel) alert ('You haven\'t selected any options!');
}

function testselected(){
    len=document.frmcreate.sltFeatures.length
    
    
}
