// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
// %% IRATA Main JS File                         %%
// %% By Craig Allen                             %%
// %% craig_bassman [at] bellsouth [decimal] net %%
// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

// 07/08/08 - v1.00 - Initial Release
// 08/10/08 - v1.01 - Added Slide Up/Down script for Tour Dates

var all_address = "irata";
var domain = "irataLIVE.com";
var mail_command = "mailto:";
var focused_border = "#AAAAAA";
var imageSet = new Array();

if (window != window.top)
{
	top.location.href = location.href;
}

function goTo(url)
{
	window.location.href = url;
}

function checkEmailAddress(email)
{
	var illegal_characters = new Array("(", ")", "\\", "[", "]", ":", ";", "<", ">", ",", "\"", "/");
	var last_char = email.charAt(email.length - 1);
	var first_char = email.charAt(0);
	var email_length = email.length;
	var error = "";
	var beg_error = "'" + email + "' is not a valid e-mail address:\n";
	var end_error = "!\nIt should be name@domain.com";
	while (first_char == " ")
	{
		email = email.substring(1, email_length);
		first_char = email.charAt(0);
		email_length = email.length;
	}
	while (last_char == " ")
	{
		email = email.substring(0, email_length - 1);
		email_length = email.length;
		last_char = email.charAt(email_length - 1);
	}
	var where_at_is = email.indexOf("@");
	var char_before_at = email.charAt(where_at_is - 1);
	var where_dot_is = email.indexOf(".");
	var second_to_last_char = email.charAt(email.length - 2);
	var where_dot_after_at_is = email.indexOf(".", where_at_is);
	var space_after_at = email.indexOf(" ", where_at_is);
	if ((email == "") || (email == "Enter E-Mail") || (email == null))
	{
		error = "You forgot to enter your e-mail address!";
		return error;
	}
	else if (email.indexOf("@", where_at_is + 1) != -1)
	{
		error = beg_error + "it can't have more than one '@' in it" + end_error;
	}
	else if (where_at_is == -1)
	{
		error = beg_error + "you forgot the '@'" + end_error;
	}
	else if ((where_dot_after_at_is < where_at_is + 3) || (last_char == ".") || (where_dot_is == -1) || (second_to_last_char == ".") || (space_after_at != -1))
	{
		error = beg_error + "'" + email.substring(where_at_is + 1, email_length) + "' is not a proper Domain Name" + end_error;
	}
	else if (char_before_at == ".")
	{
		error = beg_error + "you can't have a '.' right before the '@'" + end_error;
	}
	else if ((first_char == ".") || (first_char == "@"))
	{
		error = beg_error + "you can't have a '" + first_char + "' as the first character" + end_error;
	}
	else if (email_length < 6)
	{
		error = beg_error + "it's too short" + end_error;
	}
	else
	{
		for (i = 0; i < illegal_characters.length; i++)
		{
			if (email.indexOf(illegal_characters[i]) != -1)
			{
				error = beg_error + "it can't have the character '" + illegal_characters[i] + "' in it" + end_error;
				break;
			}
		}
	}
	return error;
}

function checkEmailField(email)
{
	var error = checkEmailAddress(email);
	if (error != "")
	{
		alert(error);
		focused_border = "red";
		email_form.focus();
		return false;
	}    
	return true;
}

function changeField(field, value, original_value, new_value)
{
	if (value == original_value)
	{
		field.value = new_value;
	}
	if (new_value == "")
	{		
		field.style.borderColor = focused_border;
		focused_border = "#AAAAAA";
	}
	else
	{
		field.style.borderColor = "#595959";
	}
	return;
}

function doPreload()
{
	for (i = 0; i < the_images.length; i++)
	{
		imageSet[the_images[i]] = new Image();
		imageSet[the_images[i]].src = "../files/images/" + the_images[i];
	}
}

function menuChange(cell, pic, in_out)
{
	var ro = "";
	if (in_out == "in")
	{
		ro = "_ro";
	}
	cell.className = "menu" + ro;
	swapImage(pic, pic + ro + ".gif")
}

function swapImage(image_name, file_name)
{
	if (imageSet[file_name] != undefined)
	{
		document.images[image_name].src = imageSet[file_name].src;
	}
	else
	{
		document.images[image_name].src = "../files/images/" + file_name;
	}
}

function checkContactForm()
{
	var error = "";
	var error2 = "";
	error = checkEmailAddress(contact_form.con_email.value);
	if (error != "")
	{
		contact_form.con_email.style.borderColor = "red";
		error = "\n" + error;
	}
	if ((contact_form.c_message.value == "") || (contact_form.c_message.value == null))
	{
		error2 = "\nYou forgot to type a message!";
		contact_form.c_message.style.borderColor = "red";
	}
	else if (contact_form.c_message.value.length < 2)
	{
		error2 = "\nYou didn't finish your message!";
		contact_form.c_message.style.borderColor = "red";
	}
	if ((error == "") && (error2 == ""))
	{
		return true;
	}
	focused_border = "red";
	var plural = "";
	if (error != "")
	{
		start_field = contact_form.con_email;
	}
	else if (error2 != "")
	{
		start_field = contact_form.c_message;
	}
	if ((error != "") && (error2 != ""))
	{
		plural = "s";
	}
	alert("The Contact Form has the following error" + plural + ":\n" + error + error2);
	start_field.focus();
	return false;
}

function checkLength(field)
{
	if (field.value.length > 5000)
	{
		alert("The message is at it's maximum length - 5,000 characters!");
		field.value = field.value.substring(0, 5000);
	}
}

function openPicture(file)
{
	var display = window.open("gallery_window.php?file=" + file, "display", "width=490, height=500");
	display.focus();
}

function showWindow(number)
{
	var display = window.open("../show_window.php?number=" + number, "display", "scrollbars=1, width=400, height=250, resizable=1");
	display.focus();
}

function checkStore(qty, form)
{
	var cart_error = "";
	if ((isNaN(qty)) || (qty == "") || (qty == "  ") || (qty == "   ") || (qty == " "))
	{
		alert("The Quantity must be a number!\nPlease correct it!");
		focused_border = "red";
		form.focus();
		form.style.borderColor = "red";
		return false;
	}
	else
	{
		return true;
	}
}

function showGigDetails(gig_no, direction)
{
	var identity = "show_div_" + gig_no;
	if (direction == "up")
	{
		animatedcollapse.hide(identity);
		document.getElementById("details_" + gig_no).innerHTML = "&nbsp; <table border=0 cellpadding=0 cellspacing=0 style='display: inline;'><tr><td class='p_m' onMouseOver='document.getElementById(\"ul_" + gig_no + "\").className=\"no_ul\";' onMouseOut='document.getElementById(\"ul_" + gig_no + "\").className=\"ul\";' onClick='showGigDetails(" + gig_no + ", \"down\");'>+</td><td>&nbsp;<a href='javascript:showGigDetails(" + gig_no + ", \"down\");' id='ul_" + gig_no + "' class='ul' onMouseOver='this.className=\"no_ul\";' onMouseOut='this.className=\"ul\";'>Show Details</a></td></tr></table>";
	}
	else
	{
		animatedcollapse.show(identity);
		document.getElementById("details_" + gig_no).innerHTML = "&nbsp; <table border=0 cellpadding=0 cellspacing=0 style='display: inline;'><tr><td class='p_m' onMouseOver='document.getElementById(\"ul_" + gig_no + "\").className=\"no_ul\";' onMouseOut='document.getElementById(\"ul_" + gig_no + "\").className=\"ul\";' onClick='showGigDetails(" + gig_no + ", \"up\");'>-</td><td>&nbsp;<a href='javascript:showGigDetails(" + gig_no + ", \"up\");' id='ul_" + gig_no + "' class='ul' onMouseOver='this.className=\"no_ul\";' onMouseOut='this.className=\"ul\";'>Hide Details</a></td></tr></table>";		
	}
}
