// JavaScript Document

	var ids=new Array('lvl1','lvl2','lvl3', 'lvlPrices');
	
	function switchid(id){	
		hideallids();
		showdiv(id);
	}
	
	function swapids(id){
		var adelaide = document.getElementById('adelaideAnimals');
		var monarto = document.getElementById('monartoAnimals');
		if(id == "adelaideAnimals")	{
			hidediv('monartoAnimals');
			showdiv('adelaideAnimals');
		}
		else {
			showdiv('monartoAnimals');
			hidediv('adelaideAnimals');
		}
	}
	
	function hideallids(){
		//loop through the array and hide each element by id
		for (var i=0;i<ids.length;i++){
			hidediv(ids[i]);
		}		  
	}
	
	function hidediv(id) {
		//safe function to hide an element with a specified id
		if (document.getElementById) { // DOM3 = IE5, NS6
			document.getElementById(id).style.display = 'none';
		}
		else {
			if (document.layers) { // Netscape 4
				document.id.display = 'none';
			}
			else { // IE 4
				document.all.id.style.display = 'none';
			}
		}
	}
	
	function showdiv(id) {
		//safe function to show an element with a specified id
			  
		if (document.getElementById) { // DOM3 = IE5, NS6
			document.getElementById(id).style.display = 'block';
		}
		else {
			if (document.layers) { // Netscape 4
				document.id.display = 'block';
			}
			else { // IE 4
				document.all.id.style.display = 'block';
			}
		}
	}
	function checkAmount(x) {
		var amount=document.getElementById(x).value;
		if(amount >= 70 && amount <= 175) {switchid('lvl1');}
		else if(amount >= 176 && amount <= 550) {switchid('lvl2');}
		else if(amount >= 551){switchid('lvl3');}
		else if (amount < 50){switchid('lvlPrices');}
	}

function adoptionGetKeyCode(e)
{
  if (window.event)
  {
    return window.event.keyCode;
  }
  else if (e)
  {
     return e.which;
  }
  else
  {
     return null;
  }
}

function adoptionAllowKeys(e, goodkeys)
{
  var key, keychar;
  key = adoptionGetKeyCode(e);
  if (key == null)
  {
    return true;
  }

  // get character
  keychar = String.fromCharCode(key);
  keychar = keychar.toLowerCase();
  goodkeys = goodkeys.toLowerCase();

  // check goodkeys
  if (goodkeys.indexOf(keychar) != -1)
  {
        return true;
  }

  // control keys
  if ( key==null || key==0 || key==8 || key==9 || key==13 || key==27 )
  {
     return true;
  }

    return false;
}


function adoptionFormCheckEmail(value) {
  if(value == '') {
    return true;
  }

  return /^\w+([\.\+-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(value);
}


function adoptionCheckMoney(value) {
  return /^\d+\.{0,1}\d{0,2}$/.test(value);
}



function checkAdoptionForm(theForm) 
{
  var error = '';

  if($('#Amount').val() == '') {
    error += ' - Donation Amount\n';
  }

  if($('#Animal').val() == '') {
    error += ' - Animal you wish to adopt\n';
  }
  
  if($('#FIRSTNAME').val() == '') {
    error += ' - First Name\n';
  }

  if($('#LASTNAME').val() == '') {
    error += ' - Last Name\n';
  }

  if($('#ADDRESS1').val() == '') {
    error += ' - Address Line 1\n';
  }

  if($('#SUBURB').val() == '') {
    error += ' - Suburb\n';
  }

  if($('#POSTCODE').val() == '') {
    error += ' - Postcode\n';
  }

  if($('#PHONE').val() == '') {
    error += ' - Phone\n';
  }

  if($('#EMAIL').val() == '') {
    error += ' - Email\n';
  }

  if(error != '') {
    alert('Please check the values you have entered for:\n' + error);
    return false;
  }

  var amount = $('#Amount').val();
  if(!adoptionCheckMoney(amount)) {
    alert('Please enter a valid Donation Amount');
    return false;
  }

  if(amount < 70) {
    alert('The minimum donation amount is $70.00');
    return false;
  }

  var email = $('#EMAIL').val();
  if(!adoptionFormCheckEmail(email)) {
    alert('Please enter a valid email address');
    return false;
  }

  var privacypolicy = document.getElementById('privacypolicy');
  if(!privacypolicy.checked) {
    alert('Please accept the privacy policy');
    return false;
  }


  return true;
}


function radioClick(id)
{
	var radioObject = document.getElementById(id);
	if ( radioObject.value != 'Family' )
	{
		disableTrWithInners('famRow1');
		//disableTrWithInners('famRow2');
		//disableTrWithInners('famRow3');
		//disableTrWithInners('famRow4');
		disableTrWithInners('famRow5');
	}
	else
	{
		enableTrWithInners('famRow1');
		//enableTrWithInners('famRow2');
		//enableTrWithInners('famRow3');
		//enableTrWithInners('famRow4');
		enableTrWithInners('famRow5');
	}
	
	if ( radioObject.value != 'Student' )
	{
		disableTrWithInners('studRow1');
		disableTrWithInners('studRow2');
	}
	else
	{
		enableTrWithInners('studRow1');
		enableTrWithInners('studRow2');
	}
	
}

function newRadioClick(id) {
	//alert(id);
	var radioYeah = document.getElementById(id);
	//alert("radio yeah .value
	if( radioYeah.value == "Gold") {
		document.getElementById("requiredLife").style.display = "none";	
	} else {
		document.getElementById("requiredLife").style.display = "";	
	}
	if(radioYeah.value == "Conservation") {
		disableTrWithInners('requiredFields');
		document.getElementById("membershipRequireda").checked = "";
	} else {
		enableTrWithInners('requiredFields');
	}
}


function adoptionRadioClick(id)
{
	var radioObject = document.getElementById(id);
	if ( radioObject.value == '1' )
	{
		enableTrWithInners('level1');
		disableTrWithInners('level2');
		disableTrWithInners('level3');
	}
	if ( radioObject.value == '2' )
	{
		disableTrWithInners('level1');
		enableTrWithInners('level2');
		disableTrWithInners('level3');
	}
	if ( radioObject.value == '3' )
	{
		disableTrWithInners('level1');
		disableTrWithInners('level2');
		enableTrWithInners('level3');
	}
}


function disableTrWithInners(id)
{
	var tableRow = document.getElementById(id);
	if ( tableRow != null )
	{
		tableRow.className = 'disabled';
		//disable inputs
		var inputs = tableRow.getElementsByTagName('input');
		for ( var i=0;  i<inputs.length; i++ )
		{
			inputs[i].disabled = 'disabled';
		}
		//disable selects
		var inputs = tableRow.getElementsByTagName('select');
		for ( var i=0;  i<inputs.length; i++ )
		{
			inputs[i].disabled = 'disabled';
		}
	}
}


function enableTrWithInners(id)
{
	var tableRow = document.getElementById(id);
	if ( tableRow != null )
	{
		tableRow.className = '';
		//enable inputs
		var inputs = tableRow.getElementsByTagName('input');
		for ( var i=0;  i<inputs.length; i++ )
		{
			inputs[i].disabled = '';
		}
		//enable selects
		var inputs = tableRow.getElementsByTagName('select');
		for ( var i=0;  i<inputs.length; i++ )
		{
			inputs[i].disabled = '';
		}
	}
}


function giftClick(id)
{
	var checkBoxObj = document.getElementById(id);
	if ( !checkBoxObj.checked )
		disableTrWithInners('giftTable');
	else
		enableTrWithInners('giftTable');
		
}


function pageStartUp()
{
	disableTrWithInners('famRow1');
	//disableTrWithInners('famRow2');
	//disableTrWithInners('famRow3');
	//disableTrWithInners('famRow4');
	disableTrWithInners('famRow5');
	
	disableTrWithInners('studRow1');
	disableTrWithInners('studRow2');
}





function intOnly(i) {
	if(i.value.length>0) {
		i.value = i.value.replace(/[^\d]+/g, ''); 
	}
}




