function mSelectTab(oSender){
	var oTbs = document.getElementById('uptbs'), aTbs = oIThelp.getAllElementsByClassName(oTbs, 'userprofile_tab'), oActBody = document.getElementById(oIThelp.mGetAttribute(oSender, 'tabbody'));
	for(var o = 0; o < aTbs.length; o++){
		if(aTbs[o].className.contains('active')){
			oIThelp.mRemoveClass(aTbs[o], 'active');
			oIThelp.mRemoveClass(document.getElementById(oIThelp.mGetAttribute(aTbs[o], 'tabbody')), 'ith_visible');
			oIThelp.mAddClass(document.getElementById(oIThelp.mGetAttribute(aTbs[o], 'tabbody')), 'ith_not_visible');
		}
	}
	oIThelp.mAddClass(oSender, 'active');
	oIThelp.mRemoveClass(oActBody, 'ith_not_visible');
	oIThelp.mAddClass(oActBody, 'ith_visible');
}

function mSetVisibility(oSender){
	var sFieldId = oIThelp.mGetAttribute(oSender, 'visiblefield'), sClassName = oSender.className == 'lock_on' ? 'lock_off' : 'lock_on', sValue = sClassName == 'lock_on' ? 'no' : 'yes';
	oSender.className = sClassName;
	document.getElementById(sFieldId).value = sValue;
}

function mUserProfileValidate(){
	var aFields = oIThelp.getAllElementsByClassName(document.getElementById('uptbs'), 'field'), sMessage='';
	for(var f = 0; f < aFields.length; f++){
		var oField = aFields[f], validateStr = oIThelp.mGetAttribute(oField, 'validate');
		if(validateStr){
			var oInput = oField.getElementsByTagName('INPUT')[0], oTitle = oIThelp.getAllElementsByClassName(oField, 'fieldtitle')[0];
			if(oTitle.className.contains('invalid')) oIThelp.mRemoveClass(oTitle, 'invalid');
			var aValidation = validateStr.split(' ');
			for(var v = 0; v < aValidation.length; v++){
				var retVal = '';
				switch ( aValidation[v].trim() ) {
					case "valid_variable"	: if (oInput.value!='' && !/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(oInput.value)) retVal=oIThelp.mGetLocalName('VALIDATION_VARIABLE'); break;
					case "email"			: if (oInput.value!='' && !/^([a-zA-Z0-9_\-])+(\.([a-zA-Z0-9_\-])+)*@((\[(((([0-1])?([0-9])?[0-9])|(2[0-4][0-9])|(2[0-5][0-5])))\.(((([0-1])?([0-9])?[0-9])|(2[0-4][0-9])|(2[0-5][0-5])))\.(((([0-1])?([0-9])?[0-9])|(2[0-4][0-9])|(2[0-5][0-5])))\.(((([0-1])?([0-9])?[0-9])|(2[0-4][0-9])|(2[0-5][0-5]))\]))|((([a-zA-Z0-9])+(([\-])+([a-zA-Z0-9])+)*\.)+([a-zA-Z])+(([\-])+([a-zA-Z0-9])+)*))$/.test(oInput.value)) retVal=oIThelp.mGetLocalName('VALIDATION_EMAIL'); break;
					case "int"			: if (oInput.value!='' && !/^[0-9]+$/.test( oElement.value )) retVal=oIThelp.mGetLocalName('VALIDATION_INT'); break;
					case "required"		: if (oInput.value=='') retVal=oIThelp.mGetLocalName('VALIDATION_REQUIRED'); break;
					case "requiredc"	: if (!oInput.checked) retVal=oIThelp.mGetLocalName('VALIDATION_REQUIRED'); break;
					/*case "password"		: if (oInput.value!=''){
						var sPassword = oInput.value;
						if( ! /^\w*(?=\w*\d)\w*$/.test(sPassword)) {retVal = oIThelp.mGetLocalName('VALIDATION_PASSWORD'); };
						if( ! /^\w*(?=\w*[a-z])\w*$/.test(sPassword)) {retVal = oIThelp.mGetLocalName('VALIDATION_PASSWORD'); };
						if( ! /^\w*(?=\w*[A-Z])\w*$/.test(sPassword)) {retVal = oIThelp.mGetLocalName('VALIDATION_PASSWORD'); };
						if( ! /^.{6,50}$/.test(sPassword)) {retVal = oIThelp.mGetLocalName('VALIDATION_PASSWORD'); };
					}
					break;*/
				}
				if(retVal != ''){
					oIThelp.mAddClass(oTitle, 'invalid');
					sMessage += retVal + ': ' + (oClient.bIE ? oTitle.innerText : oTitle.textContent) + '\n';
				}
			}
		}
	}
	var oPw = document.getElementById('basic_password'), oRpw = document.getElementById('basic_retypepassword');
	if( oPw.value != oRpw.value ){
		sMessage += oIThelp.mGetLocalName('PW_DOES_NOT_MATCH');
	}
		
	return sMessage;
}

function mUserRegistration(){
	var sMessage = mUserProfileValidate();
	if(sMessage != ''){
		alert(sMessage);
		return false;
	}
	document.getElementById('regaction').value = 'registration';
	if(theForm) theForm.submit();
	else document.forms[0].submit();
}

function mUserJoin(){
	document.getElementById('regaction').value = 'userjoin';
	if(theForm) theForm.submit();
	else document.forms[0].submit();
}

function mShowCalendar(oSender) {
	//oInput, oImg, format, showsTime, showsOtherMonths, oAttachElement
  var oInput = document.getElementById(oIThelp.mGetAttribute(oSender, 'input'));
  var oImg = oSender;
  var oAttachElement = document.getElementById(oIThelp.mGetAttribute(oSender, 'attachinput'));
  oAttachElement.uniqueFormat = oIThelp.mGetAttribute(oAttachElement, 'format');
  var format = oIThelp.mGetAttribute(oSender, 'format');
  var showsTime = null;
  var showsOtherMonths = true;
  
  if (_dynarch_popupCalendar != null) {
	// we already have some calendar created
	_dynarch_popupCalendar.hide();                 // so we hide it first.
  } else {
	// first-time call, create the calendar.
	var cal = new ith_Calendar(1, null, 
		function(cal, date) {
			cal.sel.value=date; 
			if (cal.selAE!=null) cal.selAE.value=cal.date.print(cal.selAE.uniqueFormat); 
			if (cal.dateClicked) cal.callCloseHandler();
		},
		function(cal) {cal.hide(); _dynarch_popupCalendar = null;} 
	);
	// uncomment the following line to hide the week numbers
	// cal.weekNumbers = false;
	if (typeof showsTime == "string") {
	  cal.showsTime = true;
	  cal.time24 = (showsTime == "24");
	}
	if (showsOtherMonths) {
	  cal.showsOtherMonths = true;
	}
	_dynarch_popupCalendar = cal;                  // remember it in the global var
	cal.setRange(1900, 2070);        // min/max year allowed.
	cal.create();
  }
  _dynarch_popupCalendar.setDateFormat(format);    // set the specified date format
  if(oInput.value.trim() != '')
	_dynarch_popupCalendar.parseDate(oInput.value);      // try to parse the text in field
  _dynarch_popupCalendar.sel = oInput;
  _dynarch_popupCalendar.selAE = oAttachElement;
  
  // the reference element that we pass to showAtElement is the button that
  // triggers the calendar.  In this example we align the calendar bottom-right
  // to the button.
  _dynarch_popupCalendar.showAtElement(oImg, 'br');        // show the calendar

  return false;
}

