// Form Functioins
	function setFocus(obj){
		var obj = getObject(obj);
		obj.style.background="#FFE8AA";
		obj.focus();
		//obj.select();
		return false;
	}
	function loseFocus(obj){
		var obj = getObject(obj);
		obj.style.background="#FFFFFF";
		//obj.focus();
		//obj.select();
		return false;
	}

	function isChecked(obj){
		var obj = getObject(obj);
		if (obj.checked) return true;
		else return false;
	}

	function v_uploadField(obj){
		var error = false;
		var obj = getObject(obj);
		if (obj.value==""){ error = "<li>Empty Upload Field</li>"; }
		if (obj.value.indexOf(".")<0){ error = "<li>Invalid target file, the file should have a valid extension</li>"; }
		return error;
	}

// General Functions
	function getObject(obj){
		var error = false;
		if (typeof(obj)!="object"){
			obj = document.getElementById(obj);
		}
		if (typeof(obj)!="object"){
			error = "Invalid target object ( " + obj + " )";
		}
		if (error){
			alert(error);
			return false;
		}else{
			return obj;
		}
	}

	function showPreview(obj, target, param){
		if(!obj){
			alert("Missing source object.");
			return false;
		}
		if(!target){
			alert("Target not found for preview.");
			return false;
		}
		var targetObj = getObject(target);
		var sourceObj = getObject(obj);
		targetObj.src = sourceObj.value;
		if (param){
			targetObj.width = (param.w) ? param.w : targetObj.width;
			targetObj.height = (param.h) ? param.h : targetObj.height;
		}
	}


	function changeClass(id, newClass) {
		id.className=newClass;
		//	identity=document.getElementById(id);
		//	identity.className=newClass;
	}
	/*
		function to display Alert Message in box on top of page.
	*/
	function displayAlert(strMsg, strTitle, alertBox){
		if (!alertBox){ var alertBox = "alertData"; }
		var error= "";
		if (strMsg=="" || !strMsg){	error+= "Empty Message"; }
		// Checking Alt box.
		var altBox = document.getElementById(alertBox);
		if (typeof(altBox)!="object"){ error += alertBox + " < Objet not found or not an Object"; }
	
		if (error==""){
			var alertWin = document.getElementById("alertWin");
			// creating Message title.
			if (typeof(strTitle)=="undefined" || strTitle=="" || strTitle==" "){ strTitle = ""; }
			if (strTitle=='none'){ strTitle = ''; }
			var strTitle = '<div id="alertTitle">'+strTitle+'</div>';
		
			// Creating Message.
			var strMessage = '<div id="strMessage">'+strMsg+'</div>';	
		
			// display Message Box.
			shObj(alertWin, 'block', true);
			altBox.innerHTML = strTitle + strMessage;
		}
	}
/*
function displayAlert(strMsg, strTitle, alertBox){
	if (!alertBox){ var alertBox = "alertData"; }
	var error= "";
	if (strMsg=="" || !strMsg){	error+= "Empty Message"; }
	// Checking Alt box.
	var altBox = document.getElementById(alertBox);
	if (altBox!="[object]"){ error += alertBox + " < Objet not found"; }

	if (error==""){
		// creating Message title.
		if (strTitle==undefined){ strTitle = "SYSTEME MESSAGE"; }
		var strTtitle = '<div id="alertTitle">';
		strTtitle += strTitle;
		strTtitle += '</div>';
	
		// Creating Message.
		var strMessage = '<div id="strMessage">';
		if (strMsg.indexOf("<li>")>-1 && strMsg.indexOf("<ul>")<0){
			alert("yes");
			strMessage += "<ul>" + strMsg + "</ul>";
		}else{
			strMessage += strMsg;
		}
		strMessage += '</div>';	
	
		// display Message Box.
		var alertWin = document.getElementById("alertWin");
		shObj(alertWin, 'block', true);
		altBox.innerHTML = strTtitle + strMessage;
	}
}
*/
//shObj(Object To Treat, displayAs, [bolen])
	function shObj(obj, displayAs, force){
		//alert(obj);
		var error = false;
		var temp_obj = getObject(obj);
		if (!temp_obj){ alert("( "+obj+" ) not found or not an object\n"); return false; }else{
			var currentStyle = temp_obj.style.display;
		}

		if (force && !displayAs){ alert("No display status defined \nForce display can not be applied to ( "+obj+" )"); return false; }

		if (!displayAs){
			var currentStyle = temp_obj.style.display;
			//if (currentStyle==('' || 'none') || !currentStyle){
			if (currentStyle=='none'){
				displayAs = "block";
			}else{
				displayAs = "none";
			}
		}

		if (displayAs && !force){
			var currentStyle = temp_obj.style.display;
			if (currentStyle==displayAs && displayAs!='none'){
				displayAs = "none";
			}
		}
		//alert(obj+" > " + currentStyle + " < " + displayAs);
		temp_obj.style.display = displayAs;
		
		var res = (displayAs == "none") ? false : true;
		return res;
	}



	/*////////////////////
		function hides the validate object if validate is not false. also displays the alert message if any
		USAGE:
			checkReturn(saveFile('fileEditor'), 'Error Here'[, this]);
			
		TYPES:
			response : bolen
			strAlert: string | false
			validate : object | false
	/*////////////////////
	function checkReturn(response, strAlert, target){
		//alert(" response > " + response + "\n target > " + target + "\n strAlert > " + strAlert);
		if (target){
			shObj(target, "none", 1);
			if (strAlert){ displayAlert(strAlert); }
		}
		return response;
	}



	function isEmailValid(email){
		if(email == null){
			return false;
		}
	
		var atPos = email.indexOf("@");
	
		if(
			atPos < 1 ||
			email.indexOf(".", atPos) == -1
		){
			return false
		}
	
		var login = email.substring(0, atPos);
		var domain = email.substring(atPos + 1, email.length);
	
		// Regexp declarations
		var atom = "\[^\\s\\(\\)><@,;:\\\\\\\"\\.\\[\\]\]+";
		var word = "(" + atom + "|(\"[^\"]*\"))";
		var loginRE = new RegExp("^" + word + "(\\." + word + ")*$");
	
		for (i = 0; i < login.length; i++){
			if (login.charCodeAt(i) > 127){
				return false;
			}
		}
	
		if (!login.match(loginRE)){
			return false;
		}
	
		return isDomainValid(domain);
	}

	function isDomainValid(domain){
		if(typeof(domain) != 'string'){
			return false;
		}
	
		for (i = 0; i < domain.length; i++){
			if (domain.charCodeAt(i) > 127){
				return false;
			}
		}
	
		var ipDigit = "(0?0?\\d|[01]?\\d\\d|2[0-4]\\d|25[0-6])";
		var ipRE = new RegExp("^" + ipDigit + "\\." + ipDigit + "\\." + ipDigit + "\\." + ipDigit + "$");
	
		if (ipRE.test(domain)) {
			return true;
		}
	
		var domains = domain.split(".");
	
		if (domains.length < 2) {
			return false;
		}
	
		for (i = 0; i < domains.length - 1; i++) {
			if (!(/^[a-zA-Z0-9\-]+$/).test(domains[i])) {
				return false;
			}
		}
	
		if(domains[domains.length-2].length < 2){
			return false;
		}
	
		if (!(/^[a-zA-Z]{2,}$/).test(domains[domains.length-1])){
			return false;
		}
	
		return true;
	}


	function maxLength(str, allowedNum){
		if (str.length>allowedNum){
			alert ("Max characters allowed: 255");
			return false;
		}else{
			return true;
		}
	}


	function key(param){
		var str = param.from.value;
			var regExp = /[!_@#$%^&*()|?;"_+=~`<>, \-\'\\\/]/g; // Match all these char
			str = str.replace(regExp,"-");
			str = str.replace(/[-]+/g,"-"); // replace all continuing instances with one
			str = str.toLowerCase(); // replace all continuing instances with one
		if (!param.to){ return str ; }
		else{ param.to.value = str; }
	}






/////////////////////////////////////////////
/////// Simple Ajax
/*
	USAGE
	function tabResponse(response){
		alert(response);
	}
	
	function editThis(param){
		var qStr = "&myId="+param.myId;
		simpleAjaxRequest(param.targetFile+"?"+qStr, {callBackFunction:'tabResponse',noCache:true});
	}
	
	HTML
	=====
	<a href="Javascript:void(0)" onclick="editThis({targetFile:'myfile.php',myId:'22'})">Click</a>

	myfile.php
	==========
	<?
		echo "Hello world";
		echo "<h4>".$_GET['myId']."</h4>";
	?>

*/

/////////////////////////////////////////////
	//this.ajaxRequest("color.php?date="+Math.random(555555), {callBackFunction:'writeColorBox',noCache:true});
	//simpleAjaxRequest("file.php", {callBackFunction:'getResponse',noCache:true});
	function simpleAjaxRequest(target, param){
		//alert("simpleAjaxRequest called");
		var method = (!method) ? "GET" : method;
		(!param) ? alert("param are missing") : true;
		var http = false;
	
		if(navigator.appName == "Microsoft Internet Explorer") {
			http = new ActiveXObject("Microsoft.XMLHTTP");
		} else {
			http = new XMLHttpRequest();
		}
	
		if (param.noCache){
			target = (target.indexOf("?")>-1) ?  target+"&ajaxRand="+Math.random(999999) : target+"?ajaxRand="+Math.random(999999);
		}
	
		http.open(method, target);
		http.onreadystatechange=function() {
			if(http.readyState == 4 && http.status == 200) {
				//var obj = ([param.obj+"."+param.callBackFunction]);
				eval(param.callBackFunction)(http.responseText);
			}
		}
		http.send(null);
	}


