
function change_frames(frame_num)
{
appN=navigator.appName;
appV=navigator.appVersion;

img_name="";

if ((appN.indexOf("Microsoft") !=-1) && (appV.indexOf("Windows")!=-1)) msIE=true
else msIE=false;
										//frame two is directors frame - need hotspots, must use html page
extension=(frame_num==2)?".html":".gif";
path=(frame_num==2)?"frames/":"images/fireworks/";
prepath=(frame_num==2)?"":"../"			//apparently IE needs different paths depending on wheher it's dealing w/ img or html files

if(!msIE) img_name+= path + "frame_" + frame_num + extension + ""; 
else img_name = prepath + path + "frame_" + frame_num + extension + "";

(frame_num==2)?window.parent.frames['main_frame'].window.location=img_name:
window.parent.frames['main_frame'].document.images[0].src=img_name;

//loc="frames/frame_" + frame_num + ".html";
//window.parent.frames['main_frame'].location=loc; 
}
function show_hide_class(klass)
{
	d=document.getElementsByTagName('div');
	for (i=0; i<d.length; i++)
	{	
		if (d[i].className.indexOf(klass) != -1)
		{
			vis=d[i].style.visibility;
			if(vis=="visible")	hide_class(klass);
			else				show_class(klass);		
		}
	}
}	

function show_class(klass)
{

	d=document.getElementsByTagName('div');
	for (i=0; i<d.length; i++)
	{ 
	if (d[i].className.indexOf(klass) != -1 && d[i].id=="") 
		{
			d[i].style.display="block";
			d[i].style.visibility="visible";
		}
	}
}

function hide_class(klass)
{	
	d=document.getElementsByTagName('div');
	for (i=0; i<d.length; i++)
	{
		if (d[i].className.indexOf(klass) != -1) 
		{
			d[i].style.display="none";
			d[i].style.visibility="hidden";
		}
	}
}

function show_hide_id(id)
{	
	vis=document.getElementById(id).style.visibility;
	if(vis=="visible") hide_id(id);
	else				show_id(id);
}

function show_id(id)
{
	d=document.getElementById(id);
	d.style.visibility="visible";
	d.style.display="block";
	d.scrollIntoView(true);
	
}

function hide_id(id)
{	
	d=document.getElementById(id).style;
	d.visibility="hidden";
	d.display="none";
}

function hide_all_classes()
{
	d=document.getElementsByTagName('div')
	classes_hidden="";
		
	for (i=0; i<d.length; i++)
	{	className=d[i].className
		if(className!=null && classes_hidden.indexOf(className) == -1)
		{
			hide_class(className);
			classes_hidden += " " + className + " ";
		}
	}
}

function open_win(address,height,width,left)
{	
	if(height==null)height=550;
	if(width==null)width=850;
	if(left==null)left=100;
	height=height.toString();
	width=width.toString();	
	left=left.toString();
	win_str="height=" + height + ",width=" + width + ",left=" + left + ",top=20,location=no,scrollbars=yes,resizable=yes,toolbar=yes";
	w=window.open(address,'tempWin',win_str,'');
	//w.document.open();
	//w.document.clear();
	if(address.indexOf(".gif") !=-1 || address.indexOf(".jpg") != -1)
		 w.document.write("<html><body bgcolor='#ffffff'><div align='center'><img src='" + address + "' border=0></div></body></html>");
	else w.location=address;
	//w.document.close();
	w.focus();
}

function set_opener()//called from calling_card.php
{	
	parent_win=window.parent
	opener_loc=" " + parent_win.opener.location + " ";
	current_loc=" " + window.location + " ";
	if(opener_loc.indexOf("thankyou") !=-1 || current_loc.indexOf("thankyou") !=-1) ;		//opener is already at thankyou pg, don't go any farther
	else {
	//alert('chg');
	loc_str="thankyou.php";
	parent_win.opener.location=loc_str
	}
}

	
function create_viewer(text){
	
	doc_code="<html><head><link rel='STYLESHEET' type='text/css' href='../includes/stylesheet.css'></head>";
	doc_code+="<body bgcolor='#CCCCFF' topmargin=0 leftmargin=0 marginheight=0 marginwidth=0>";
	doc_code+="<br clear='all'><table width=85% bgcolor=#FFFFFF border=0><tr><td>";
	doc_code+=text
	doc_code+="</td></tr>";
	doc_code+="</table></body></html>";
	
	window_str="width=450,height=450,left=50,screenX=50,top=10,screenY=10,resizable=yes,directories=no,status=no,scrollbars=no,location=no,menubar=no,toolbar=no";
	w=window.open("","img_viewer",window_str,"false");
	w.document.clear();
	
	w.document.write(doc_code);
	w.document.close();
	w.focus();
}	
function gotopage(f,sb_name)	{		
	//make action of form: "javascript: gotopage(document.forms['form_name'],'sb_name');"
	//make onChange of sb: "onChange="document.forms['form_name'].submit()"
	sel_index=f.elements[sb_name].options.selectedIndex;
	location_str=f.elements[sb_name].options[sel_index].value;
	window.location=location_str;
}
void function retvoid(arg)	{
//good to use as href for an <a> tag that doesn't go anywhere but has javascript code in onClick
;
}
//********************************form validation***********************************

invalid=new Boolean(false);
err_msg="Please fill in the following fields: \n \n";

function is_null(value)
{
	if(value==null || value=="" || value==" ")	return true;
	else return false;
}
function add_to_err_msg(field)
{
	if(field.indexOf("x_")!=-1)			//field="x_Ship_To_Address
		field=field.substring(2,field.length);
	err_msg += field + "\n";
	invalid=true;
}
function validate_form(form_name, required_fields)
{	
	var check_name;
	elements_array=required_fields.split(",");
	err_msg="Please fill in the following fields: \n \n";
	//alert(elements_array.length);
	for(i=0; i<=elements_array.length-1; i++)
	{
		s="document.forms['" + form_name + "'].elements['" + elements_array[i] + "']";
		type=eval(s + ".type");
		name=eval(s + ".name");
//alert(name + " " + i);
		if (type=="text" || type=="textarea" || type=="password")
		{
			value=eval(s + ".value");
			if(is_null(value)) add_to_err_msg(name)
			else if (!is_null(value) && (name=="cardnumber" || name=="cc_number"))
			{
				if (value.indexOf(" ") !=-1 || value.indexOf("-") !=-1)
					add_to_err_msg(name + " - without spaces or dashes " + "\n");
				else
				{
					if(value.length==16)	{
						cc_pattern=/\d{16}/;
						if(!cc_pattern.test(value))	{
							add_to_err_msg(name + " - not of the correct length or format (no spaces or dashes)" + "\n");
						}
					}
					else if(value.length==15)	{	//amex cards are only 15 digits
						cc_pattern=/\d{15}/;
						if(!cc_pattern.test(value))	{
							add_to_err_msg(name + " - not of the correct length or format (no spaces or dashes)" + "\n");
						}
					}
					else if (value.length !=16)	{
						add_to_err_msg(name + " - not of the correct length or format (no spaces or dashes)" + "\n");
					}
				}
			}
			else if(!is_null(value) && name=="zip")	
			{
				if(value.length<5) add_to_err_msg("Zip code not of the correct length");
				else {
					for(j=0;j<value.length;j++)	{
						if (value.charAt(j)!=0 && !parseInt(value.charAt(j)))	{
							add_to_err_msg(name + " must consist of only numbers " + "\n");
							break;
						}
					}
				}	
			}
			else if(name=="phone")	{
				strng=value;
				var stripped = strng.replace(/[\(\)\.\-\ ]/g, '');
				//strip out acceptable non-numeric characters
				if (isNaN(parseInt(stripped))) {
				   add_to_err_msg("The phone number contains illegal characters.");
				}
				//Then we count the length of the number. It should have exactly ten digits -- any more or less, and we reject it.
				
				if (!(stripped.length == 10)) {
					add_to_err_msg("The phone number is the wrong length. Make sure you included an area code.\n");
				}

				
				/*
				phoneReg = "^(?:[\(][0-9]{3}[\)]|[0-9]{3})[-. ]?[0-9]{3}[-. ]?[0-9]{4}$";
				var regex=new RegExp();
				if(regex)	{
					if (!regex.test(value)) {
						add_to_err_msg("Please enter a valid Phone number plus Area Code.\n");
						break;
					}
				}
				*/
			}
			else if(name=="cvm")	{
				if(value.length<3) add_to_err_msg("CVM number not of the correct length (it is either 3 or 4 numbers long).");
				else {
					for(j=0;j<value.length;j++)	{
						if (value.charAt(j)!=0 && !parseInt(value.charAt(j)))	{
							add_to_err_msg(name + " must consist of only numbers " + "\n");
							break;
						}
					}
				}
			}
		}
		else if (type.indexOf("select")!=-1)
		{
			selectedIndex=eval(s + ".selectedIndex");
			if(selectedIndex==-1) add_to_err_msg(name);
		}
		else if (type=="radio")
		{;
		}
		//else if (type=="checkbox" && name!=check_name)
		//last part ensures that this loop is not executed for each element of the checkbox
		//{;
			/*
			check_length=eval("document." + form_name + ".elements['" + name + "'].length");
			alert(document.f.one.length);
			
			check_name=name;
			if (check_length > 1)		//group of checkboxes in form
			{
				for (j=0; i<check_length; i++)
				{
					checked=eval(form_name + "." + name + "[" + j + "]");
					alert(checked)
					if (checked) break;
					else if (j==check_length-1) err_msg += name + "\n";
				}*/
		} 
		
	if(invalid==true && err_msg.length>40)
	{
		alert(err_msg);
		return false;
	}
	else return true;
}

