function openViewlet(htmlFile,htmlWidth,htmlHeight)
{
    if(document.all)
    {
        htmlWidth+=5;
        htmlHeight+=10;
    }
    window.open(htmlFile,'Leelou','width='+htmlWidth+',height='+htmlHeight+',top=10,left=20');
}
function OpenWindow(theURL,winName,features)
{
    win1=window.open(theURL,winName,features);
}


//this function checks if all reqirements are met
function checkFields(inputForm)
{
   var alertMsg = "Following error has occured:\n";
	var alertNum = 1;
	var valid = true;
   
	
	if (inputForm.firstName.value == "")
	{
		alertMsg += alertNum + ". The First Name field cannot be empty.\n";
		alertNum++;
		valid = false;
	}
	
	if (inputForm.lastName.value == "")
	{
		alertMsg += alertNum + ". The Last Name field cannot be empty.\n";
		alertNum++;
		valid = false;
	}
	
	if (inputForm.company.value == "")
	{
		alertMsg += alertNum + ". The Company field cannot be empty.\n";
		alertNum++;
		valid = false;
	}
	
	if (inputForm.jobTitle.value == "")
	{
		alertMsg += alertNum + ". The Job Title field cannot be empty.\n";
		alertNum++;
		valid = false;
	}
	
	if (inputForm.email.value == "")
	{
		alertMsg += alertNum + ". The Email field cannot be empty.\n";
		alertNum++;
		valid = false;
	}
	
	if (inputForm.telephone.value == "")
	{
		alertMsg += alertNum + ". The Phone field cannot be empty.\n";
		alertNum++;
		valid = false;
	}
	
	if (inputForm.address1.value == "")
	{
		alertMsg += alertNum + ". The Address Line 1 field cannot be empty.\n";
		alertNum++;
		valid = false;
	}
	
	if (inputForm.city.value == "")
	{
		alertMsg += alertNum + ". The City field cannot be empty.\n";
		alertNum++;
		valid = false;
	}
	
	if (inputForm.state.value == "")
	{
		alertMsg += alertNum + ". The State/Province field cannot be empty.\n";
		alertNum++;
		valid = false;
	}
	
	if (inputForm.zip.value == "")
	{
		alertMsg += alertNum + ". The Zip/Postal code field cannot be empty.\n";
		alertNum++;
		valid = false;
	}
	
	if (inputForm.country.value == "")
	{
		alertMsg += alertNum + ". The country field cannot be empty.\n";
		alertNum++;
		valid = false;
	}
	
    if (inputForm.refferedBy.value == "")
	{
		alertMsg += alertNum + ". Please specify how you heard about QSI.\n";
		alertNum++;
		valid = false;
	}

    if (inputForm.refferedBy.value=="Other (Please specify below)")
	{
        if(inputForm.other.value == "")
        {
		    alertMsg += alertNum + ". Please fill in the Additional Information field.\n";
		    alertNum++;
		    valid = false;
        }
	}

	if (inputForm.notes.value.length > 255)
	{
		alertMsg += alertNum + ". The Comments field cannot be longer than 255 characters.\n";
		alertNum++;
		valid = false;
	}
	
	if (valid == false)
	{
		alert(alertMsg);
	}

	return valid;
}

/*
//this function checks if all reqirements are met
function old_checkFields(inputForm)
{
   var alertMsg = "Following error has occured:\n";
	var alertNum = 1;
	var valid = true;
   
	if (inputForm.memberID.value == "")
	{
		alertMsg += alertNum + ". The User Name field cannot be empty.\n";
		alertNum++;
		valid = false;
	}
	if (inputForm.password.value == "")
	{
		alertMsg += alertNum + ". The Password field cannot be empty.\n";
		alertNum++;
		valid = false;
	}

	if (inputForm.password.value != inputForm.confirmPassword.value)
	{
		alertMsg += alertNum + ". The confirmed password does not match the password.\n";
		alertNum++;
		valid = false;
	}
	
	if (inputForm.firstName.value == "")
	{
		alertMsg += alertNum + ". The First Name field cannot be empty.\n";
		alertNum++;
		valid = false;
	}
	
	if (inputForm.lastName.value == "")
	{
		alertMsg += alertNum + ". The Last Name field cannot be empty.\n";
		alertNum++;
		valid = false;
	}
	
	if (inputForm.company.value == "")
	{
		alertMsg += alertNum + ". The Company field cannot be empty.\n";
		alertNum++;
		valid = false;
	}
	
	if (inputForm.jobTitle.value == "")
	{
		alertMsg += alertNum + ". The Job Title field cannot be empty.\n";
		alertNum++;
		valid = false;
	}
	
	if (inputForm.email.value == "")
	{
		alertMsg += alertNum + ". The Email field cannot be empty.\n";
		alertNum++;
		valid = false;
	}
	
	if (inputForm.telephone.value == "")
	{
		alertMsg += alertNum + ". The Phone field cannot be empty.\n";
		alertNum++;
		valid = false;
	}
	
	if (inputForm.address1.value == "")
	{
		alertMsg += alertNum + ". The Address Line 1 field cannot be empty.\n";
		alertNum++;
		valid = false;
	}
	
	if (inputForm.city.value == "")
	{
		alertMsg += alertNum + ". The City field cannot be empty.\n";
		alertNum++;
		valid = false;
	}
	
	if (inputForm.state.value == "")
	{
		alertMsg += alertNum + ". The State/Province field cannot be empty.\n";
		alertNum++;
		valid = false;
	}
	
	if (inputForm.zip.value == "")
	{
		alertMsg += alertNum + ". The Zip/Postal code field cannot be empty.\n";
		alertNum++;
		valid = false;
	}
	
	if (inputForm.country.value == "")
	{
		alertMsg += alertNum + ". The country field cannot be empty.\n";
		alertNum++;
		valid = false;
	}
	
    if (inputForm.refferedBy.value == "")
	{
		alertMsg += alertNum + ". Please specify how you heard about QSI.\n";
		alertNum++;
		valid = false;
	}

    if (inputForm.refferedBy.value=="Other (Please specify below)")
	{
        if(inputForm.other.value == "")
        {
		    alertMsg += alertNum + ". Please fill in the Additional Information field.\n";
		    alertNum++;
		    valid = false;
        }
	}

	if (inputForm.notes.value.length > 255)
	{
		alertMsg += alertNum + ". The Comments field cannot be longer than 255 characters.\n";
		alertNum++;
		valid = false;
	}
	
	if (valid == false)
	{
		alert(alertMsg);
	}

	return valid;
}
*/


//this function checks if all reqirements are met
function checkModFields(inputForm)
{
	var alertMsg = "Following error has occured:\n";
	var alertNum = 1;
	var valid = true;

	if (inputForm.password.value == "")
	{
		alertMsg += alertNum + ". The Password field cannot be empty.\n";
		alertNum++;
		valid = false;
	}

	if (inputForm.password.value != inputForm.confirmPassword.value)
	{
		alertMsg += alertNum + ". The confirmed password does not match the password.\n";
		alertNum++;
		valid = false;
	}
	
	if (inputForm.firstName.value == "")
	{
		alertMsg += alertNum + ". The First Name field cannot be empty.\n";
		alertNum++;
		valid = false;
	}
	
	if (inputForm.lastName.value == "")
	{
		alertMsg += alertNum + ". The Last Name field cannot be empty.\n";
		alertNum++;
		valid = false;
	}
	
	if (inputForm.company.value == "")
	{
		alertMsg += alertNum + ". The Company field cannot be empty.\n";
		alertNum++;
		valid = false;
	}
	
	if (inputForm.jobTitle.value == "")
	{
		alertMsg += alertNum + ". The Job Title field cannot be empty.\n";
		alertNum++;
		valid = false;
	}
	
	if (inputForm.email.value == "")
	{
		alertMsg += alertNum + ". The Email field cannot be empty.\n";
		alertNum++;
		valid = false;
	}
	
	if (inputForm.telephone.value == "")
	{
		alertMsg += alertNum + ". The Phone field cannot be empty.\n";
		alertNum++;
		valid = false;
	}
	
	if (inputForm.address1.value == "")
	{
		alertMsg += alertNum + ". The Address Line 1 field cannot be empty.\n";
		alertNum++;
		valid = false;
	}
	
	if (inputForm.city.value == "")
	{
		alertMsg += alertNum + ". The City field cannot be empty.\n";
		alertNum++;
		valid = false;
	}
	
	if (inputForm.state.value == "")
	{
		alertMsg += alertNum + ". The State/Province field cannot be empty.\n";
		alertNum++;
		valid = false;
	}
	
	if (inputForm.zip.value == "")
	{
		alertMsg += alertNum + ". The Zip/Postal code field cannot be empty.\n";
		alertNum++;
		valid = false;
	}
	
	if (inputForm.country.value == "")
	{
		alertMsg += alertNum + ". The country field cannot be empty.\n";
		alertNum++;
		valid = false;
	}
	
	if (valid == false)
	{
		alert(alertMsg);
	}
   return valid;
}

//this function set limits for a textarea
function limitText(inputField, maxSize)
{
	if (inputField.value.length > maxSize) // if too long, trim it
	{
		inputField.value = inputField.value.substring(0, maxSize);	
	}	
}



function fontsizeup() {
  active = getActiveStyleSheet();
  switch (active) {
    case 'A--' : 
      setActiveStyleSheet('A-');
      break;
    case 'A-' : 
      setActiveStyleSheet('A');
      break;
    case 'A' : 
      setActiveStyleSheet('A+');
      break;
    case 'A+' : 
      setActiveStyleSheet('A++');
      break;
    case 'A++' :
      break;
    default :
      setActiveStyleSheet('A');
      break;
  }
}

function fontsizedown() {
  active = getActiveStyleSheet();
  switch (active) {
    case 'A++' : 
      setActiveStyleSheet('A+');
      break;
    case 'A+' : 
      setActiveStyleSheet('A');
      break;
    case 'A' : 
      setActiveStyleSheet('A-');
      break;
    case 'A-' : 
      setActiveStyleSheet('A--');
      break;
    case 'A--' : 
       break;
    default :
      setActiveStyleSheet('A--');
      break;
  }
}

function setActiveStyleSheet(title) {
  var i, a, main;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
      a.disabled = true;
      if(a.getAttribute("title") == title) a.disabled = false;
    }
  }
}

function getActiveStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled) return a.getAttribute("title");
  }
  return null;
}

function getPreferredStyleSheet() {
  return ('A-');
}

function createCookie(name,value,days) {
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  }
  else expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  for(var i=0;i < ca.length;i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  }
  return null;
}

window.onload = function(e) {
  var cookie = readCookie("style");
  var title = cookie ? cookie : getPreferredStyleSheet();
  setActiveStyleSheet(title);
}

window.onunload = function(e) {
  var title = getActiveStyleSheet();
  createCookie("style", title, 365);
}

var cookie = readCookie("style");
var title = cookie ? cookie : getPreferredStyleSheet();
if (title == 'null') {
  title = getPreferredStyleSheet();
}

setActiveStyleSheet(title);

var newwindow = '';

function popitup(url){
    if (!newwindow.closed && newwindow.location){
		   newwindow.location.href = url;
	  }
	  else{
       newwindow=window.open(url,'name','height=400,width=800,screenX=100,screenY=100,top=100,left=100');
		   if (!newwindow.opener){
          newwindow.opener = self;
	      }
    }
	  if (window.focus) {
     newwindow.focus();
    }
	  return false;
}
