/* *********************************************************** 
 *	FUNCTION:	open_link
 *	PURPOSE: 	open new window
 * ********************************************************* */

//function open_link(url, width, height, name, location, scrollbars, resizable) {
function open_link(url, width, height) {
  // width, height, name, location and scrollbars are optional
  //
  // Pop up a new window named LoudDog with a default size of 685 x 480
  // window name of LoudDog and no location bar.


  var namenum = Math.round(Math.random() * 10000);
  if (width      == null) width=680;
  if (height     == null) height=450;
  var name="ClearBead" + namenum;
  var location='no';
  var scrollbars='no';
  var resizable='no';
  var opts="menubar=no,toolbar=no,scrollbars=" + scrollbars + ",resizable=" + resizable + ",fullsize=no,width="
           + width + ",height=" + height + ",location=no";

  winref=window.open(url,name,opts);
  winref.focus();
}

/* *********************************************************** 
 *	FUNCTION:	closewin
 *	PURPOSE: 	close an opened window
 * ********************************************************* */
 
function closewin() {
	window.close();
	}

/* *********************************************************** 
 *	FUNCTION:	redirParent
 *	PURPOSE: 	redirect a parent window
 * ********************************************************* */
function redirParent(url) {
	opener.document.location = url;
	}


/* *********************************************************** 
 *	FUNCTION:  valildateForm
 *	PURPOSE: validateForm input
 * ********************************************************* */
var bad_char_errors = new Array();
var errors = new Array();

function validateForm(form) {
	var f=form;
	var errdiv = document.getElementById("errmsg");
	
	var form_elements = new Array();

	form_elements = [['toemails','Email Addresses'],
					 					 ['fromemail','Your Email Address']]
					 					
	
	for ( i = 0; i < form_elements.length; i++ ) {
		if ( document.getElementById(form_elements[i][0]) ) {
			var e = eval('f.' + form_elements[i][0] + '.value');
			
			if (!e) {
				errors.push('<span>&middot; '+form_elements[i][1]+' is required</span>');
				document.getElementById(form_elements[i][0]).className= "highlight";
			} else {
				if (form_elements[i][1] == "Email") { //verify email address
					if (! chk_email(e)) {
						document.getElementById(form_elements[i][0]).className= "highlight";
					} else {
						document.getElementById(form_elements[i][0]).className= "";
					}
				
				} else {
					document.getElementById(form_elements[i][0]).className= ""; //clear class="HIGHLIGHT" retained from non reload
				}
			}
		}		
	}
	
	/*var c = document.getElementById('checkboxlist');
	if (c) {
		if (!f.check1.checked && !f.check2.checked && !f.check3.checked && !f.check4.checked) { 
			c.className = "highlight";
			errors.push('<span>&middot; Choose a product for download</span>');
		} else {
			c.className = "";
		}
	}*/
	

	if (errors[0] || bad_char_errors[0]) {
		errdiv.style.display = "block";
		errdiv.innerHTML = 'Please correct the following errors: ';
		if (errors[0]) {
			for( j = 0; j < errors.length; j++ ) {
				errdiv.innerHTML += errors[j]
			}
		}
		
		if (bad_char_errors[0]) {
			for( x = 0; x < bad_char_errors.length; x++ ) {
				errdiv.innerHTML += bad_char_errors[x]
			}
		}
		errors.length = 0;
		bad_char_errors.length = 0;
		return false;
		
	} else if (!errors[0] && !bad_char_errors[0]){
		errdiv.style.display = "none";
		f.submit();
		return true;
		
	}

}


function writeStates() {
	var states = new Array ('AL',
							'AK',
							'AS',
							'AZ',
							'AR',
							'CA',
							'CO',
							'CT',
							'DE',
							'DC',
							'FL',
							'GA',
							'HI',
							'ID',
							'IL',
							'IN',
							'IA',
							'KS',
							'KY',
							'LA',
							'ME',
							'MD',
							'MA',
							'MI',
							'MN',
							'MS',
							'MO',
							'MT',
							'NE',
							'NV',
							'NH',
							'NJ',
							'NM',
							'NY',
							'NC',
							'ND',
							'OH',
							'OK',
							'OR',
							'PA',
							'RI',
							'SC',
							'SD',
							'TN',
							'TX',
							'UT',
							'VT',
							'VA',
							'WA',
							'WV',
							'WI',
							'WY');
	var len = states.length;
	for (m=0;m<len;m++) {
    var m_txt = states[m];
    document.write('<option value="'+ m_txt +'">' + m_txt +'</option>');
  } 
}

function safe(text){
	var alink = new Array;
	var name = new Array;
	alink['jake'] = 'm&#97;il&#116;&#111;:jake&#64;&#106;&#97;&#107;e&#50;006&#46;&#99;&#111;m';
	alink['webmaster'] = 'm&#97;&#105;&#108;&#116;o&#58;web&#109;as&#116;e&#114;&#64;&#106;ake2006&#46;c&#111;m';
	name['jake'] = 'j&#97;ke&#64;&#106;&#97;&#107;e&#50;&#48;&#48;&#54;&#46;&#99;om';
	name['webmaster'] = '&#119;&#101;&#98;ma&#115;ter&#64;&#106;&#97;&#107;&#101;&#50;&#48;&#48;&#54;&#46;co&#109;';
	
	document.write('<a href="' + alink[text] + '">' + name[text] + '</a>');
}

/* *********************************************************** 
 *  PHP LIST FUNCTIONS
 * ********************************************************* */

/* ***********************************************************
 *	FUNCTION:  checkform
 *	PURPOSE: validateForm input
 * ********************************************************* */

var fieldstocheck = new Array();
    fieldnames = new Array();

function checkform() {
  for (i=0;i<fieldstocheck.length;i++) {
    if (eval("document.subscribeform.elements['"+fieldstocheck[i]+"'].value") == "") {
      alert("Please enter your "+fieldnames[i]);
      eval("document.subscribeform.elements['"+fieldstocheck[i]+"'].focus()");
      return false;
    }
  }

  return true;
}

/* ***********************************************************
 *	FUNCTION:  addFieldToCheck
 *	PURPOSE: prepare form field for validation
 * ********************************************************* */

function addFieldToCheck(value,name) {
  fieldstocheck[fieldstocheck.length] = value;
  fieldnames[fieldnames.length] = name;
}

/* ***********************************************************
 *	FUNCTION:  compareEmail
 *	PURPOSE: if you ask for e-mail re-entry, compare the two
 * ********************************************************* */

function compareEmail()
{
  return (document.subscribeform.elements["email"].value == document.subscribeform.elements["emailconfirm"].value);
}