
/*
 * A simple utility function to confirm accessing a URL. It will display
 * the given message in a alert box and proceed to the given URL if the
 * user clicks OK.
 */
function confirmUrl(message, url) {
	if(confirm(message)) 
		location.href = url;
}



/**
  * Selects the text in a textbox. Use such as:
  * <input type="text" name="userId" maxlength="20" value="user name" onclick="removeText(this)"/>
  */
function selectText(element) {
	element.select();
}


/**
  * Removes the text in a textbox. Use such as:
  * <input type="text" name="userId" maxlength="20" value="user name" onclick="removeText(this)"/>
  */
function removeText(element) {
	element.value = "";
}  



/*
 * Tries to copy the given string into the clipboard. If that fails, displays
 * a dialog.
 */	
function copyToClipboard(content) {
	if(window.clipboardData && clipboardData.setData) {
		window.clipboardData.setData("Text", content);
	}
	else {
		prompt('Sorry, your browser does not support copying data to the clipboard. Please copy the text from here by hand.\nThen click any button.', content);
	}
}



function hideDivChildren(parentId) {
	parent = document.getElementById(parentId);
	children = parent.getElementsByTagName('div');
	
	for(i=0; i<children.length; i++) {
		children[i].className = "invisible";
	}	
}


function toggleVisibility(id) {
	element = document.getElementById(id);
	if(element != null) {
		if(element.className == "visible")
			element.className = "invisible";
		else
			element.className = "visible";
	}
}



function showTab(sTabsDivId, sTabContentsDivId, nTabIndex) {
	// Set all tabs to inactive
	div = document.getElementById(sTabsDivId);
	children = div.getElementsByTagName('span');
	for(i=0; i<children.length; i++) {
		children[i].className = "tab";
	}
	
	// Set new tab as active
	if(nTabIndex != null && nTabIndex != -1) {
		e = document.getElementById(sTabsDivId+"_"+nTabIndex);
		if(e != null)
			e.className = "tabActive";
	}
	
	
	// Set all tab contentss to invisible
	div = document.getElementById(sTabContentsDivId);
	children = div.getElementsByTagName('div');
	for(i=0; i<children.length; i++) {
		children[i].className = "invisible";
	}
	
	// Set new tab as active
	if(nTabIndex != null && nTabIndex != -1) {
		e = document.getElementById(sTabContentsDivId+"_"+nTabIndex);
		if(e != null)
			e.className = "visible";
	}
}



function submitForm(sFormId) {
	form = document.getElementById(sFormId);
	if(form != null) {
		form.submit();
	}
	else
		alert("Can't find form element with name ["+sFormId+"]");
}


function popupWindow(popupURL, width, height, scrollbars) {
        // Provide default values
        if(width == null) width = 617;
        if(height == null) height = 400;
        if(scrollbars == null) scrollbars = 'yes';
	   
        // Open window and bring to front
        win = window.open(popupURL, 'popupWin', 'toolbars=0,width='+width+',height='+height+',scrollbars='+scrollbars);   
        win.focus();
}

function ValidateForm() {
if (document.survey.email.value.indexOf("@")==-1 || document.survey.email.value.lastIndexOf(".")==-1)
          {
                alert("Please enter a valid email address");
                return false;
          }
else
          {
                document.getElementById('survey').submit();
                return true;
          }
          
} 

function checkform() {
  for (i=0;i<fieldstocheck.length;i++) {
    if (eval("document.subscribeform.elements['"+fieldstocheck[i]+"'].value") == "") {
      alert("Please enter your "+fieldnames[i]);
      eval("document.subscribeform.elements['"+fieldstocheck[i]+"'].focus()");
      return false;
    }
  }
  if(! compareEmail())
  {
    alert("Email Addresses you entered do not match");
    return false;
  }
  return true;
}
var fieldstocheck = new Array();
var fieldnames = new Array();
function addFieldToCheck(value,name) {
  fieldstocheck[fieldstocheck.length] = value;
  fieldnames[fieldnames.length] = name;
}
function compareEmail()
{
  return (document.subscribeform.elements["email"].value == document.subscribeform.elements["emailconfirm"].value);
}