 
/*Common Functions */

/* returns querystring value*/
function getQueryVariable(variable) {
  var query = window.location.search.substring(1);
  var vars = query.split("&");
  for (var i=0;i<vars.length;i++) {
    var pair = vars[i].split("=");
    if (pair[0] == variable) {
      return unescape(pair[1]);
    }
  } 
  return "";
}

function confirmBad(prompt, url){
    if(confirm(prompt)){
        window.location.href = url;
    }
}

function highlightInvalids(){
    var validators = $$('span.validator');
    for(var i = 0; i < validators.length; i++){
        if(validators[i].visible()){
            els = validators[i].ancestors()[0].select('input','select');
            for(var j = 0; j < els.length; j++){
                els[j].setStyle({border: '1px solid red'});
            }
        }
    }
    try{
        if(validators.length > 0) validators[0].ancestors()[0].select('input')[0].focus();
    } catch(e){}
}

function setFirstFocus(){
  var bFound = false;
  //for each form
  for (f=0; f < document.forms.length; f++) {
        //for each form element
        for (i=0; i < document.forms[f].length; i++) {
              el = document.forms[f][i]
              if (el.disabled != true) {
                    if (el.type != undefined) {
                          switch (el.type.toLowerCase()) {
                                case "text" : el.focus(); bFound = true; break;
                                case "textarea" : el.focus(); bFound = true; break;
                                case "checkbox" : el.focus(); bFound = true; break;
                                case "radio" : el.focus(); bFound = true; break;
                                case "file" : el.focus(); bFound = true; break;
                                case "password" : el.focus(); bFound = true; break;
                                case "select-one" : el.focus(); bFound = true; break;
                                case "select-multiple" : el.focus(); bFound = true; break;
                          } // switch el.type
                    } //if (el.type != undefined)
              } //if (el.disabled != true)
              if (bFound == true) break;
        } //for each form element
        if (bFound == true) break;
  } //for each form
}

function checkInFrame(loggedIn){

    if(!loggedIn && top.location != document.location){
        top.location = document.location;
    }
    else if (loggedIn && top.location != document.location){
        // load up stylesheet
        document.getElementById("logo_holder").style.display = "none";
        document.getElementById("registrarName").style.display = "none";
        document.getElementById("secondaryTitle").style.display = "none";
        document.getElementById("navTabs").style.display = "none";
        document.getElementById("navigation").style.height = "0px";
        document.getElementById("navigation").style.border = "none";
        document.getElementById("footer").style.display = "none";
        document.getElementById("all").style.background = "#fff";
        document.getElementById("body").style.background = "#fff";
    }
}


