function Check(e,mode){
  if (mode == "check"){
  	e.checked = true;
  } else {
  	e.checked = false;
  }
  Highlight(e,mode);
}

function SetAll(mode){
  var dl = document.dumpList;
  var len = dl.elements.length;
  for (var i = 0; i < len; i++){
  	var e = dl.elements[i];
  	if (e.name.indexOf("chk") == 0){
  		Check(e,mode);
  	}
  }
}

function Highlight(e,mode){
  var r = null;
  r = e.parentElement.parentElement;
  if (r){
  	if (mode == "check"){
  		r.className = "rowhighlighted";
  	}	else{
  		r.className = "rownormal";
  	}
  }
}

function Toggle(e){
  if (e.checked){
  	Highlight(e,"check");
  } else {
  	Highlight(e,"clear");
  }
}

function SetAction1Chosen (){
  if (document.frmAction1.listAction1.value != "") {
  	var dl = document.dumpList;
  	dl.actionchosen.value = document.frmAction1.listAction1.value;
  	dl.submit();
  } else {
  	alert("Please select an action");
  }
}

function SetAction2Chosen (){
  if (document.frmAction2.listAction2.value != "") {
  	var dl = document.dumpList;
  	dl.actionchosen.value = document.frmAction2.listAction2.value;
  	dl.submit();
  } else {
  	alert("Please select an action");
  }
}

function submitViaEnter(evt){
  evt = (evt) ? evt : event;
  var target = (evt.target) ? evt.target : evt.srcElement;
  var form = target.form;
  var charCode = (evt.charCode) ? evt.charCode:
    ((evt.which) ? evt.which : evt.keyCode);
  if (charCode == 13 || charCode == 3){
    form.submit();
    return false;
  }
}

function pause(numberMillis){
  //var dialogScript =
  //       'window.setTimeout(' +
  //       ' function () { window.close(); }, ' + numberMillis + ');';
  //var result =
  //window.showModalDialog(
  //       'javascript:document.writeln(' +
  //        '"<script>' + dialogScript + '<' + '/script>")');
}

function pokeList(iListNo,cListDetail){
  if (iListNo == 1) {
    parent.frmLists.list1.value=cListDetail;
  } else if (iListNo == 2) {
    parent.frmLists.list2.value=cListDetail;
  } else if (iListNo == 3) {
    parent.frmLists.list3.value=cListDetail;
  }
}

function alter(object) {
  object.target = "postframe";
  return true;
}

function trimAll(sString) {
  while (sString.substring(0,1) == ' ') {
    sString = sString.substring(1, sString.length);
  }
  while (sString.substring(sString.length-1, sString.length) == ' ') {
    sString = sString.substring(0,sString.length-1);
  }
  return sString;
}

function insertFlash(cDivId, iWidth, iHeight, cSwf, cFlashVars) {
  var d = document.getElementById(cDivId);
  d.innerHTML =
    '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width=' + iWidth + ' height=' + iHeight +'><param name="movie" value="' + cSwf + '"><param name="quality" value="high"><param name="FlashVars" value="' + cFlashVars + '"><embed src="' + cSwf + '" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width=' + iWidth + ' height=' + iHeight + '></embed></object>';
}

var isLoaded = false;
function init() {
  isLoaded = true;
}

function showHideElement(source,img,target) {
  sourceElem = document.getElementById(source);
  imgElem = document.getElementById(img);
  targetElem = document.getElementById(target);
  if (imgElem.src.match("hide")) {
    targetElem.style.display = "none";
    imgElem.src = "images/website/icon_show.jpg";
  } else {
    targetElem.style.display = "";
    imgElem.src = "images/website/icon_hide.jpg";
  }
}

function returnToTab() {
  //alert(event.keyCode);
  if(event.keyCode==13) event.keyCode=9;
}

var dv_dtCh= "/";
var dv_minYear=1900;
var dv_maxYear=2100;

function dv_isInteger(s){
	var i;
  for (i = 0; i < s.length; i++){
      // Check that current character is number.
      var c = s.charAt(i);
      if (((c < "0") || (c > "9"))) return false;
  }
  // All characters are numbers.
  return true;
}

function dv_stripCharsInBag(s, bag){
	var i;
  var returnString = "";
  // Search through string's characters one by one.
  // If character is not in bag, append to returnString.
  for (i = 0; i < s.length; i++){
      var c = s.charAt(i);
      if (bag.indexOf(c) == -1) returnString += c;
  }
  return returnString;
}

function dv_daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
  // EXCEPT for centurial years which are not also divisible by 400.
  return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}

function dv_daysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
  }
  return this;
}

function dv_isDate(dtStr){
	var daysInMonth = dv_daysArray(12)
	var pos1=dtStr.indexOf(dv_dtCh)
	var pos2=dtStr.indexOf(dv_dtCh,pos1+1)
	var strDay=dtStr.substring(0,pos1)
	var strMonth=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
		return 2
	}
	if (strMonth.length<1 || month<1 || month>12){
		return 3
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>dv_daysInFebruary(year)) || day > daysInMonth[month]){
		return 4
	}
	if (strYear.length != 4 || year==0 || year<dv_minYear || year>dv_maxYear){
		return 5
	}
	if (dtStr.indexOf(dv_dtCh,pos2+1)!=-1 || dv_isInteger(dv_stripCharsInBag(dtStr, dv_dtCh))==false){
		return 6
	}
  return 1
}

function dv_validateDate(dateFld,label){
  if (dateFld == "dd/mm/yyyy") {
    return true
  }
  validnum = dv_isDate(dateFld.value)
  if (validnum==1)
    return true
  switch (validnum) {
    case 2:
  		alert("The date format in '" + decodeURI(label) + "' should be : dd/mm/yyyy")
  		dateFld.focus()
      return false
      break
    case 3:
  		alert("Please enter a valid month in '" + decodeURI(label) + "'")
  		dateFld.focus()
      return false
      break
    case 4:
  		alert("Please enter a valid day in '" + decodeURI(label) + "'")
  		dateFld.focus()
      return false
      break
    case 5:
  		alert("Please enter a valid 4 digit year between " + dv_minYear + " and " + dv_maxYear + " in '" + decodeURI(label) + "'")
  		dateFld.focus()
      return false
      break
    case 6:
  		alert("Please enter a valid date in '" + decodeURI(label) + "'")
  		dateFld.focus()
      return false
      break
    default:
  		return false
	}
}

function isDate(txtDate,alwBlank,dateLocale){
    var currVal = txtDate;
    if(currVal == ''){
      if(alwBlank == false) return false;
      return true;
    }
    var rxDatePattern = /^(\d{1,2})(\/|-)(\d{1,2})(\/|-)(\d{4})$/; //Declare Regex
    var dtArray = currVal.match(rxDatePattern); // is format OK?

    if (dtArray == null)
        return false;

    //Checks for dd/mm/yyyy format.
    if(dateLocale == 'US'){
      dtMonth = dtArray[1];
      dtDay= dtArray[3];
    } else {
      dtMonth = dtArray[3];
      dtDay= dtArray[1];
    }
    dtYear = dtArray[5];

    if (dtMonth < 1 || dtMonth > 12)
        return false;
    else if (dtDay < 1 || dtDay> 31)
        return false;
    else if ((dtMonth==4 || dtMonth==6 || dtMonth==9 || dtMonth==11) && dtDay ==31)
        return false;
    else if (dtMonth == 2)
    {
        var isleap = (dtYear % 4 == 0 && (dtYear % 100 != 0 || dtYear % 400 == 0));
        if (dtDay> 29 || (dtDay ==29 && !isleap))
                return false;
    }
    return true;
}


function setLanguage (lang,vw) {
  if (vw == "preview") {
    //alert(parent.location.pathname);
    lcHref = parent.location.pathname + "?lang=" + lang;
    //alert(lcHref);
    parent.location.href = lcHref;
  } else {
    lcHref = location.pathname + "?lang=" + lang;
    location.href = lcHref;
  }
}

function getUrlVars(str){
  var vars = [], hash;
  var hashes = str.slice(str.indexOf('?') + 1).split('&');
  for(var i = 0; i < hashes.length; i++){
    hash = hashes[i].split('=');
    vars.push(hash[0]);
    vars[hash[0]] = hash[1];
  }
  return vars;
}

function CPconfirmDelete(form,qualifier){
  var agree=confirm("Are you sure you want to delete the selected item(s)?");
  if(qualifier==undefined){qualifier = "";}
  if (agree){
	  CPdoMode("DELETE-SELECTED"+qualifier,form);
	  return true;
  } else {
	  return false;
  }
}
function CPdoMode(mode,form){
  form.mode.value = mode;
  form.submit();
}
function CPisNumber(elem) {
  var str = elem.value;
  var re = /^[-]?\d*\.?\d*$/;
  str = str.toString();
  if (!str.match(re)) {
    alert("Enter only numbers in this field");
    elem.focus();
    elem.select();
    return false;
  } else {
    return true;
  }
}
function CPisValidNumRange(elem,from,to,allowblank) {
  if (elem.value == "" && allowblank == "Y") {
    return true;
  }
  if (elem.value < from || elem.value > to) {
    alert("Enter " + from + "-" + to + " in this field");
    elem.focus();
    return false;
  }
  return true;
}
function CPautofocus(field,limit,next,evt) {
  evt = (evt) ? evt : event;
  var charCode = (evt.charCode) ? evt.charCode : ((evt.keyCode) ? evt.keyCode : ((evt.which) ? evt.which : 0));
  if (charCode > 31 && field.value.length == limit) {
  }
}

function SetAllCheckBoxes(FormName, FieldName, CheckValue) {
	if(!document.forms[FormName])
		return;
	var objCheckBoxes = document.forms[FormName].elements[FieldName];
	if(!objCheckBoxes)
		return;
	var countCheckBoxes = objCheckBoxes.length;
	if(!countCheckBoxes)
		objCheckBoxes.checked = CheckValue;
	else
		// set the check value for all check boxes
		for(var i = 0; i < countCheckBoxes; i++)
			objCheckBoxes[i].checked = CheckValue;
}

function SetParentCheckBox(FormName, FieldName, Parent) {
	if(!document.forms[FormName])
		return;
	var objCheckBoxes = document.forms[FormName].elements[FieldName];
	if(!objCheckBoxes)
		return;
	var countCheckBoxes = objCheckBoxes.length;
	if(!countCheckBoxes)
		document.FormName.Parent.checked = false;
	else
		// set the check value for all check boxes
    allChecked = true;
		for(var i = 0; i < countCheckBoxes; i++){
			if(objCheckBoxes[i].checked == false) allChecked = false;
    }
    document.getElementById(Parent).checked = allChecked;
}

function SwapPlusMinusImg(el){
  var str = el.src;
  if(str.indexOf("plus.gif") >0){
    str = str.replace("plus.gif","minus.gif");
  } else {
    str = str.replace("minus.gif","plus.gif");
  }
  return str;
}

function getCookie(c_name){
  var i,x,y,ARRcookies=document.cookie.split(";");
  for (i=0;i<ARRcookies.length;i++){
    x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
    y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
    x=x.replace(/^\s+|\s+$/g,"");
    if (x==c_name){
      return unescape(y);
    }
  }
  return "";
}

