function onCreateAccount()
{
	var msg = '';
	
	if(document.getElementById('txtUsername').value == '')
		msg += '<li>Please provide a Username.</li>';
	if(document.getElementById('txtPass').value == '')
		msg += '<li>Please provide a Password.</li>';
	if(document.getElementById('txtConfirmPass').value == '')
		msg += '<li>Please confirm your Password.</li>';
	if(document.getElementById('txtPass').value != document.getElementById('txtConfirmPass').value)
		msg += '<li>The password do not match.</li>';
	if(document.getElementById('txtAlias').value == '')
		msg += '<li>Please provide an Alias.</li>';
	if(document.getElementById('txtEmail').value == '')
		msg += '<li>Please provide your Email Address.</li>';
	if(document.getElementById('txtConfirmEmail').value == '')
		msg += '<li>Please provide a confirm your Email Address.</li>';
	if(document.getElementById('txtEmail').value != document.getElementById('txtConfirmEmail').value)
		msg += '<li>The Emails do not match.</li>';
	
	if(msg != '')
	{
		document.getElementById('dummyCreateAccount').style.display = 'block';
		document.getElementById('messageCreateAccount').style.display = 'block';
		document.getElementById('messageCreateAccount').innerHTML = msg;
		return false;
	}
	else
	{
		return true;
	}
}// end of function onCreateAccount()

function calcRand() 
{

  var retVal = Math.floor(Math.random() * 1001);
  return retVal;

}

function onContactUs()
{
	var msg = '';
	
	if(Trim(document.getElementById('txtName').value) == '')
		msg += '<li>Please provide your name</li>';
	if(Trim(document.getElementById('txtEmail').value) == '')
		msg += '<li>Please provide your email address</li>';
	else
	{
		var str = document.getElementById('txtEmail').value;
		var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
		if (filter.test(str))
			testresults=true
		else
			msg += '<li>Please provide a valid email address</li>';
		
	}
	if(document.getElementById('theDropDown').value == '')
		msg += '<li>Please select a subject</li>';
	if(Trim(document.getElementById('txtComments').value) == '')
		msg += '<li>Please provide your comments</li>';
	
	if(msg != '')
	{
		document.getElementById('contactUsValidationDiv').innerHTML = msg;
		return false;
	}
	else
		return true;
}

function onLogin()
{
	var msg = '';
	
	if(document.getElementById('txtLoginUsername').value == '')
		msg += '<li>Please provide a Username.</li>';
	if(document.getElementById('txtLoginPass').value == '')
		msg += '<li>Please provide a Password.</li>';
			
	if(msg != '')
	{
		document.getElementById('dummyMessage').style.display = 'block';
		document.getElementById('actualMessage').style.display = 'block';
		document.getElementById('actualMessage').innerHTML = msg;
		return false;
	}
	else
	{
		return true;
	}
}// end of function onLogin()

function onCreateQuiz()
{
	var msg = '';
	if(document.getElementById('txtQuizTitle').value == '')
		msg += '<li>Please provide Question Title</li>';
	if(document.getElementById('selectCat').value == '')
		msg += '<li>Please choose a Category</li>';
	if(document.getElementById('startDateTime').value == '')
		msg += '<li>Please provide a Starting Date</li>';
	if(document.getElementById('endDateTime').value == '')
		msg += '<li>Please provide an Ending Date</li>';
	if(document.getElementById('txtQuestionScore').value == '')
		msg += '<li>Please provide a default score for each question</li>';
	if(document.getElementById('radioQuizEventYes').checked && document.getElementById('selectEvent').value == '')
		msg += '<li>Please choose an Event for this Quiz</li>';
	if(document.getElementById('radioQuizEventYes').checked && document.getElementById('selectEvent').value == 'Other' && document.getElementById('txtEventTitle').value == '')
		msg += '<li>Please provide an Event for the Quiz</li>';
	if(document.getElementById('txtRadioResultOn').checked && document.getElementById('resultDateTime').value == '')
		msg += '<li>Please provide Result Announcement Date</li>';
		
	if(msg != '')
	{
		document.getElementById('actualMessage').innerHTML = msg;
		document.getElementById('dummyMessage').style.display = 'block';
		document.getElementById('actualMessage').style.display = 'block';
		return false;
	}
	else
		return true;
	
}

function LTrim(str) 
{ 
	 for (var k=0; k<str.length && str.charAt(k)<=' ' ; k++) ;
	 return str.substring(k,str.length);
}

function RTrim(str) 
{
	 for (var j=str.length-1; j>=0 && str.charAt(j)<=' ' ; j--) ;
	 return str.substring(0,j+1);
}

function Trim(str) 
{
	 return LTrim(RTrim(str));
}


function onAddressBookImporterSubmit()
{
	var msg = '';
	if(document.getElementById('txtEmailUsername').value == '')
		msg += '<li>Please provide your email username</li>';
	if(document.getElementById('txtEmailPass').value == '')
		msg += '<li>Please provide your email account password</li>';
		
	if(msg != '')
	{
		document.getElementById('actualMessage').innerHTML = msg;
		document.getElementById('dummyMessage').style.display = 'block';
		document.getElementById('actualMessage').style.display = 'block';
		return false;
	}
	else
		return true;
}

function getCurrentDateTime(controlId)
{
	var currentTime = new Date()
	var month = currentTime.getMonth() + 1
	var day = currentTime.getDate()
	var year = currentTime.getFullYear()
	var hour = currentTime.getHours()
	var minute = currentTime.getMinutes()
	var second = currentTime.getSeconds()
	
	if (day < 10)
		day = "0" + day
	if (month < 10)
		month = "0" + month
	if (hour < 10)
		hour = "0" + hour
	if (minute < 10)
		minute = "0" + minute
	if (second < 10)
		second = "0" + second
	
	document.getElementById(controlId).value = year+'-'+month+'-'+day+' '+hour+':'+minute+':'+second;

}

function counter(textAreaId,counterSpanId,len)
{
	var textArea = document.getElementById(textAreaId).value;
	document.getElementById(counterSpanId).innerHTML = textArea.length;
	if(textArea.length > len)
		document.getElementById(textAreaId).value = textArea.substr(0,len);
}// end of function counter()

function onFastResponder()
{
	if(document.getElementById("radioFastYes").checked)
		document.getElementById("fastResponse").style.display = 'block';
	if(document.getElementById("radioFastNo").checked)
		document.getElementById("fastResponse").style.display = 'none';
}// end of function onFastResponder()

function onEvent()
{
	if(document.getElementById("radioQuizEventYes").checked)
		document.getElementById("events").style.display = 'block';
	if(document.getElementById("radioQuizEventNo").checked)
		document.getElementById("events").style.display = 'none';
}// end of function onEvent()

function showHideDiv(divId)
{
	if(document.getElementById(divId).style.display == 'none')
		document.getElementById(divId).style.display = 'block';
	else
		document.getElementById(divId).style.display = 'none';
}// end of function showHideDiv(divId)

function dropDownOnChange(dropDownId, theValue, controlsArray)
{
	if(document.getElementById(dropDownId).value == theValue)
	{
		for(i=0;i<controlsArray.length;i++)
			document.getElementById(controlsArray[i]).style.display = 'block';
	}
	else
	{
		for(i=0;i<controlsArray.length;i++)
			document.getElementById(controlsArray[i]).style.display = 'none';
	}
}// end of function dropDownOnChange(dropDownId, controlsArray)

function onRegister()
{
	//alert('you are here');
	$('#signUp').jqm({ajax: 'createAccount.htm', trigger: 'a.signupTrigger'});
}// end of function onRegister()

function tooglePartial(id)
{
	
	if(document.getElementById("selectPartial" + id)[0].selected)
	{
		for(i=1; i<=count; i++)
			document.getElementById("selectPartial" + i).disabled = false;
			
		document.getElementById("selectPartial" + id).disabled = true;
	}
	else
	{
		document.getElementById("selectPartial" + id)[0].selected = true;
		for(i=1; i<=count; i++)
			document.getElementById("selectPartial" + i).disabled = false;
		
		document.getElementById("selectPartial" + id).disabled = true;
		alert('Correct Answer cannot have Partial Scoring');
	}
}

function clearAnswers()
{
	for(i=1; i<=count; i++)
	{
		document.getElementById("radioAnswers" + i).checked = false;
		document.getElementById("selectPartial" + i).disabled = false;
	}
}

function onPartialScoring()
{
	if(document.getElementById("radioCorrectAnswerYes").checked)
	{
		if(document.getElementById("radioPartialYes").checked)
		{
			for(i=1;i<=count;i++)
				document.getElementById("selectPartial" + i).disabled = false;
		}
		
		if(document.getElementById("radioPartialNo").checked)
		{
			for(i=1;i<=count;i++)
				document.getElementById("selectPartial" + i).disabled = true;
		}
	}
	else
	{
		for(i=1;i<=count;i++)
		{
			document.getElementById("selectPartial" + i)[0].selected = true;
			document.getElementById("selectPartial" + i).disabled = true;
		}
		document.getElementById("radioPartialNo").checked = true;
		alert('You can use this feature only when specifying a correct answer.');
	}
}

function onCorrectAnswer()
{
	if(document.getElementById("radioCorrectAnswerYes").checked)
	{
	    for(i=1;i<=count;i++)
			document.getElementById("radioAnswers" + i).disabled = false;
	}
	else
	{
		for(i=1;i<=count;i++)
		{
			document.getElementById("selectPartial" + i)[0].selected = true;
			document.getElementById("selectPartial" + i).disabled = true;
		}
		
		if(document.getElementById("radioCorrectAnswerNo").checked)
		{
			for(i=1;i<=count;i++)
				document.getElementById("radioAnswers" + i).disabled = true;
		}
		
		document.getElementById("radioPartialNo").checked = true;
	}
}

function partialOnChange(id)
{
	if(document.getElementById("radioAnswers" + id).checked)
	{
		alert('Correct Answer cannot have Partial Scoring');
		
		document.getElementById("selectPartial" + id)[0].selected = true;
		document.getElementById("selectPartial" + id).disabled = true;
	}
}

function selectAll(selectAllCheckboxId, checkboxGroupId, checkboxCount)
{
	if(document.getElementById(selectAllCheckboxId).checked)
	{
		for(var i=0;i<checkboxCount;i++)
			document.getElementById(checkboxGroupId+i).checked = true;
	}// end of if(document.getElementById(selectAllCheckboxId).checked)
	else
	{
		for(var i=0;i<checkboxCount;i++)
			document.getElementById(checkboxGroupId+i).checked = false;
	}// end of else of if(document.getElementById(selectAllCheckboxId).checked)
}// end of function selectAll(checkboxGroupId, checkboxCount)

function onInvitePlayers(textareaId, checkboxGroupId, checkboxCount)
{
	var emailAddresses = '';
	for(var i=0;i<checkboxCount;i++)
	{
		if(document.getElementById(checkboxGroupId+i).checked)
		{
			emailAddresses += document.getElementById(checkboxGroupId+i).value;
			emailAddresses += ';';
		}
	}
	
	if (window.opener && !window.opener.closed)
		window.opener.document.getElementById(textareaId).value += emailAddresses;
	window.close();
}

function test()
{
    alert('here');
    alert(document.addQuestionForm.data['txtAnswers'][0].value);
}

function calcage(secs, num1, num2) {
	if(num2 == 0)
		s = (Math.floor(secs/num1)).toString();
	else
		s = ((Math.floor(secs/num1))%num2).toString();
  if (s.length < 2)
    s = "0" + s;
  return "<b>" + s + "</b>";
}

function CountBack(secs) {
  if (secs < 0) {
    document.getElementById("cntdwn").innerHTML = FinishMessage;
    if(document.getElementById("cntdwn").parentElement)
    	document.getElementById("cntdwn").parentElement.title = FinishMessage;
    document.getElementById("cntdwn").style.fontSize = "9pt";
    return;
  }
  DisplayFormat = "%%M%%:%%S%% Left";
  DisplayStr = DisplayFormat.replace(/%%M%%/g, calcage(secs,60,0));
  DisplayStr = DisplayStr.replace(/%%S%%/g, calcage(secs,1,60));

  document.getElementById("cntdwn").innerHTML = DisplayStr;
  var SetTimeOutPeriod = (Math.abs(-1)-1)*1000 + 990;
  setTimeout("CountBack(" + (secs-1) + ")", SetTimeOutPeriod);
}

function putspan() {
 document.write("<div style='float:left;margin-top:7px;width:100px;' title='Fast response time left'><span id='cntdwn' style='background-color:white;color:black;font-size:11pt;' ></span></div>");
}
function startTimer(duration)
{
	gsecs = Math.floor(duration.valueOf());
	CountBack(gsecs);
}