// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults
function clearText(thefield){
	if (thefield.defaultValue==thefield.value) {
		thefield.value = ""
	}
}
// Function hidediv(id)
// Purpose: the input id div will be hidden
function hidediv(id) {
	//safe function to hide an element with a specified id
	if (document.getElementById) { // DOM3 = IE5, NS6
	    if (document.getElementById(id)) {
		  document.getElementById(id).style.display = 'none';
		}
	}
	else {
		if (document.layers) { // Netscape 4
			document.id.display = 'none';
		}
		else { // IE 4
			document.all.id.style.display = 'none';
		}
	}
}
// Function hideimg(id)
// Purpose: the input id image will be hidden
function hideimg(id) {
	//safe function to show an element with a specified id
		  
	if (document.getElementById) { // DOM3 = IE5, NS6
	    if (document.getElementById(id)) {
	       document.getElementById(id).style.backgroundPosition = 'left top';
	    }
	}
	else {
		if (document.layers) { // Netscape 4
			document.id.backgroundPosition = 'left top';
		}
		else { // IE 4
			document.all.id.style.backgroundPosition = 'left top';
		}
	}    
}

// Function showdiv(id)
// Purpose: the input id div will be shown
function showdiv(id) {
	//safe function to show an element with a specified id
		  
	if (document.getElementById) { // DOM3 = IE5, NS6
	    if (document.getElementById(id)) {
		  document.getElementById(id).style.display = 'block';
		}
	}
	else {
		if (document.layers) { // Netscape 4
			document.id.display = 'block';
		}
		else { // IE 4
			document.all.id.style.display = 'block';
		}
	}
}
// Function showimg(id)
// Purpose: the input id image will be shown
function showimg(id) {
	//safe function to show an element with a specified id
		  
	if (document.getElementById) { // DOM3 = IE5, NS6
	    if (document.getElementById(id)) {
	       document.getElementById(id).style.backgroundPosition = 'right top';
	    }
	}
	else {
		if (document.layers) { // Netscape 4
			document.id.backgroundPosition = 'right top';
		}
		else { // IE 4
			document.all.id.style.backgroundPosition = 'right top';
		}
	}    
}


// Function setcolor(id,colorid)
// Purpose: the color style will be changed
function setcolor(id,colorid) {
	//safe function to hide an element with a specified id
	if (document.getElementById) { // DOM3 = IE5, NS6
	    if (document.getElementById(id)) {
		  document.getElementById(id).style.color = colorid;
		  return;
		}
	}
	else {
		if (document.layers) { // Netscape 4
			document.id.display = colorid;
			return;
		}
		else { // IE 4
			document.all.id.style.display = colorid;
			return;
		}
	}
}

// Function setunderline(id,bvalue)
// Purpose: the underline style will be changed
function setunderline(id,bvalue) {
	//safe function to hide an element with a specified id
	if (document.getElementById) { // DOM3 = IE5, NS6
	    if (document.getElementById(id)) {
		  document.getElementById(id).style.textDecoration = bvalue;
		  return;
		}
	}
	else {
		if (document.layers) { // Netscape 4
			document.id.textDecoration = bvalue;
			return;
		}
		else { // IE 4
			document.all.id.style.textDecoration = bvalue;
			return;
		}
	}
}

// Function setbgcolor(id,colorid)
// Purpose: the background color style will be changed
function setbgcolor(id,colorid) {
	//safe function to hide an element with a specified id
	if (document.getElementById) { // DOM3 = IE5, NS6
	    if (document.getElementById(id)) {
		  document.getElementById(id).style.backgroundColor = colorid;
		  return;
		}
	}
	else {
		if (document.layers) { // Netscape 4
			document.id.backgroundColor = colorid;
			return;
		}
		else { // IE 4
			document.all.id.style.backgroundColor = colorid;
			return;
		}
	}
}
// Function getimage(id,imageid)
// Purpose: the image src will be changed
function getimage(id) {
    var retval = "";
	//safe function to hide an element with a specified id
	if (document.getElementById) { // DOM3 = IE5, NS6
	    if (document.getElementById(id)) {
		  retval = document.getElementById(id).src;
		}
	}
	else {
		if (document.layers) { // Netscape 4
			retval = document.id.src;
		}
		else { // IE 4
			retval = document.all.id.src;
		}
	}
	return retval;
}
// Function setimage(id,imageid)
// Purpose: the image src will be changed
function setimage(id,imageid) {
	//safe function to hide an element with a specified id
	if (document.getElementById) { // DOM3 = IE5, NS6
	    if (document.getElementById(id)) {
		  document.getElementById(id).src = imageid;
		}
	}
	else {
		if (document.layers) { // Netscape 4
			document.id.src = imageid;
		}
		else { // IE 4
			document.all.id.src = imageid;
		}
	}
}
// Function setbgimage(id,imageid)
// Purpose: the background color style will be changed
function setbgimage(id,imageid) {
    // build url string
    var newImage = "url("+imageid+")";
    
	//safe function to hide an element with a specified id
	if (document.getElementById) { // DOM3 = IE5, NS6
	    if (document.getElementById(id)) {
		  document.getElementById(id).style.backgroundImage = newImage;
		  return;
		}
	}
	else {
		if (document.layers) { // Netscape 4
			document.id.style.backgroundImage = newImage;
			return;
		}
		else { // IE 4
			document.all.id.style.backgroundImage = newImage;
			return;
		}
	}
}
// Function getChecked(id)
// Purpose: this will return the checked checkbox 
function getChecked(id) {
    var retval = false;
	//safe function to hide an element with a specified id
	if (document.getElementById) { // DOM3 = IE5, NS6
	    if (document.getElementById(id)) {
		  retval = document.getElementById(id).checked;
		}
	}
	else {
		if (document.layers) { // Netscape 4
			retval = document.id.checked;
		}
		else { // IE 4
			retval = document.all.id.checked;
		}
	}
	return retval;    
}

// Function setChecked(id)
// Purpose: this will set the checked checkbox 
function setChecked(id,value) {
	//safe function to hide an element with a specified id
	if (document.getElementById) { // DOM3 = IE5, NS6
	    if (document.getElementById(id)) {
		    document.getElementById(id).checked = value;
		    return;
		}
	}
	else {
		if (document.layers) { // Netscape 4
			document.id.checked = value;
			return;
		}
		else { // IE 4
			document.all.id.checked = value;
			return;
		}
	}
}

// Function getEnabled(id)
// Purpose: this will return the disabled checkbox 
function getDisabled(id) {
    var retval = true;
	//safe function to hide an element with a specified id
	if (document.getElementById) { // DOM3 = IE5, NS6
	    if (document.getElementById(id)) {
		  retval = document.getElementById(id).disabled;
		}
	}
	else {
		if (document.layers) { // Netscape 4
			retval = document.id.disabled;
		}
		else { // IE 4
			retval = document.all.id.disabled;
		}
	}
	return retval;    
}

// Function setEnabled(id)
// Purpose: this will enable a checkbox 
// Also, we need to enable the text span which will be
// pre-pended with the word 'span'+id
function setEnabled(id) {
    var span = 'span'+id;
	//safe function to hide an element with a specified id
	if (document.getElementById) { // DOM3 = IE5, NS6
	    if (document.getElementById(id)) {
		  document.getElementById(id).disabled = false;
		}
	}
	else {
		if (document.layers) { // Netscape 4
			document.id.disabled = false;
		}
		else { // IE 4
			document.all.id.disabled = false;
		}
	}
	
	setcolor(span,'#6A737B');
}
// Function setDisabled(id)
// Purpose: this will disable a checkbox 
function setDisabled(id) {
    var span = 'span'+id;
	//safe function to hide an element with a specified id
	if (document.getElementById) { // DOM3 = IE5, NS6
	    if (document.getElementById(id)) {
		  document.getElementById(id).disabled = true;
		  document.getElementById(id).checked = false;
		}
	}
	else {
		if (document.layers) { // Netscape 4
			document.id.disabled = true;
			document.id.checked = false;
		}
		else { // IE 4
			document.all.id.disabled = true;
			document.all.id.checked = false;
		}
	}
	setcolor(span,'#aaa'); 
}

// Function setDim(id)
// Purpose: this will dim the disabled item using opacity
function setDim(id) {
    // opacity is for firefox
    // filter is for IE (values range from 0 to 10)
	//testObj.style.opacity = value/10;
	//testObj.style.filter = 'alpha(opacity=' + value*10 + ')';
	
	//safe function to hide an element with a specified id
	if (document.getElementById) { // DOM3 = IE5, NS6
	    if (document.getElementById(id)) {
		  document.getElementById(id).style.MozOpacity = 0.3;             // FF
		  document.getElementById(id).style.filter="alpha(opacity=30)";   // IE
		}
	}
	else {
		if (document.layers) { // Netscape 4
			document.id.style.filter="alpha(opacity=30)";
		}
		else { // IE 4
			document.all.id.style.filter="alpha(opacity=30)";
		}
	}  	
}

// Function setUndim(id)
// Purpose: this will undim the disabled item using opacity
function setUndim(id) {
    // opacity is for firefox
    // filter is for IE (values range from 0 to 10)
	//testObj.style.opacity = value/10;
	//testObj.style.filter = 'alpha(opacity=' + value*10 + ')';
	
	//safe function to hide an element with a specified id
	if (document.getElementById) { // DOM3 = IE5, NS6
	    if (document.getElementById(id)) {
		  document.getElementById(id).style.MozOpacity = 0.9;             // FF
		  document.getElementById(id).style.filter="alpha(opacity=90)";   // IE
		}
	}
	else {
		if (document.layers) { // Netscape 4
		    document.id.style.filter="alpha(opacity=90)";
		}
		else { // IE 4
		    document.all.id.style.filter="alpha(opacity=90)";
		}
	}  	
}

// Function getDim(id)
// Purpose: this will return if the item is dimmed
function getDim(id) {
	//safe function to hide an element with a specified id
	if (document.getElementById) { // DOM3 = IE5, NS6
	    if (document.getElementById(id)) {
	      if (navigator.appVersion.indexOf("MSIE")!=-1) {
	          // returns "alpha(opacity=XX)"
	          if (document.getElementById(id).style.filter == "alpha(opacity=90)") {
	              return false;
	          } else {
	              return true;
	          }
	          //return document.getElementById(id).style.filter;
	      } else {
	          if (document.getElementById(id).style.MozOpacity == 0.9) {
	              return false;
	          } else {
	              return true;
	          }
		  }
		}
	}
	else {
		if (document.layers) { // Netscape 4
		    return document.id.style.filter;
		}
		else { // IE 4
		    return document.all.id.style.filter;
		}
	}  	
}
// Function countResults()
// Purpose: this will return the count of all undimed results
function countResults(v,allItems) {
    var retval;
    var count = 0;
    for (var i=0; i<allItems.length; i++) {
        if (getDim(v+allItems[i][1]) == false) {
            count += 1;
        }
        //retval = getDim(v+allItems[i][1]);
        //if (retval == "alpha(opacity=90)" || retval == 0.9) {
        //    count += 1;
        //}
    }
    return count;
}

// Function countResults()
// Purpose: this will return the count of all undimed results
function comparefunc(v,allItems) {
    var retval;
    var count = 0;
    for (var i=0; i<allItems.length; i++) {
        if (getDim(v+allItems[i][1]) == false) {
            setChecked(v+allItems[i][1],true);
        }
        //retval = getDim(v+allItems[i][1]);
        //if (retval == "alpha(opacity=90)" || retval == 0.9) {
        //    count += 1;
        //}
    }
}

// Function getvalue(id)
// Purpose: this will return the value of the id element
function getvalue(id) {
    var retval = "";
	//safe function to hide an element with a specified id
	if (document.getElementById) { // DOM3 = IE5, NS6
	    if (document.getElementById(id)) {
		  retval = document.getElementById(id).value;
		}
	}
	else {
		if (document.layers) { // Netscape 4
			retval = document.id.value;
		}
		else { // IE 4
			retval = document.all.id.value;
		}
	}
	return retval;    
}

// Function setvalue(id,val)
// Purpose: this will set the value of the element
function setvalue(id,val) {
	//safe function to hide an element with a specified id
	if (document.getElementById) { // DOM3 = IE5, NS6
	    if (document.getElementById(id)) {
		  document.getElementById(id).value = val;
		}
	}  
}
// Function writehtml(id,string)
// Purpose: writes new string to the specified span
function writehtml(id,string) {
	//safe function to hide an element with a specified id
	if (document.getElementById) { // DOM3 = IE5, NS6
	    if (document.getElementById(id)) {
	      document.getElementById(id).innerHTML = string;
		}
	}
	else {
		if (document.layers) { // Netscape 4
			document.id.innerHTML = string;
		}
		else { // IE 4
			document.all.id.innerHTML = string;
		}
	}
}

// Function: SetAllRegions
// Selects all checkboxes for regions
function SetAllRegions(obj)
{
    field_us = obj + "_locale_us";
    field_eu = obj + "_locale_eu";
    field_au = obj + "_locale_au";
  
    setChecked(field_us,true);
    setChecked(field_eu,true);
    setChecked(field_au,true);
}