// JavaScript Document
function submitSearch(what)
{
	//setup URL and searchString variables
	var searchString = document.getElementById('searchString').value;

	//redirect browser to the search script, passing the searchString variable - but only if the searchString isn't empty
	if(searchString.length != 0) 
	{
		document.searchForm.submit();
	}
	else
	{
		return false;
	}
}

function openWindow(windowURL,windowWidth,windowHeight,windowStyle, windowOtherParams)
{
	//determine basic parameters of the new window
	if(windowStyle == 1)
	{
		windowScrollbars = 1;
		windowToolbar    = 0;
		windowMenubar    = 0;
	}
	else
	{
		windowScrollbars = 1;
		windowToolbar    = 1;
		windowMenubar    = 1;
	}
	
	//open new window with passed and determined parameters
	var windowAttributes = "width=" + windowWidth + ", height=" + windowHeight + ", scrollbars=" + windowScrollbars + ", toolbar = " + windowToolbar + ", menubar = " + windowMenubar + ", " + windowOtherParams + "'";
	var newWindow = window.open(windowURL,'',windowAttributes);
}

function openManual(url) {
  newWindow = window.open(url,'','HEIGHT=500,WIDTH=790,resizable=yes,location=no,toolbar=yes,directories=no,scrollbars=1');
}

function open_assessment(assessment_id) {
  var new_window = window.open("http://tryout.questionmark.com/us/open.dll?name=tryitout&session="+assessment_id,"Assessment","width=800,height=600,resizeable=0,scrollbars=1")
}

function printThisPage() {
	window.print();
}

function isEmail(string) {
    if (string.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1)
        return true;
    else
        return false;
}

function trim(s) {
  while (s.substring(0,1) == ' ') {
    s = s.substring(1,s.length);
  }
  while (s.substring(s.length-1,s.length) == ' ') {
    s = s.substring(0,s.length-1);
  }
  return s;
}


// FEEDBACK FORM FUNCTIONS
function noenter() 
{
  return !(window.event && window.event.keyCode == 13); 
}

function enableFeedbackFormSubmit(what)
{
	what.feedbackForm_btn.disabled = false;
}

function clearFeedbackFormAnswerText(what, defaultText)
{
	if (what.answer_text.value == defaultText)
	{
		what.answer_text.value = "";
	}
}

function checkFeedbackForm(what)
{
	var j = 0;
	for (i = 0; i < what.answer_number.length; i++)
	{
		if (what.answer_number[i].checked == true)
		{
			j++;
		}
	}
	
	if (j > 0)
	{
		what.submit();
	}
}

function showHidden(what)
{
	document.getElementById(what).style.display = (document.getElementById(what).style.display == "block" ) ? "none" : "block";
}

function swapImage(what,imgFrom,imgTo)
{
	var currentSite = location.protocol + "//" + location.host;
	var imgSource = document[what.name].src.replace(currentSite,'');

	document[what.name].src = (imgSource == imgFrom) ? imgTo : imgFrom;
}

function setCookie(cookieName,cookieValue)
{
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+ 30)
	document.cookie = cookieName + "=" + escape(cookieValue) + ";domain=.questionmark.com;path=/"; // + ";expires="+exdate.toGMTString() + ";";
}

function getCookie(cookieName)
{
	if (document.cookie.length>0)
	{
		c_start=document.cookie.indexOf(cookieName + "=");
		if (c_start!=-1)
		{
			c_start=c_start + cookieName.length+1;
			c_end=document.cookie.indexOf(";",c_start);
			if (c_end==-1) c_end=document.cookie.length;
			return unescape(document.cookie.substring(c_start,c_end));
		}
	}
return "";
}

function Left(str, n){
	if (n <= 0)
	    return "";
	else if (n > String(str).length)
	    return str;
	else
	    return String(str).substring(0,n);
}

function Right(str, n){
    if (n <= 0)
       return "";
    else if (n > String(str).length)
       return str;
    else {
       var iLen = String(str).length;
       return String(str).substring(iLen, iLen - n);
    }
}

function KeyCheck(e)
{
	var KeyID = (window.event) ? event.keyCode : e.which;
	if((KeyID >= 65 && KeyID <= 90) || (KeyID >= 97 && KeyID <= 122) || (KeyID >= 33 && KeyID <= 47) || (KeyID >= 58 && KeyID <= 64) || (KeyID >= 91 && KeyID <= 96) || (KeyID >= 123 && KeyID <= 126))
	{
		return false;
	}
	return true;
}