function openWin(url, width, height) {
	var win;
	var windowName;
	var params;
	windowName  = "buttons";
	params = "toolbar=0,";
	params += "location=0,";
	params += "directories=0,";
	params += "status=1,";
	params += "menubar=0,";
	params += "scrollbars=1,";
	params += "resizable=0,";
	params += "top=50,";
	params += "left=50,";
	params += "width="+width+",";
	params += "height="+height;
	win = window.open(url, windowName, params);
}

function openWin2(url, width, height) {
	var win;
	var windowName;
	var params;
	windowName  = "buttons";
	params = "toolbar=0,";
	params += "location=0,";
	params += "directories=0,";
	params += "status=0,";
	params += "menubar=0,";
	params += "scrollbars=1,";
	params += "resizable=1,";
	params += "top=50,";
	params += "left=50,";
	params += "width="+width+",";
	params += "height="+height;
	win = window.open(url, windowName, params);
}

function popSend(url, width, height, reqVars) {
	var win;
	var windowName;
	var params;
	windowName  = "buttons";
	params = "toolbar=0,";
	params += "location=0,";
	params += "directories=0,";
	params += "status=1,";
	params += "menubar=0,";
	params += "scrollbars=1,";
	params += "resizable=0,";
	params += "top=50,";
	params += "left=50,";
	params += "width="+width+",";
	params += "height="+height;
	win = window.open(url+"?"+reqVars, windowName, params);
}

window.onload = function() {
	setContainerHeight();
}

function setContainerHeight() {
	// if window is bigger than div#container, set #container to height of window so bg image extends to bottom
	var windowHeight = window.innerHeight ? window.innerHeight : document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body.clientHeight;
	if (document.getElementById('container')) {
		if (windowHeight > document.getElementById('container').offsetHeight) {
		  document.getElementById('container').style.height = windowHeight + 'px';
		}
	}
}



function validate_stf()
{
	if (document.stf1.your_name.value == "")
	{
		alert ("Please fill in 'Your Name'.");
		document.stf1.your_name.focus();
		return false;
	}
	if (document.stf1.your_email.value == "")
	{
		alert ("Please fill in 'Your Email'.");
		document.stf1.your_email.focus();
		return false;
	}
	if (!/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(document.stf1.your_email.value)){
		alert ("'Your Email' is in an incorrect format.");
		document.stf1.your_email.focus();
		return false;
	}
	if (document.stf1.friends_name.value == "")
	{
		alert ("Please fill in 'Friends Name'.");
		document.stf1.friends_name.focus();
		return false;
	}
	if (document.stf1.friends_email.value == "")
	{
		alert ("Please fill in 'Friends Email'.");
		document.stf1.friends_email.focus();
		return false;
	}
	if (!/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(document.stf1.friends_email.value)){
		alert ("'Friends Email' is in an incorrect format.");
		document.stf1.friends_email.focus();
		return false;
	}

	return true;
}





function validate_reg1()
{

	var found_title = false;

	for (var i=0; i<document.reg1.title.length; i++)  {
		if (document.reg1.title[i].checked && document.reg1.title[i].value != "other")
		{
		found_title = true;
		}
	}
	if (document.reg1.title_other.value != "")
	{
		found_title = true;
	}
	if (found_title == false)
	{
		alert ("Please select your degree.");
		return false;
	}
	if (document.reg1.first_name.value == "")
	{
		alert ("Please fill in the 'First Name'.");
		document.reg1.first_name.focus();
		return false;
	}
	if (document.reg1.last_name.value == "")
	{
		alert ("Please fill in the 'Last Name'.");
		document.reg1.last_name.focus();
		return false;
	}
	if (document.reg1.address1.value == "")
	{
		alert ("Please fill in the 'Address 1'.");
		document.reg1.address1.focus();
		return false;
	}
	if (document.reg1.city.value == "")
	{
		alert ("Please fill in the 'City'.");
		document.reg1.city.focus();
		return false;
	}
	if (document.reg1.state.value == "")
	{
		alert ("Please select a 'State'.");
		document.reg1.state.focus();
		return false;
	}
	if (document.reg1.postal_code.value == "")
	{
		alert ("Please fill in the 'Postal Code'.");
		document.reg1.address1.focus();
		return false;
	}
	if (document.reg1.country.value == "")
	{
		alert ("Please select a 'Country'.");
		document.reg1.country.focus();
		return false;
	}
	if (document.reg1.email.value == "")
	{
		alert ("Please fill in the 'Email Address'.");
		document.reg1.email.focus();
		return false;
	}
	if (!/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(document.reg1.email.value)){
		alert ("'Email Address' is in an incorrect format.");
		document.reg1.email.focus();
		return false;
	}
	if (document.reg1.email2.value == "")
	{
		alert ("Please fill in the 'Confirm Email'.");
		document.reg1.email2.focus();
		return false;
	}
	if (!/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(document.reg1.email2.value)){
		alert ("'Confirm Email' is in an incorrect format.");
		document.reg1.email2.focus();
		return false;
	}
	if (document.reg1.email.value != document.reg1.email2.value)
	{
		alert ("'Email Address' and 'Confirm Email' do not match.");
		document.reg1.email2.focus();
		return false;
	}

	return true;
}



function validate_reg2()
{

	var found_spec = false;
	var found_ded = false;


	if (document.reg2.spec_neurology.checked == false && document.reg2.spec_psychiatry.checked == false && document.reg2.spec_familypractice.checked == false && document.reg2.spec_rehabilitation.checked == false && document.reg2.spec_nursing.checked == false && document.reg2.specialty_other.value == "")
	{
		alert ("Please choose Your Specialty or fill in 'Other'.");
		document.reg2.specialty_other.focus();
		return false;
	}
	for (var i=0; i<document.reg2.dedicate.length; i++)  {
		if (document.reg2.dedicate[i].checked)
		{
		found_ded = true;
		}
	}
	if (document.reg2.dedicate_other.value != "")
	{
		found_ded = true;
	}
	if (found_ded == false)
	{
		alert ("Please choose which field you dedicate your time.");
		document.reg2.dedicate_other.focus();
		return false;
	}

	return true;

}



function validate_reg1_pc()
{
	var found_age = false;
	var found_gender = false;

	if (document.reg1.first_name.value == "")
	{
		alert ("Please fill in the 'First Name'.");
		document.reg1.first_name.focus();
		return false;
	}
	if (document.reg1.last_name.value == "")
	{
		alert ("Please fill in the 'Last Name'.");
		document.reg1.last_name.focus();
		return false;
	}
	if (document.reg1.address1.value == "")
	{
		alert ("Please fill in the 'Address 1'.");
		document.reg1.address1.focus();
		return false;
	}
	if (document.reg1.city.value == "")
	{
		alert ("Please fill in the 'City'.");
		document.reg1.city.focus();
		return false;
	}
	if (document.reg1.state.value == "")
	{
		alert ("Please select a 'State'.");
		document.reg1.state.focus();
		return false;
	}
	if (document.reg1.postal_code.value == "")
	{
		alert ("Please fill in the 'Postal Code'.");
		document.reg1.postal_code.focus();
		return false;
	}
	if (document.reg1.country.value == "")
	{
		alert ("Please select a 'Country'.");
		document.reg1.country.focus();
		return false;
	}
	if (document.reg1.email.value == "")
	{
		alert ("Please fill in the 'Email Address'.");
		document.reg1.email.focus();
		return false;
	}
	if (!/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(document.reg1.email.value)){
		alert ("'Email Address' is in an incorrect format.");
		document.reg1.email.focus();
		return false;
	}
	if (document.reg1.email2.value == "")
	{
		alert ("Please fill in the 'Confirm Email'.");
		document.reg1.email2.focus();
		return false;
	}
	if (!/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(document.reg1.email2.value)){
		alert ("'Confirm Email' is in an incorrect format.");
		document.reg1.email2.focus();
		return false;
	}
	if (document.reg1.email.value != document.reg1.email2.value)
	{
		alert ("'Email Address' and 'Confirm Email' do not match.");
		document.reg1.email2.focus();
		return false;
	}
	for (var i=0; i<document.reg1.age.length; i++)  {
		if (document.reg1.age[i].checked)
		{
			found_age = true;
		}
		if (document.reg1.age[0].checked)
		{
			toggleLayer('warn2','open');
			return false;
		}
	}
	for (var i=0; i<document.reg1.gender.length; i++)  {
		if (document.reg1.gender[i].checked)
		{
			found_gender = true;
		}
	}
	if (found_age == false)
	{
		alert ("Please choose your approximate age.");
		document.reg1.age[0].focus();
		return false;
	}
	if (found_gender == false)
	{
		alert ("Please choose your gender.");
		document.reg1.gender[0].focus();
		return false;
	}

	return true;
}



function validate_reg2_pc()
{

	var found_diagnosed = false;

	for (var i=0; i<document.reg2.diagnosed.length; i++)  {
		if (document.reg2.diagnosed[i].checked)
		{
		found_diagnosed = true;
		}
	}
	if (document.reg2.medication_antidepressants.checked == false && document.reg2.medication_antipsychotics.checked == false && document.reg2.medication_lithium.checked == false && document.reg2.medication_rehabilitation.checked == false && document.reg2.medication_tegretol.checked == false && document.reg2.medication_other.checked == false && document.reg2.medication_no.checked == false)
	{
		alert ("Please choose you currently taking any medication(s) for PBA.");
		document.reg2.medication_antidepressants.focus();
		return false;
	}
	if (found_diagnosed == false)
	{
		alert ("Please choose which field you been diagnosed with PBA.");
		document.reg2.diagnosed[0].focus();
		return false;
	}

	return true;

}



function validate_reg3()
{

	if (document.reg3.affirm.checked ==  false)
	{
		alert ("Please confirm your registration.");
		document.reg3.affirm.focus();
		return false;
	}

	return true;

}




function validate_comments()
{
	if (document.contact_form.contact_name.value == "")
	{
		alert ("Please fill in the 'Name'.");
		document.contact_form.contact_name.focus();
		return false;
	}
	if (document.contact_form.contact_email.value == "")
	{
		alert ("Please fill in the 'Email Address'.");
		document.contact_form.contact_email.focus();
		return false;
	}
	if (!/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(document.contact_form.contact_email.value)){
		alert ("Please your 'Email Address' is in an incorrect format.");
		document.contact_form.contact_email.focus();
		return false;
	}
	if (document.contact_form.contact_message.value == "")
	{
		alert ("Please fill in the 'Message'.");
		document.contact_form.contact_message.focus();
		return false;
	}
	
	return true;
}




function validate_man_reg()
{
	if (document.man_reg.last_name.value == "")
	{
		alert ("Please fill in the 'Last Name'.");
		document.man_reg.last_name.focus();
		return false;
	}
	if (document.man_reg.email_address.value == "")
	{
		alert ("Please fill in the 'Email Address'.");
		document.man_reg.email_address.focus();
		return false;
	}
	if (!/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(document.man_reg.email_address.value)){
		alert ("Please your 'Email Address' is in an incorrect format.");
		document.man_reg.email_address.focus();
		return false;
	}
	
	return true;
}





function validate_man_update()
{
	if (document.man_reg2.address1.value == "")
	{
		alert ("Please fill in the 'Address 1'.");
		document.man_reg2.address1.focus();
		return false;
	}
	if (document.man_reg2.city.value == "")
	{
		alert ("Please fill in the 'City'.");
		document.man_reg2.city.focus();
		return false;
	}
	if (document.man_reg2.state.value == "")
	{
		alert ("Please select a 'State'.");
		document.man_reg2.state.focus();
		return false;
	}
	if (document.man_reg2.postal_code.value == "")
	{
		alert ("Please fill in the 'Postal Code'.");
		document.man_reg2.postal_code.focus();
		return false;
	}
	if (document.man_reg2.country.value == "")
	{
		alert ("Please select a 'Country'.");
		document.man_reg2.country.focus();
		return false;
	}

	return true;
}




function country_change() {
	var select_element = document.form1.country;
	
	var usa_tbody = document.getElementById('usa_block');
	var canada_tbody = document.getElementById('canada_block');
	var other_tbody = document.getElementById('other_block');
	
	if (select_element.value == '124') {
	
		/* canada chosen */
		canada_tbody.className = 'tbody_show';
		usa_tbody.className = 'tbody_hide';
		other_tbody.className = 'tbody_hide';
	} else if (select_element.value == '840') {
	
		/* usa chosen */
		canada_tbody.className = 'tbody_hide';
		usa_tbody.className = 'tbody_show';
		other_tbody.className = 'tbody_hide';
	} else if (select_element.value != '') {
	
		/* other chosen */
		canada_tbody.className = 'tbody_hide';
		usa_tbody.className = 'tbody_hide';
		other_tbody.className = 'tbody_show';
	} else {
	
		/* none chosen */
		canada_tbody.className = 'tbody_hide';
		usa_tbody.className = 'tbody_hide';
		other_tbody.className = 'tbody_hide';
	}
}

function toggleLayer(whichLayer,mode){

	if (document.getElementById){
		// this is the way the standards work
		var style2 = document.getElementById(whichLayer).style;
	}
	else if (document.all){
		// this is the way old msie versions work
		var style2 = document.all[whichLayer].style;
	}
	else if (document.layers){
		// this is the way nn4 works
		var style2 = document.layers[whichLayer].style;
	}

	if(mode=='close'){style2.display = "none";}
	else if(mode=='open'){style2.display = "block";}
	else{style2.display = style2.display=="block"?"none":"block";}
}


function toggleLayerSend(whichLayer,mode){

	if (document.getElementById){
		// this is the way the standards work
		var style2 = document.getElementById(whichLayer).style;
	}
	else if (document.all){
		// this is the way old msie versions work
		var style2 = document.all[whichLayer].style;
	}
	else if (document.layers){
		// this is the way nn4 works
		var style2 = document.layers[whichLayer].style;
	}

	if(mode=='close'){style2.display = "none";}
	else if(mode=='open'){style2.display = "block";}
	else{style2.display = style2.display=="block"?"none":"block";}

	var objects = document.getElementsByTagName("SELECT");

	for(var i=0;i<objects.length;i++)
	{
		 //to hide
		 if(mode=='open'){
			objects[i].style.visibility = "hidden";
		 }
		 
		 //to show
		 if(mode=='close'){
			objects[i].style.visibility = "visible";
		 }
	}
}


function bookmark(url,title){
  title_array = title.split(" - ")
  title = 'PBAInfo.org - ' + title_array[1];
  if ((navigator.appName == "Microsoft Internet Explorer") && (parseInt(navigator.appVersion) >= 4)) {
  window.external.AddFavorite(url,title);
  } else if (navigator.appName == "Netscape") {
    window.sidebar.addPanel(title,url,"");
  } else {
    alert("Press CTRL-D (Netscape) or CTRL-T (Opera) to bookmark");
  }
}

function checkAll(theForm, element, field) {
	//alert (theForm.checkall.checked);
    for (i = 0, n = theForm.elements.length; i < n; i++)
        if (theForm.elements[i].name.indexOf(field) != -1)
            //theForm.elements[i].checked = true;
			//eval("theForm.elements[" + i + "].checked = theForm.checkall.checked");
			eval("theForm.elements[" + i + "].checked = element.checked");
}

/*----------------Functions for Stylesheet Switcher--------------------*/
/*function setActiveStyleSheet(title, reset) {
  var i, a, main;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
      a.disabled = true;
      if(a.getAttribute("title") == title) a.disabled = false;
    }
  }
  if (reset == 1) {
	  createCookie("wstyle", title, 365);
  }
}

function setStyle() {
	var style = readCookie("wstyle");
	if (style != null) {
		setActiveStyleSheet(style, 0);
	}
}*/

/*----------------Functions for video popup--------------------*/

function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {
			oldonload();
			func();
		}
	}
}

//function to get elements by their class name
function getElementsByAttr (aName, aValue, tName){
  var i, elms, attr, rslt = [];
  if(document.all || document.getElementsByTagName){
    if(tName){
      elms = document.all ? document.all.tags(tName.toUpperCase()) : document.getElementsByTagName(tName);
    }else{
      elms = document.all ? document.all : document.getElementsByTagName("*");
    }
    for(i = 0; i < elms.length; i++){
      // Note: in IE5/Mac, element.getAttribute("class") returns null 
      // even when the class attribute contains a value. 
      // However, element.className will return the correct value.
      attr = aName == "class" ? elms[i].className : elms[i].getAttribute(aName);
      if(attr){
        if(aValue && attr != aValue){
          continue;
        }
        rslt[rslt.length] = elms[i];
      }
    }
  }
  return rslt;
}


//generic popup function
function popup(u, w, h, n, scroll, loc, resize, tool, menu){
	newwindow = window.open(u, n,'height='+h+',width='+w+',scrollbars='+scroll+',location='+loc+',resizable='+resize+',toolbar='+tool+',menubar='+menu+'');
	if (window.focus) {
		newwindow.focus()
	}
	return false;
}

//find <a>'s with class name info and make them pop up
function getVideoPopups(){
	var vids = getElementsByAttr('class', 'video_popup', 'a');
	for (i=0; i < vids.length; i++) {
		vids[i].onclick = function(){
			return popup(this.href, 320, 330, 'VideoPlayer', 'no', 'no', 'no', 'no', 'no');
		}
	}
}

addLoadEvent(getVideoPopups);
