var browserName = navigator.appName; 
var links = '';
var browser_check = '';
var myshowcase = new Array ("../images/my_basic.gif" ,
							"images/my_business.gif" ,
							"images/my_personal.gif" ,
							"images/bottom_grey_box.gif" , 
							"images/bottom_left_box.gif" ,
							"images/bottom_right_box.gif" ,
							"images/grey_bar.gif" ,
							"images/grey_strip.gif" ,
							"images/grey_strip_middle.gif" ,
							"images/top_grey_box.gif" ,
							"images/top_left_box.gif" ,
							"images/top_right_box.gif" ,
							"images/banner_bottom.gif" ,
							"images/banner_strip.gif" , 
							"images/banner_top.gif" ,
							"images/blue_bar.gif");

if (browserName=="Netscape")
{ 
	links = 'links_net';
	browser_check = "netscape";
}
else 
{
	if (browserName=="Microsoft Internet Explorer")
	{
		links = 'links_ie';
		browser_check = "ie";
	}
	else
	{
		links = 'links_net';
		browser_check = "ie";
	}
}
function preload_images(){
	var images = new Array;

	for (var pic_num = 0; pic_num < myshowcase.length; pic_num++)
	{
		images[pic_num] = new Image();
		images[pic_num].src = myshowcase[pic_num];
	}
}
function check_email(){
	var str = document.email_form.Email.value;
	var filter = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
	
	if (filter.test(str))
		return true;
	else
		return false;
}
function calculator_form(which){
	//initialize variables
	var count_form = 0;
	var radio_counter = 0;
	var radio_group = 0;
	var total_check = 0;
	var alertmsg_form = '';		
	
	for ( i = 0; i < document.form1.elements.length; i++ )
	{//loop through form for empty elements		
		temp = 0;//set back to 0
		radio_counter = radio_counter + radio_group;//add the elements of radio group so next group is detected
		radio_group = 0;//set back to 0
		test = document.form1.elements[radio_counter].getAttribute('name');//get radio group name
		papas =	eval("document.form1." + test +".length");//read the length of the group
		for (var x = 0; x < papas; x++)
		{//loop through the radio group
			if (eval("document.form1." + test + "[" + x + "].checked") == true)//check if radio button checked
			//check if checked
				count_form++;//add to count form
			radio_group++;//increase radio_group so we can detect how many elemnts in radio group name
			temp = papas - x;//check how many times we looped
		}//end for loop
		total_check = total_check + temp;//check how many times we looped
	}//end for loop
	
	if(count_form == total_check)
	//if how many loop times equal with total count, correct
		return true;
	else
	{//else false
		alert('There are ' + eval(total_check - count_form) + ' field/s that are missing' );
		return false;	
	}//end else
}
function checkform(which){
	var count = 0;
	var alertmsg = '';		

	for ( i = 0; i < document.email_form.elements.length; i++ )
	{//loop through form for empty elements
		if((document.email_form.elements[i].value == "")&&(document.email_form.elements[i].name != "Address"))
		{
			alertmsg = alertmsg +' '+ document.email_form.elements[i].name +'\n';
			count++;
		}
	}
	
	if((count == 0)&&(check_email() == true))//everything is filled up
		return true;//submit form
	else
	{
		if(count >= 1)
		{//no its not filled
			alert('The following are required\nFields with an * (asterisk) are required\n' + alertmsg);
			return false;
		}
		else
		{
			if(check_email() == false)
			{//email is in wrong format
				alert("Email should be in format name@email.com");
				return false;
			}
		}
	}
}
function init(){
	hidelayer();
	setZIndex('moto','submenu');
	preload_images();
	
	var logo = 0;
	var moto = 0;
	var main_table_text = 0;
	var main_table = 0;
	var cms_table = 0;
	var offers_table = 0;
	var bottom_table = 0 ;
	var bottom = 0;
	var more = 15;
	
	logo = parseInt(document.getElementById('logo').offsetHeight);
	moto = parseInt(document.getElementById(links).offsetHeight);
	main_table_text = parseInt(document.getElementById('main_table_text').offsetHeight);
	
	main_table = parseInt(document.getElementById('main_table').offsetHeight);
	cms_table = parseInt(document.getElementById('cms_table').offsetHeight);
	
	
	offers_table = main_table + cms_table + logo + moto;
	bottom_table = main_table_text + moto + logo;
	if(bottom_table <= offers_table)
		bottom = offers_table + more;
	else
		bottom =  bottom_table + more;
		
	widthbottomtable(bottom);
}
function widthbottomtable(x){
	var bottom = x;
	bottom = bottom + 'px';
	document.getElementById('bottom_table').style.top = bottom;
}
function showlayer(){
	document.getElementById('submenu').style.visibility="visible";
}
function hidelayer(){
	document.getElementById('submenu').style.visibility="hidden";
}
function setZIndex(id,id_2) {
	if(browser_check == "netscape")
	{	
		document.getElementById(id).style.zIndex = 0;
		document.getElementById(id_2).style.zIndex = 1;
	}
	else
	{
		if(browser_check == "ie")
		{
			document.getElementById(id).style.zIndex = -1;
			document.getElementById(id_2).style.zIndex = 1;
		}
	}
}
