 if(window.attachEvent)
    window.attachEvent("onload",setListeners);

  function setListeners(){
    inputList = document.getElementsByTagName("INPUT");
    for(i=0;i<inputList.length;i++){
      inputList[i].attachEvent("onpropertychange",restoreStyles);
      inputList[i].style.backgroundColor = "";
    }
    selectList = document.getElementsByTagName("SELECT");
    for(i=0;i<selectList.length;i++){
      selectList[i].attachEvent("onpropertychange",restoreStyles);
      selectList[i].style.backgroundColor = "";
    }
  }

  function restoreStyles(){
    if(event.srcElement.style.backgroundColor != "")
      event.srcElement.style.backgroundColor = "";
  }

// END OF GOOGLE FIX

function ajaxUpdater(varURL,varDIV){
	new Ajax.Updater(varDIV, varURL, {evalScripts:true});
}

function ajaxPost(varFORM, varURL_POST, varURL_UPDATE, varDIV){
	var params = Form.serialize($(varFORM));
	new Ajax.Updater(varDIV, varURL_POST, {asynchronous:true, parameters:params});	
	//ajaxUpdater(varURL_UPDATE, varDIV);
}

function popUp(URL, w, h) {
	LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
	
	childWindow=open(URL, "", "toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width="+w+",height="+h+",left ="+LeftPosition+",top="+TopPosition+"");
	if (childWindow.opener == null) childWindow.opener = self;
}

function confirmDelete() {
	OkToGo = false;
	lResult = window.confirm("Are you sure that you want to Delete this Item?");
	if(lResult){
		var confirm;
		confirm=prompt("Please type DELETE in the text box below to remove this form:", "");
		if(confirm=="DELETE")
			return (true);
	}
	
	return (false);
}

String.prototype.trim=function(){
	return this.replace(/^\s*|\s*$/g,'');
}

String.prototype.ltrim=function(){
	return this.replace(/^\s*/g,'');
}

String.prototype.rtrim=function(){
	return this.replace(/\s*$/g,'');
}
function onlyNum(input){

	var num = input.value.replace(/\,/g,'');
	
	if(isNaN(num))
		input.value = input.value.substring(0,input.value.length-1);
		
	num	= input.value;
	
	if(num.length > 0)
		num	= num.trim();
		
	input.value	= num;

}

function toggleLayer(layerName){
	if (document.getElementById) {
    	var targetElement = document.getElementById(layerName);
		if(targetElement.style.display == "")
			hideLayer(layerName);
		else
			showLayer(layerName);
			
	}
}
function showLayer(layerName){
	if (document.getElementById){
    	var targetElement = document.getElementById(layerName);
        targetElement.style.display = '';
    }
}

function hideLayer(layerName){
	if (document.getElementById) {
    	var targetElement = document.getElementById(layerName);
		targetElement.style.display = 'none';
    }
}

/***
switch property detail tabs
***/
function switchTabs(tabOn, numTabs){
	for(i=1; i<= numTabs; i++){
		var tab_a = document.getElementById('tab'+i+'a');
		var tab_b = document.getElementById('tab'+i+'b');
		var tab_c = document.getElementById('tab'+i+'c');
		var tab_d = document.getElementById('tab'+i+'d');
		
		if(tabOn == i){
			tab_a.className = 'tabOn_left';
			tab_b.className = 'tabOn_bg';
			tab_c.className = 'tabOn_right';
			tab_d.className = 'tabOnTxt';
		}
		else{
			tab_a.className = 'tabOff_left';
			tab_b.className = 'tabOff_bg';
			tab_c.className = 'tabOff_right';
			tab_d.className = 'tabOffTxt';
		}
		
	}
}

/***
IMAGE UPLOAD
***/
function PreviewImg(imgFile, defaultID, previewID, upload, previewIMG){    
    
	
	var isIE  = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
	var isSafari  = (navigator.appVersion.indexOf("Safari") != -1) ? true : false;
	field = document.getElementById(upload).value;
	image = document.getElementById(previewIMG);
	path = 'file:///'+ field;
	path = path.replace(/\\/, '/'); // Fix Windows paths
	
	var imgRe = /^.+\.(jpg|jpeg|gif|png)$/i;
	if(path.search(imgRe) != -1){
	
		if(isIE){
			var defPreview = document.getElementById(defaultID);
			var newPreview = document.getElementById(previewID);
	
			defPreview.style.display = 'none';
			newPreview.filters.item("DXImageTransform.Microsoft.AlphaImageLoader").src = imgFile.value;
			newPreview.style.width = "38px";
			newPreview.style.height = "28px";
		}
		else{			
			image.src = '/images/icons/upload_check.gif';
		}
	}
	else{
		alert('Invalid file type selected.');	
	}
}
function preview(upload, previewIMG) {
    var isIE  = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
	var isSafari  = (navigator.appVersion.indexOf("Safari") != -1) ? true : false;
	
	field = document.getElementById(upload).value;
	image = document.getElementById(previewIMG);
	path = 'file:///'+ field;
	path = path.replace(/\\/, '/'); // Fix Windows paths
	
	// show the image preview
	var imgRe = /^.+\.(jpg|jpeg|gif|png)$/i;
	if(path.search(imgRe) != -1){
		if(path.search(/^http:\/\//i) != -1){
			image.src = '/images/icons/upload_check.gif';
		}
		else if(isIE){
			image.src = '/images/icons/upload_check.gif';
		}
		else
			image.src = '/images/icons/upload_check.gif';
	}
	else{
		alert('Invalid file type selected.');
		document.getElementById(upload).value='';
		document.getElementById(upload).focus();
	}
	
}

function isAlphaKey(e) {
   var k;
   document.all ? k = e.keyCode : k = e.which;
   return ((k > 64 && k < 91) || (k > 96 && k < 123) || (k > 47 && k < 58)|| k == 8);
}

function extractAlpha(str) {
   return str.replace(/[^a-z]/gi,"");
}
