/* JavaScript Document
#########################################################
#														#
#	Project:	Weritech Funcions						#
#	Versie:		1.0										#
#	Filename:	Weritech.js								#
#	copyright:	(c) 2005-2010 Weritech V.O.F.			#
#	Created By:	S. Riewald and N. van der Wegen			#
#	www:		info@weritech.nl						#
#														#			
#########################################################  
*/

(function() {
		  
			  
		Weritech = (function(){return this;}).call();
		
		// Start Public IdentifierTypes Functions

		Weritech.Version = '1.0'; // 1nd generation Weritech.js!
		
		Weritech.GetIdentifierTypes = function () { return $.Weritech.GetIdentifierTypes };
		Weritech.GetIdentifierTypes.id = function () { return 'id'; };
		Weritech.GetIdentifierTypes.name = function () { return 'name'; };
		
		Weritech.InnerHtmlAdd = function (ObjectID,Data) { InnerHtmlAdd(ObjectID,Data); }
		Weritech.InnerHtmlReplace = function (ObjectID,Data) { InnerHtmlReplace(ObjectID,Data); }
		Weritech.InnerHtmlClear = function (ObjectID) { InnerHtmlClear(ObjectID); }
		
		
		Weritech.InputTextValueAdd = function (ObjectID,Data) { InputTextValueAdd(ObjectID,Data); }
		Weritech.InputTextValueReplace = function (ObjectID,Data) { InputTextValueReplace(ObjectID,Data); }
		Weritech.InputTextValueClear = function (ObjectID) { InputTextValueClear(ObjectID); }
		
		Weritech.SelectOptionAdd = function (ObjectID,Data) { SelectOptionAdd(ObjectID,Data); }
		Weritech.SelectOptionReplace = function (ObjectID,Data) { SelectOptionReplace(ObjectID,Data); }
		Weritech.SelectOptionClear = function (ObjectID) { SelectOptionClear(ObjectID); }
		Weritech.SelectOptionSort = function (ObjectID) { SelectOptionSort(ObjectID); }
		
		
		Weritech.StyleAdd = function (Data,ObjectID) { StyleAdd(Data,ObjectID); };
		
		Weritech.ScriptAdd = function (Data,ObjectID) { ScriptAdd(Data,ObjectID); };
		
		Weritech.Eval = function (Data) { eval(Data); };
		
		// End Public IdentifierTypes Functions
		
		/////////////////////////////// < ....Private functions form here.... > \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
		
		// Start Add data into innerHTML
		function InnerHtmlAdd(ObjectID,Data) {
			 if (document.getElementById(ObjectID)) {
				var InnerHtmlAddObj = document.getElementById(ObjectID);
		 		InnerHtmlAddObj.innerHTML = InnerHtmlAddObj.innerHTML + Data;	
		 	}
		}
		
		// Start Replace data into innerHTML
		function InnerHtmlReplace(ObjectID,Data) {
			 if (document.getElementById(ObjectID)) {
				var InnerHtmlReplaceObj = document.getElementById(ObjectID);
		 		InnerHtmlReplaceObj.innerHTML = Data;	
		 	}
		}
		
		// Start Clear data from innerHTML
		function InnerHtmlClear(ObjectID) {
			 if (document.getElementById(ObjectID)) {
				var InnerHtmlClearObj = document.getElementById(ObjectID);
		 		InnerHtmlClearObj.innerHTML = '';	
		 	}
		}
		
		// Start Add data into Value
		function InputTextValueAdd(ObjectID,Data) {
			if (document.getElementById(ObjectID)) {
				var InputTextValueAddObj = document.getElementById(ObjectID);
		 		InputTextValueAddObj.value = InputTextValueAddObj.value + Data;
			}
		}
		
		// Start Replace data into Value
		function InputTextValueReplace(ObjectID,Data) {
			if (document.getElementById(ObjectID)) {
				var InputTextValueReplaceObj = document.getElementById(ObjectID);
		 		InputTextValueReplaceObj.value = Data;
			}
		}
		
		// Start Clear data from Value
		function InputTextValueClear(ObjectID) {
			if (document.getElementById(ObjectID)) {
				var InputTextValueClearObj = document.getElementById(ObjectID);
		 		InputTextValueClearObj.value = '';
			}
		}
		
		
		// Start Add options in Select field
		function SelectOptionAdd(ObjectID,Data) {
			if (document.getElementById(ObjectID)) {
				if  (document.getElementById(ObjectID).type != 'select') {
					return;
				}
				var elSel = document.getElementById(ObjectID);
				var arrTmp = Data.split(",");
				for(var j=0;j<arrTmp.length;j++) {
       				if (arrTmp[j]) {
       					var op = document.createElement("OPTION");
        				var arrTmp1 = arrTmp[j].split("=");
          				op.text = arrTmp1[1];
          				op.value = arrTmp1[0];
          				try {
            				elSel.add(op, null); 
           				} catch(ex) {
             				elSel.add(op);
						}
          			}
				}
			}
		}

		// Start Replace options in Select field
		function SelectOptionReplace(ObjectID,Data) {
			if (document.getElementById(ObjectID)) {
				if  ((document.getElementById(ObjectID).type != 'select') && (document.getElementById(ObjectID).type != 'select-one')) {
					return;
				}
				var elSel = document.getElementById(ObjectID);
				//Remove options in Select field
				for (j = elSel.length - 1; j>=0; j--) {
          			elSel.remove(j);
     			}	 
				var arrTmp = Data.split(",");
				for(var j=0;j<arrTmp.length;j++) {
       				if (arrTmp[j]) {
       					var op = document.createElement("OPTION");
        				var arrTmp1 = arrTmp[j].split("=");
          				op.text = arrTmp1[1];
          				op.value = arrTmp1[0];
          				try {
            				elSel.add(op, null); 
           				} catch(ex) {
             				elSel.add(op);
						}
          			}
				}
			}
		}
		
		// Start Clear options in Select field
		function SelectOptionClear(ObjectID) {

			if (document.getElementById(ObjectID)) {

				if  ((document.getElementById(ObjectID).type != 'select') && (document.getElementById(ObjectID).type != 'select-one')) {
					return;
				}

				var elSel = document.getElementById(ObjectID);

				//Remove options in Select field
				for (j = elSel.length - 1; j>=0; j--) {
          			elSel.remove(j);
     			}
			}
		}
		
		// Start Sort options in Select field
		function SelectOptionSort(ObjectID) {
			if (document.getElementById(ObjectID)) {
				if  ((document.getElementById(ObjectID).type != 'select') && (document.getElementById(ObjectID).type != 'select-one')) {
					return;
				}
				var elSel = document.getElementById(ObjectID);
				var arrTexts = new Array();
				for(j=0; j<elSel.length; j++)  {
					arrTexts[j] = elSel.options[j].text;
				}
				arrTexts.sort();
				for(j=0; j<elSel.length; j++)  {
					elSel.options[j].text = arrTexts[j];
					elSel.options[j].value = arrTexts[j];
				}
			}
		}
		
		// Start Add Style to document
		function StyleAdd(Data,ObjectID) {
			if ((ObjectID != null) || (ObjectID != '')) {
				if (document.getElementById('Style_' + ObjectID)) {
					//alert('Script is al ready loaded: ' + ObjectID);
					return;
				} else {
					//alert('Script is not loaded: ' + ObjectID);
				}
			}
			var style = document.createElement('style');
			
			if (style.styleSheet) {  // IE
    			style.styleSheet.cssText = Data;
			} else { // the world
    			var tt1 = document.createTextNode(newdef);
   				style.appendChild(tt1);
			}
			style.setAttribute("type", "text/css");
			document.body.appendChild(style);
		}
		
		
		// Start Add Script to document
		function ScriptAdd(Data,ObjectID) {
			//alert('ObjectID: ' + ObjectID);
			if ((ObjectID != null) || (ObjectID != '')) {
					if (document.getElementById('Script_' + ObjectID)) {
						//alert('Script is al ready loaded: ' + ObjectID);
						return;
					} else {
							//alert('Script is not loaded: ' + ObjectID);
					}
			}
			var script = document.createElement("script");
  			script.text = Data;
			
			if ((ObjectID != null) || (ObjectID != '')) {
				script.setAttribute("id", "Script_" + ObjectID);
			}
  			script.setAttribute("type", "text/javascript");
 			script.setAttribute("language", "JavaScript");
  			document.body.appendChild(script);
		}
})();



