dom = (document.getElementById) ? 1 : 0;

var TxtId = "";

function ActivateField(what) { if (dom) {
	what.style.borderColor = '#77aaff';
	what.style.backgroundColor = '#ddeeff';
} }

function DeactivateField(what) { if (dom) {
	what.style.borderColor = '';
	what.style.backgroundColor = '';
} }

function ButtonFocus(what) { if (dom) {
	what.style.borderColor = '#ff9933';
	what.style.backgroundColor = '#bbddff';
} }

function ButtonBlur(what) { if (dom) {
	what.style.borderColor = '';
	what.style.backgroundColor = '';
} }

function ExpandHideSection(SectionExpandImage, RowSection) {
	if (document.getElementById(SectionExpandImage).src == ButtonIconURL + 'blue_arrow_up_16.png') {
		document.getElementById(RowSection).className = 'RowSectionHide';
		document.getElementById(SectionExpandImage).src = ButtonIconURL + 'blue_arrow_down_16.png';
	} else {
		document.getElementById(RowSection).className = 'RowSectionShow';
		document.getElementById(SectionExpandImage).src = ButtonIconURL + 'blue_arrow_up_16.png';
	}
}

function UpdateCheckValue(CheckboxField, HiddenField) {
	if (CheckboxField.checked == true) {
		document.getElementById(HiddenField).value = '1';
	} else {
		document.getElementById(HiddenField).value = '0';
	}
}

function ComboChange(DropDownID, TextBoxID, Custom) {
	if (document.getElementById(DropDownID).value == Custom) {
		document.getElementById(TextBoxID).value = '';
		document.getElementById(TextBoxID).style.visibility = 'visible';
		document.getElementById(TextBoxID).focus();
	} else {
		document.getElementById(TextBoxID).style.visibility = 'hidden';
		document.getElementById(TextBoxID).value = document.getElementById(DropDownID).value;
	}
}

function ValidateSubmit(FormName, SubmitID) {
	var VF = 'ValidateForm' + FormName + '()';
	if (eval(VF) == true) {
		document.getElementById(SubmitID).disabled = true;
		var FN = 'Form' + FormName;
		document.getElementById(FN).submit();
	}
}

function ValidateAjax(FormName, AjaxURL) {
	var VF = 'ValidateForm' + FormName + '()';
	if (eval(VF) == true) {
		var AD = 'AjaxDataURL' + FormName + '()';
		var AjaxData = eval(AD);
		var Message = 'Saving...';
		AjaxURL += AjaxData;
		if (FormName == 'DomainInputForm') {
			Message = 'Checking Availability...';
		}
		MyAjax(AjaxURL, 'JavaScript', Message);
		//alert(AjaxURL);
	}
}

function DeleteAjax(FormName, AjaxURL) {
	if (document.getElementById('T').value == '3') {
		AjaxURL += '?T=4&ID=' + document.getElementById('ID').value;
		PromptBox('Are you sure you want to delete?', 'Delete?', 'delete.png', "MyAjax('" + AjaxURL + "', 'JavaScript', 'Deleting...');");
		//alert(AjaxURL);
	}
}

function getCheckedValue(radioObj) {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}

function NumbersOnly(e) {
	var key;
	var keychar;
	if (window.event) {
		key = window.event.keyCode;
	} else if (e) {
		key = e.which;
	} else {
		return true;
	}
	keychar = String.fromCharCode(key);
	// control keys
	if ((key==null) || (key==0) || (key==8) || (key==9) || (key==13) || (key==27)) {
		return true;
	// numbers
	} else if ((("0123456789").indexOf(keychar) > -1)) {
		return true;
	} else {
		return false;
	}
}

function LettersOnly(e) {
	var key;
	var keychar;
	if (window.event) {
		key = window.event.keyCode;
	} else if (e) {
		key = e.which;
	} else {
		return true;
	}
	keychar = String.fromCharCode(key);
	keychar = keychar.toLowerCase();
	// control keys
	if ((key==null) || (key==0) || (key==8) || (key==9) || (key==13) || (key==27)) {
		return true;
	// alphas
	} else if ((("abcdefghijklmnopqrstuvwxyz").indexOf(keychar) > -1)) {
		return true;
	} else {
		return false;
	}
}

function LettersNumbersOnly(e) {
	var key;
	var keychar;
	if (window.event) {
		key = window.event.keyCode;
	} else if (e) {
		key = e.which;
	} else {
		return true;
	}
	keychar = String.fromCharCode(key);
	keychar = keychar.toLowerCase();
	// control keys
	if ((key==null) || (key==0) || (key==8) || (key==9) || (key==13) || (key==27)) {
		return true;
	// alphas and numbers
	} else if ((("abcdefghijklmnopqrstuvwxyz0123456789").indexOf(keychar) > -1)) {
		return true;
	} else {
		return false;
	}
}

function UsernameCharsOnly(e) {
	var key;
	var keychar;
	if (window.event) {
		key = window.event.keyCode;
	} else if (e) {
		key = e.which;
	} else {
		return true;
	}
	keychar = String.fromCharCode(key);
	keychar = keychar.toLowerCase();
	// control keys
	if ((key==null) || (key==0) || (key==8) || (key==9) || (key==13) || (key==27)) {
		return true;
	// alphas and numbers
	} else if ((("abcdefghijklmnopqrstuvwxyz0123456789_-.").indexOf(keychar) > -1)) {
		return true;
	} else {
		return false;
	}
}

function DomainCharsOnly(e) {
	var key;
	var keychar;
	if (window.event) {
		key = window.event.keyCode;
	} else if (e) {
		key = e.which;
	} else {
		return true;
	}
	keychar = String.fromCharCode(key);
	keychar = keychar.toLowerCase();
	// control keys
	if ((key==null) || (key==0) || (key==8) || (key==9) || (key==13) || (key==27)) {
		return true;
	// alphas and numbers
	} else if ((("abcdefghijklmnopqrstuvwxyz0123456789-").indexOf(keychar) > -1)) {
		return true;
	} else {
		return false;
	}
}

function EmailAddressOnly(e) {
	var key;
	var keychar;
	if (window.event) {
		key = window.event.keyCode;
	} else if (e) {
		key = e.which;
	} else {
		return true;
	}
	keychar = String.fromCharCode(key);
	keychar = keychar.toLowerCase();
	// control keys
	if ((key==null) || (key==0) || (key==8) || (key==9) || (key==13) || (key==27)) {
		return true;
	// alphas and numbers
	} else if ((("abcdefghijklmnopqrstuvwxyz0123456789@.!#$%&'*+-/=?^_`{|}~").indexOf(keychar) > -1)) {
		return true;
	} else {
		return false;
	}
}

function ShowCal(MyId, TodayDay, TodayMonth, TodayYear, PopUpX, PopUpY) {
	document.getElementById('DimPage').style.visibility = 'visible';
  TxtId = MyId;
  var TxtDate = document.getElementById(MyId).value;
  var DD = TodayDay;
  var MM = TodayMonth;
  var YYYY = TodayYear;

  if (TxtDate != "" && TxtDate != "//") {
    DD = TxtDate.charAt(0) + TxtDate.charAt(1);
    MM = TxtDate.charAt(3) + TxtDate.charAt(4);
    YYYY = TxtDate.charAt(6) + TxtDate.charAt(7) + TxtDate.charAt(8) + TxtDate.charAt(9);
  }
  MM--;

  document.getElementById("Months").selectedIndex = MM;

  var Cont = new Boolean(1);
  var Cnt = 0;
  var TempYYYY = '';

  while (Cont) {
    TempYYYY = document.getElementById("Years").options[Cnt].value;
    if (TempYYYY == YYYY) {
      Cont = 0;
	    document.getElementById("Years").selectedIndex = Cnt;
    }
    Cnt++;
  }

  document.getElementById('Calendar').style.left = PopUpX + "px";
  document.getElementById('Calendar').style.top = PopUpY + "px";
  document.getElementById('Calendar').style.zIndex = "20";
  document.getElementById('Calendar').style.visibility = "visible";
  ShowDates();
}

function HideCal() {
  document.getElementById('Calendar').style.visibility = "hidden";
  document.getElementById('DimPage').style.visibility = 'hidden';
}

function GetDaysInMonth(IMonth, IYear) {
  var IDate = new Date(IYear, IMonth, 0);
  return IDate.getDate();
}

function ShowDates() {
  var M = document.getElementById("Months");
  var MyMonth = M.options[M.selectedIndex].value;
  var Y = document.getElementById("Years");
  var MyYear = Y.options[Y.selectedIndex].value;
  var MyDate = new Date();
  MyDate.setDate(01);
  MyDate.setMonth(MyMonth);
  MyDate.setFullYear(MyYear);
  var MyDay = MyDate.getDay();
  var TempMonth = MyMonth;
  TempMonth++;
  var DaysInMonth = GetDaysInMonth(TempMonth, MyYear);
  if (TempMonth <= 9) {
    TempMonth = "0" + TempMonth;
  }
  var X = document.getElementById('Dates').rows;
  var Y = X[0].cells;
  var CurDay = 1;
  var TempDate = "";
  var TempDay = ""
  var AltCount = 1;

  for (Cnt1 = 1; Cnt1 <= 6; Cnt1++) {
    Y = X[Cnt1].cells;
    for (Cnt2 = 0; Cnt2 <= 6; Cnt2++) {
      if (Cnt1 == 1 && Cnt2 < MyDay || CurDay > DaysInMonth) {
        Y[Cnt2].innerHTML = "&nbsp;";
      } else {
	      TempDay = CurDay;
		    if (TempDay <= 9) {
          TempDay = "0" + TempDay;
        }
	    TempDate = TempDay + "/" + TempMonth + "/" + MyYear;
        Y[Cnt2].innerHTML = "<a class=\"DateLink" + AltCount + "\" href=\"\" onclick=\"SelectDate('" + TempDate + "'); return false;\" onmouseover=\"window.status='" +  TempDate + "'; return true;\" onmouseout=\"window.status=''; return true;\">" + CurDay + "</a>";
        CurDay++;
		if (AltCount == 1) {
			AltCount = 2;
		} else {
			AltCount = 1;
		}
      }
    }
  }
}

function SelectDate(MySelectedDate) {
	document.getElementById(TxtId).value = MySelectedDate;
	document.getElementById('text_' + TxtId).innerHTML = MySelectedDate;
	HideCal();
	//alert(document.getElementById(TxtId).value);
}

function NoneCal() {
	document.getElementById(TxtId).value = '';
	document.getElementById('text_' + TxtId).innerHTML = '';
	HideCal();
	//alert(document.getElementById(TxtId).value);
}
