function required (id) {
	var errorDiv = document.getElementById(id+'Error');
	var elem = document.getElementById(id);
	if (!elem.value.length) {
		errorDiv.innerHTML = capWords(id.replace('_',' '))+' is required';
		elem.style.backgroundColor = '#FFEEEE';
		return 1;
	} else {
		errorDiv.innerHTML = '';
		elem.style.backgroundColor = '#FFFFFF';
	}
}

function clearErrors (id) {
	var errorDiv = document.getElementById(id+'Error');
	var elem = document.getElementById(id);
	errorDiv.innerHTML = '';
	elem.style.backgroundColor = '#FFFFFF';
}

function isValidEmail(id,blur) {
	var errorDiv = document.getElementById(id+'Error');
	var elem = document.getElementById(id);
	email = elem.value;
	AtPos = email.indexOf("@");
	StopPos = email.lastIndexOf(".");
	if (email == "") {
		if (blur) {
			return 1;
		}
	} else if (AtPos == -1 || StopPos == -1) {
		if (blur) {
			return 1;
		}
	} else if (StopPos < AtPos) {
		if (blur) {
			return 1;
		}
		elem.style.backgroundColor = '#FFFFEE';
	} else if (StopPos - AtPos == 1) {
		if (blur) {
			return 1;
		}
	} else {
		return 0;
	}
}

function capWords(str){ 
   var words = str.split(" "); 
   for (var i=0 ; i < words.length ; i++){ 
      var testwd = words[i]; 
      var firLet = testwd.substr(0,1); 
      var rest = testwd.substr(1, testwd.length -1) 
      words[i] = firLet.toUpperCase() + rest 
   } 
   return words.join(" "); 
}

function translationControl (action) {
	if (action == 'hide') {
		setCookie('showTranslation','hide',90);
		document.getElementById('english').className='translationHidden';
		document.getElementById('translationControl').innerHTML='Show Translation';
		document.getElementById('translationControl').href="javascript:translationControl('show');";
	} else if (action == 'show') {
		setCookie('showTranslation','show',90);
		document.getElementById('english').className='translationShown';
		document.getElementById('translationControl').innerHTML='Hide Translation';
		document.getElementById('translationControl').href="javascript:translationControl('hide');";
	}
}

function showMenu (id) {
	if (id != '') {
		var item = document.getElementById(id);
		var subMenu = document.getElementById(id+'Submenu');
		var topPx = item.offsetTop;
		var leftPx = item.offsetLeft;
		var heightPx = item.offsetHeight;
		var widthPx = item.offsetWidth;
		subMenu.style.display = 'block';
		subMenu.style.left=(leftPx-1)+'px';
		subMenu.style.width=widthPx+'px';
		subMenu.style.top=(topPx+heightPx-1)+'px';
	}
}

function setCookie(c_name,value,expiredays) {
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie=c_name+ "=" +escape(value)+
	((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}

function getCookie(c_name) {
	if (document.cookie.length>0) {
		c_start=document.cookie.indexOf(c_name + "=");
		if (c_start!=-1) {
			c_start=c_start + c_name.length+1;
			c_end=document.cookie.indexOf(";",c_start);
			if (c_end==-1) c_end=document.cookie.length;
				return unescape(document.cookie.substring(c_start,c_end));
			} 
		}
	return "";
}

function ajaxLoadObject (url, divID) {
	makeHttpRequest ( url, 'noFadeDiv', false, divID );
}

function makeHttpRequest(url, callback_function, return_xml, divID) {
   var http_request = false;
   if (window.XMLHttpRequest) { // Mozilla, Safari,...
       http_request = new XMLHttpRequest();
       if (http_request.overrideMimeType) {
           http_request.overrideMimeType('text/xml');
       }
   } else if (window.ActiveXObject) { // IE
       try {
           http_request = new ActiveXObject("Msxml2.XMLHTTP");
       } catch (e) {
           try {
               http_request = new ActiveXObject("Microsoft.XMLHTTP");
           } catch (e) {}
       }
   }

   if (!http_request) {
       alert('Unfortunatelly your browser doesn\'t support this feature.<br/> Please upgrade to <a href="http://www.mozilla.com">Mozilla</a>.');
       return false;
   }
   http_request.onreadystatechange = function() {
       if (http_request.readyState == 4) {
           if (http_request.status == 200) {
               if (return_xml) {
                   eval(callback_function + '(http_request.responseXML,divID)' );
               } else {
                   eval(callback_function + '(http_request.responseText,divID)' );
               }
           } else {
               document.getElementById('ERROR_BOX').innerHTML =  'There was a problem with the request.(Code: ' + http_request.status + ') URL:' + url;
           }
       }
   }
   http_request.open('GET', url, true);
   http_request.send(null);
}

function noFadeDiv (response, divID) {
	obj = document.getElementById(divID);
	if (obj && response) {
		obj.innerHTML = response;
	}
}

function is_array( mixed_var ) {
    return ( mixed_var instanceof Array );
}