// -------------------------------/
// ryzen design  .  content script
// version 1.0 . (c) copyright 2k4
// visit . http://www.ryzen.com.au 
// -------------------------------/


// global variables
var ary_images = new Array("btn_about_over.jpg","btn_student_over.jpg","btn_landfill_over.jpg","btn_contact_over.jpg","btn_joinlnow_over.jpg","btn_enquiry_over.jpg");
var ary_anchors = new Array(); // anchor array
var temp_obj; // holding object
var temp_win; // temporary popup window
var err = 0; // error counter

// -------------------/
// preload main images
// -------------------/
function preload()
{	for(i=0;i<ary_images.length;i++)
	{	var temp_img = new Image
			temp_img.src = "/resources/image/layout/"+ary_images[i]
	}
}
// ------------------------/
// change image over states
// ------------------------/
function over_state(dir,button)
{	button.src = dir+button.id+"_over.jpg";
}
function out_state(dir,button)
{	button.src = dir+button.id+".jpg";
}
function over_icon(dir,button)
{	button.src = dir+button.id+"_over.gif";
}
function out_icon(dir,button)
{	button.src = dir+button.id+".gif";
}
// ----------------------/
// retrieve anchor points
// ----------------------/
function set_quicklinks()
{	temp_obj = document.getElementsByName("anchor");
	if(temp_obj !== null)
	{	for(i=0;i<temp_obj.length;i++)
		{	ary_anchors[i] = new Array();
			ary_anchors[i][0] = temp_obj[i].title
			ary_anchors[i][1] = temp_obj[i].id
		}
		temp_obj = document.getElementById("anchor_box");
		for(j=0;j<ary_anchors.length;j++)
		{	temp_obj.innerHTML = temp_obj.innerHTML
			+	"<a href='#"+ary_anchors[j][1]+"' class='ticker'>"+ary_anchors[j][0]+"</a><br>"
			temp_obj.style.display = "block";
		}
	}
}
// --------------------/
// change local council
// --------------------/
function my_council(this_council)
{	if(this_council !== "")
	{	var ypos = (screen.height/2)-30;
		var xpos = (screen.width/2)-75;
		url = "/script/script_council.asp?council="+this_council;
		pref = "dependent=no,border=flat,status=no,width=140px,height=60px,left="+ xpos +",top="+ypos;
		temp_win = window.open(url,"temp_win",pref);
	}
}
// -----------------------/
// display HTML email help
// -----------------------/
function html_email()
{	var ypos = (screen.height/2)-65;
	var xpos = (screen.width/2)-145;
	url = "/contact/html_email.htm"
	pref = "dependent=no,border=flat,status=no,width=280px,height=130px,left="+ xpos +",top="+ypos;
	temp_win = window.open(url,"temp_win",pref);
}
// -----------------/
// join mailing list
// -----------------/
function join_list()
{	var my_first;
		my_first = document.all.join_first.value;
	var my_email;
		my_email = document.all.join_email.value;
	var my_format;
		if(document.all.join_html.checked == true)
		{	my_format = 1;
		}
		else{	my_format = 0;
		}
	var my_council;
		my_council = document.all.join_council.value;
	if(check(my_email) !== false)
	{
		if(my_first !== "" && my_email !== "")
		{	var ypos = (screen.height/2)-60;
			var xpos = (screen.width/2)-80;
			url = "/script/script_join.asp?first="+my_first+"&email="+my_email+"&format="+my_format+"&council="+my_council;
			pref = "dependent=no,border=flat,status=no,width=160px,height=120px,left="+ xpos +",top="+ypos;
			temp_win = window.open(url,"temp_win",pref);
			setTimeout('join_reset()',50)
		}
		else{	alert("You need to provide an email address, and first name before you can join our mailing list.")}
	}
}
// -----------------/
// join mailing list
// -----------------/
function join_reset()
{	var my_first;
		my_first = document.getElementById("join_first");
		my_first.value = "name"
	var my_email;
		my_email = document.getElementById("join_email");
		my_email.value = "your email address"
	var my_format;
		my_format = document.getElementById("join_html");
		my_format.checked = false;
}

// -------------------/
// clear name field
// -------------------/
function clear_name_field()
{

	var my_name = document.getElementById("join_first");

	if (my_name.value == "name") {
		my_name.select;
		my_name.value = "";
	} else {
		if (my_name.value.length == 0){
			my_name.select;
			my_name.value = "name";}
	}


}

// -------------------/
// clear email field
// -------------------/
function clear_email_field()
{	

	var my_email = document.getElementById("join_email");

	if (my_email.value == "your email address") {
		my_email.select;
		my_email.value = "";
	} else {
		if (my_email.value.length == 0){
			my_email.select;
			my_email.value = "your email address";}
	}


}
// ----------------------/
// validate email address
// ----------------------/
function check(this_email)
{	var chr_pos;
	var ary_periods = new Array();
	var err = 0;
	var periods = 0;	
	var email = new String
		email = this_email
	if(email.indexOf("@") == -1 || email.indexOf("@") == 0)
	{	err++
	}
	var result;
		result = email.indexOf(".");
	while(result != -1)
	{	ary_periods[periods] = new Array();	
		ary_periods[periods][0] = result
		result = email.indexOf(".",result+1);
		periods++
	}
	if(periods == 0 || periods > 3)
	{	err++
	}
	if(err > 0)
	{	alert("Your email address appears to be invalid. Please check and try again.")
		return false
	}
}