
defaultstar0 = 0; //smallest star to be painted
defaultstar1 = 0; //smallest star to be painted
defaultstar2 = 0; //smallest star to be painted
defaultstar3 = 0; //smallest star to be painted

//starrating0///////////////////////////////////////////////////////////////////////
function drawRating0(position, elem, li){
	stars = document.getElementById('starrating0');
	star=[];
	star = stars.getElementsByTagName('li');
	for ( i = 0 ; i < position; i++)
	{
		star[i].style.backgroundPosition = '19px';				
	}			
}

function clearRating0()
{	
	stars = document.getElementById('starrating0');
	star=[];
	star = stars.getElementsByTagName('li');
	for ( i = 0 ; i < 5; i++)
	{
		if (i < defaultstar0)
		{
			star[i].style.backgroundPosition = '19px 100%';				
		} 
		else {
			star[i].style.backgroundPosition = '';
		}		
	}
}

function doRating0(position)
{
	document.getElementById('reviewform').scoreBattery.value = position;
	defaultstar0 = position;
	clearRating0(); //instant star change			
}

//starrating1///////////////////////////////////////////////////////////////////////
function drawRating1(position){
	stars = document.getElementById('starrating1');
	star=[];
	star = stars.getElementsByTagName('li');
	for ( i = 0 ; i < position; i++)
	{
		star[i].style.backgroundPosition = '19px';				
	}			
}

function clearRating1()
{	
	stars = document.getElementById('starrating1');
	star=[];
	star = stars.getElementsByTagName('li');
	for ( i = 0 ; i < 5; i++)
	{
		if (i < defaultstar1)
		{
			star[i].style.backgroundPosition = '19px 100%';				
		} 
		else {
			star[i].style.backgroundPosition = '';
		}		
	}
}

function doRating1(position)
{
	document.getElementById('reviewform').scoreBuild.value = position;
	defaultstar1 = position;
	clearRating1(); //instant star change			
}

//starrating2////////////////////////////////////////////////////////////////////
function drawRating2(position){
	stars = document.getElementById('starrating2');
	star=[];
	star = stars.getElementsByTagName('li');
	for ( i = 0 ; i < position; i++)
	{
		star[i].style.backgroundPosition = '19px';				
	}			
}

function clearRating2()
{	
	stars = document.getElementById('starrating2');
	star=[];
	star = stars.getElementsByTagName('li');
	for ( i = 0 ; i < 5; i++)
	{
		if (i < defaultstar2)
		{
			star[i].style.backgroundPosition = '19px 100%';				
		} 
		else {
			star[i].style.backgroundPosition = '';
		}		
	}
}

function doRating2(position)
{
	document.getElementById('reviewform').scoreValue.value = position;
	defaultstar2 = position;
	clearRating2(); //instant star change			
}

//starrating3////////////////////////////////////////////////////////////////////
function drawRating3(position){
	stars = document.getElementById('starrating3');
	star=[];
	star = stars.getElementsByTagName('li');
	for ( i = 0 ; i < position; i++)
	{
		star[i].style.backgroundPosition = '19px';				
	}			
}

function clearRating3()
{	
	stars = document.getElementById('starrating3');
	star=[];
	star = stars.getElementsByTagName('li');
	for ( i = 0 ; i < 5; i++)
	{
		if (i < defaultstar3)
		{
			star[i].style.backgroundPosition = '19px 100%';				
		} 
		else {
			star[i].style.backgroundPosition = '';
		}		
	}
}

function doRating3(position)
{
	document.getElementById('reviewform').scoreOverall.value = position;
	defaultstar3 = position;
	clearRating3(); //instant star change			
}

//Function to show/hide elements. ele is the variable for the document id to be passed into the function.
function showHidden(ele)
{	
	if(document.getElementById(ele).style.display == 'block')
	{
		document.getElementById(ele).style.display = 'none';
	}
	else{
		document.getElementById(ele).style.display = 'block';
	}
}

//Form Validation
function checkForm(theForm)
{	
	var reason ="";
	
	reason += checkEmpty(theForm.name);
	reason += checkEmail(theForm.email);
	
	if(reason != "")
	{
		alert("The following errors occurred:\n"+reason);
		return false;
	}
	return true;
}

function trim(s)
{
  return s.replace(/^\s+|\s+$/, '');
}

function checkEmail(theField) 
{
    var error = "";
    var tField = trim(theField.value);   // value of field with whitespace trimmed off
    var emailFilter = /^[^@]+@[^@.]+\.[^@]*\w\w$/ ;
    var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/ ;
   
    if (theField.value == "") 
	{
        theField.style.background = '#f4f290';
        error = "You didn't enter an email address.\n";
    } 
	else if (!emailFilter.test(tField)) 
	{   
		//test email for illegal characters
        theField.style.background = '#f4f290';
        error = "Please enter a valid email address.\n";
    } 
	else if (theField.value.match(illegalChars)) 
	{
        theField.style.background = '#f4f290';
        error = "The email address contains illegal characters.\n";
    } 
	else 
	{
        theField.style.background = 'White';
    }
    return error;
}

function checkEmpty(theField)
{
	var empty = "";
	
	if(theField.value.length == 0)
	{
		theField.style.background = '#f4f290';
		empty = "You didn't enter a "+theField.name+" \n";
	}
	else{
		theField.style.background = "white";
	}
	return empty;
}

function showTab(onElem, offElem1, offElem2, offElem3, onTab, offTab1, offTab2, offTab3)
{	
	//Tab on
	document.getElementById(onElem).style.display = 'block';
	document.getElementById(onTab).style.backgroundImage = "url('/images/tab_white.png')";
	document.getElementById(onTab).style.color = '#326696';	
	
	//Tabs off
	document.getElementById(offElem1).style.display = 'none';
	document.getElementById(offTab1).style.backgroundImage = "url('/images/tab_grey.png')";
	document.getElementById(offTab1).style.color = '#666666';
	
	document.getElementById(offElem2).style.display = 'none';
	document.getElementById(offTab2).style.backgroundImage = "url('/images/tab_grey.png')";
	document.getElementById(offTab2).style.color = '#666666';
	
	document.getElementById(offElem3).style.display = 'none';
	document.getElementById(offTab3).style.backgroundImage = "url('/images/tab_grey.png')";
	document.getElementById(offTab3).style.color = '#666666';
}
