/********************************************
* XML Cache using IE 5.0 Behaviour
* Author : @Kok Sang
* Website: http://www16.brinkster.com/iforum
---------------------------------------------
Save to Client Session.
@ SvXML    = the XML vocab retrieve from Server
@ sSession = the client session name
********************************************/
function SvData(SvXML,sSession){
     xcache.value = SvXML;
     oXMLTMP = xcache;
     strTheValue = oXMLTMP.value;
     oXMLTMP.setAttribute("PersistedValue",strTheValue);
     oXMLTMP.save(sSession);
}

/***********************************
Load data from Client Session
@ sSession = the client session name
************************************/
function ldData(sSession) {
  objTextBox = xcache;
  objTextBox.load(sSession);
  strTheValue = objTextBox.getAttribute("PersistedValue");
  if (strTheValue == null) strTheValue="";
  return strTheValue;
}


//Global variabel
var get_data = new Array();

/****************************************
Check The Radio or Check box true | false
****************************************/
function Chked(SrItm){
   return (SrItm.checked) ? true : false;
}
/***********************
Check the Input Types
************************/
function ChkInput(types){
	var SrRdr = (types.type == "radio" || types.type == "checkbox") ? true : false;
	return SrRdr,(types.type == "text" || types.type == "password") ? "teks" : "nop";
}
/***************************************
Create the XML Vocab from the form Input
****************************************/
function CrtVcb(Onode){
  var oVocab = new ActiveXObject("microsoft.xmldom");
  var oRNode = oVocab.createElement("root");
  oVocab.documentElement = oRNode;
  var oSecondNode = oVocab.createElement(Onode);
  var oNameNode,Bdoc;
  oVocab.documentElement.appendChild(oSecondNode);
  with (document.forms(0)){
	  for (var i=0;i<length;i++){
	    Bdoc = false;
	    if (ChkInput(item(i)) == "teks"){
		  if (item(i).value != '')
			Bdoc = true
		  else Bdoc = false;
		}
		else{
		  if (ChkInput(item(i))){
			Bdoc = (Chked(item(i))) ? true : false;
		  }
		  if (item(i).tagName.toLowerCase() == "select") Bdoc = true;
		}

		if (Bdoc){
		   oNameNode = oVocab.createElement(item(i).name);
		   oNameNode.text = item(i).value;
		   oSecondNode.appendChild(oNameNode);
		}
	  }
	}
  return oVocab;
}
/*************************
save vocab XML to be proceed
Enter the file name from prompted box (case sensitive)
**************************/
function Save(){
   if (get_data[0] != null){
     SvData(CrtVcb('TaxML').xml,get_data[0]);
     //alert("data saved " + get_data[0]);
   }else {
     //get_data[0] = window.prompt("Save File","Enter File Name: [case sensitive]");
     get_data[0] = "<%=PageID%>";  
     SvData(CrtVcb('TaxML').xml,get_data[0]);
     //alert("data saved " + get_data[0]);
   }
}
/*************************
Edit vocab XML to be proceed
@Enter the file name (case sensitive)
@load the session
**************************/
function Load(){
  var get_tmp = get_data[0];
  get_data[0] = "<%=PageID%>";    
  if (get_data[0] != null) { 
   if (oXMLCache.loadXML(ldData(get_data[0]))){

   }else {
	  //alert("Sorry There was no File above");
   }
  } 
  else{
    get_data[0] = get_tmp;  
  }
}


