// JavaScript Document
/*
function to check/uncheck the styled checkbox. attached to the onClick element of the div representing the checkbox
*/
function check_checkbox(id, hidden_id) {
	var obj = document.getElementById(id);
	c = obj.className;
	var check = document.getElementById(hidden_id);
	if (c == 'checkbox_checked') 
	{
	obj.className = 'checkbox_unchecked';
	check.value = '0';
	}
	else 
	{
	obj.className = 'checkbox_checked';
	check.value = '1';
	}
}
/*
function to replace the content of the input element with the input text
used to change the "selected" element of the dropdown.
attached to the onClick event of the dropdown elements
*/
function loadDiv(div, hidden_id, txt){
	document.getElementById(div).innerHTML=txt
	combo_box = document.getElementById(hidden_id);
	combo_box.value = txt;
}
/*
the function that hides or shows the dropdown. attach it to the onClick event of the headerDiv
*/
function ShowHide(id){
if (id.indexOf('content')== -1) {
		if(document.getElementById(id+'content').style.display =='none' || document.getElementById(id+'content').style.display =='')
			document.getElementById(id+'content').style.display = 'block'
		else
			document.getElementById(id+'content').style.display = 'none'
	}
	else{
		if(document.getElementById(id).style.display =='none' || document.getElementById(id).style.display =='')
			document.getElementById(id).style.display = 'block'
		else
			document.getElementById(id).style.display = 'none'
	}
}

function isEmpty(s)
{
	return((s==null)||(s.length==0))
}

var whitespace=" \t\n\r";

function isWhitespace(s)
{
	i=0;
	
	if(isEmpty(s)) 
		return true; 
		
	for(i=0;i< s.length;i++)
	{
		c=s.charAt(i);
		
		if(whitespace.indexOf(c)==-1) 
			return false;
	} 
	
	return true;
}

/*
the function validates if required fields are filled in on the page where it is called 
and if not displays a message with all required fields that are not filled in.
a field is considered required if its id begins with *.
the "names" for each required field that are displayed in the alert box are taken 
either from the name attribute in the case of inputs or from the title attribute in 
the case of the header divs that are used for tge styling of dropdowns
*/
function validate ()
{
    var agreest = document.getElementById('agreest');
    var agreert = document.getElementById('agreert');
	
	if((!agreest || agreest.value == 1) && (!agreert || agreert.value == 1))
	{
		var divCollection = document.getElementsByTagName('div')
		var	inputCollection = document.getElementsByTagName('input')
		var alertMSG = 'the following required fields are not filled in:\n'
		var a = ''
	
		for (var i=0;i<divCollection.length;i++) {
			if (divCollection[i].id!= null && divCollection[i].id!= undefined){
								if (divCollection[i].id.indexOf('*')==0){
									a = document.getElementById(divCollection[i].id).innerHTML
									if (a.indexOf('--')!=-1 || a.indexOf('Select')!=-1){
										//alert (a)
										alertMSG += " - "+document.getElementById(divCollection[i].id).title+"\n"
									}
								}
			}
		}
		for (var j=0;j<inputCollection.length;j++) {
			if (inputCollection[j].id!= null && inputCollection[j].id!= undefined){
								if (inputCollection[j].id.indexOf('*')==0){
									a = document.getElementById(inputCollection[j].id).value
									
									if (isEmpty(a) || isWhitespace(a)){
										alertMSG += " - "+document.getElementById(inputCollection[j].id).name+"\n"
									}
								}
			}
		}
	}
	else
		alertMSG = 'You must agree to the terms and conditions!';

	if (alertMSG != 'the following required fields are not filled in:\n')
	{
		alert (alertMSG);
		return false;
	}
	else
		return true;
}