//Manual Scroller- © Dynamic Drive 2001
//For full source code, visit http://www.dynamicdrive.com

//specify speed of scroll (greater=faster)
var speed=10

iens6=document.all||document.getElementById
ns4=document.layers


function movedown(id)
{
	if (iens6)
	{
		var crossobj=document.getElementById? document.getElementById("content"+id) : document.all["content"+id];

		var contentheight=crossobj.offsetHeight
	}
	else if (ns4)
	{
		var crossobj=document["nscontainer"+id].document["nscontent1"+id];
		var contentheight=crossobj.clip.height
	}
	
	if (window.moveupvar) clearTimeout(moveupvar)
	if (iens6&&parseInt(crossobj.style.top)>=(contentheight*(-1)+50))
	crossobj.style.top=parseInt(crossobj.style.top)-speed+"px"

	else if (ns4&&crossobj.top>=(contentheight*(-1)+50))
	crossobj.top-=speed
	//movedownvar=setTimeout("movedown()",20)
}

function moveup(id)
{
	if (iens6)
	{
		var crossobj=document.getElementById? document.getElementById("content"+id) : document.all["content"+id];

		var contentheight=crossobj.offsetHeight
	}
	else if (ns4)
	{
		var crossobj=document["nscontainer"+id].document["nscontent1"+id];
		var contentheight=crossobj.clip.height
	}
	
	if (window.movedownvar) clearTimeout(movedownvar)
	if (iens6&&parseInt(crossobj.style.top)<=0)
	crossobj.style.top=parseInt(crossobj.style.top)+speed+"px"
	else if (ns4&&crossobj.top<=0)
	crossobj.top+=speed
	
	//moveupvar=setTimeout("moveup()",20)
}

function stopscroll()
{
	if (window.moveupvar) clearTimeout(moveupvar)
	if (window.movedownvar) clearTimeout(movedownvar)
}

function getcontent_height(){

	var crossobj;
	if (iens6)
	{
		crossobj=document.getElementById? document.getElementById("content1") : document.all["content1"];
	
		var contentheight=crossobj.offsetHeight
	}
	else if (ns4)
	{
		crossobj=document["nscontainer1"].document["nscontent1"];
		var contentheight=crossobj.clip.height
		document.nscontainer1.document.nscontent1.visibility="show"
	}
}

// JavaScript Document
function confirmDelete(arg) 
{
	if(arg == undefined)
	{
		arg = "Are you sure you would like to delete?";
	}

	if(confirm(arg)) {
		return true;
	} else {
		return false;
	}
}
function confirmDereg()
{
	if(confirm("Are you sure you want to unregister from current show?")) {
		return true;
	} else {
		return false;
	}	
}

function confirmScramble(arg)
{
	if(confirm(arg)) {
		return true;
	} else {
		return false;
	}	
}
function confirmDescramble(arg)
{
	if(confirm(arg)) {
		return true;
	} else {
		return false;
	}	
}


function validate_form()
{
	var array_input=document.getElementsByTagName("INPUT");
	var array_select=document.getElementsByTagName("SELECT");
	var array_textarea=document.getElementsByTagName("TEXTAREA");
	var alert_obj;
	var current_tabindex=1000; // init
	var checkbox_flag=false; // validation failed on checkbox?
	var radio_flag=false;
	var radio_buffer=0;
	var radio_buffer_checked=false;
	var radio_allchecked=false;
	var radio_first_tab=null;
	
	for(i=0; i<array_textarea.length; i++) {		// textarea
		var buff=array_textarea[i].title;
		if(buff.substring(0,1)=='*' && array_textarea[i].disabled==false && array_textarea[i].value.length < 1) {
			if(array_textarea[i].tabIndex<current_tabindex) {
				alert_obj=array_textarea[i];
				current_tabindex=alert_obj.tabIndex;
			}
		}
	}
	for(i=0; i<array_select.length; i++) { // select
		var buff=array_select[i].title;
		if(buff.substring(0,1)=='*' && array_select[i].disabled==false && array_select[i].value.length < 1) {
			if(array_select[i].tabIndex<current_tabindex) {
				alert_obj=array_select[i];
				current_tabindex=alert_obj.tabIndex;
			}
		}
	}
	for(i=0; i<array_input.length; i++) { // input
		var buff=array_input[i].title;
		if(array_input[i].type =='text' || array_input[i].type =='password') {
			if(buff.substring(0,1)=='*' && array_input[i].disabled==false && array_input[i].value.length < 1) {
				if(array_input[i].tabIndex<current_tabindex) {
					alert_obj=array_input[i];
					current_tabindex=alert_obj.tabIndex;
				}
			}
		} else if(array_input[i].type == 'radio' && radio_flag==false) {	// radio input
			if(buff.substring(0,1)=='*') {
				var radio_group=document.getElementsByName(array_input[i].name);
				var btn = valButton(radio_group);
				if (btn == null) {
					radio_flag=true;
					alert_obj=array_input[i];
					current_tabindex=alert_obj.tabIndex;
				}
			}
		} else if(array_input[i].type == 'checkbox') {
			if(buff.substring(0,1)=='*' && array_input[i].disabled==false && array_input[i].checked==false) {
				if(array_input[i].tabIndex<current_tabindex) {
					checkbox_flag=true;
					alert_obj=array_input[i];
					current_tabindex=alert_obj.tabIndex;
				}
			}
		} 
	}
	
	if(current_tabindex!=1000) {
		if(checkbox_flag==true) {
			alert('Please make sure you check '+alert_obj.title.substring(2, alert_obj.title.length));
		} else if(radio_flag==true) {
			alert('Please make sure you select '+alert_obj.title.substring(2, alert_obj.title.length));
		} else {
			alert('Please make sure you enter '+alert_obj.title.substring(2, alert_obj.title.length));
		}
		alert_obj.focus();
		return false;
	} else {
		//alert('something up');
	}
	/*	
	var obj_email=document.getElementById('email');
	return echeck(obj_email.value);
	*/
	return true;
}

function hideSendtoPhoneCheckbox()
{
	var array_input=document.getElementsByTagName("INPUT");
	for(i=0; i<array_input.length; i++) 
	{ // input
		if(array_input[i].type == 'checkbox') 
		{
			array_input[i].style.display = "none";
			break;
		}
	} 
	
}

function echeck(str) {

	var at="@";
	var dot=".";
	var lat=str.indexOf(at);
	var lstr=str.length;
	var ldot=str.indexOf(dot);
	if (str.indexOf(at)==-1){
	   alert("Invalid E-mail Address");
	   return false;
	}

	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
	   alert("Invalid E-mail Address");
	   return false;
	}

	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
	    alert("Invalid E-mail Address");
	    return false;
	}

	 if (str.indexOf(at,(lat+1))!=-1){
	    alert("Invalid E-mail Address");
	    return false;
	 }

	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
	    alert("Invalid E-mail Address");
	    return false;
	 }

	 if (str.indexOf(dot,(lat+2))==-1){
	    alert("Invalid E-mail Address");
	    return false;
	 }
	
	 if (str.indexOf(" ")!=-1){
	    alert("Invalid E-mail Address");
	    return false;
	 }
 	 return true;				
}


function get_selected_value(combo_id)
{
	var	combo = document.getElementById(combo_id);
	var val= combo.options[combo.selectedIndex].value;
	return val;
}

function selectSponsors()
{
	
	var listbox = document.getElementById('sponsors_list');
	for(i=0; i<listbox.options.length; i++) 
	{
		listbox.options[i].selected=true;
	}
}

function selectFilesList()
{
	var listbox = document.getElementById('files_list');
	for(i=0; i<listbox.options.length; i++) 
	{
		listbox.options[i].selected=true;
	}
}

function populateSponsorsFields(arg,selectedIndex) 
{
	var EventSponsorID = document.getElementById('EventSponsorID');
	var SponsorName = document.getElementById('SponsorName');
	var SponsorLink = document.getElementById('SponsorLink');
	var edit_sponsor=document.getElementById('edit_sponsor');
	var cmd_add=document.getElementById('add_sponsor');
	
	edit_sponsor.value=selectedIndex;
	
	var arr = arg.split('|');
	EventSponsorID.value=arr[0];
	SponsorName.value=arr[2];
	SponsorLink.value=arr[3];
	cmd_add.value='Edit Sponsor';
}

function addSponsorItem()
{
	var listbox = document.getElementById('sponsors_list');
	var EventCalendarID = document.getElementById('EventCalendarID');
	var EventSponsorID = document.getElementById('EventSponsorID');
	var SponsorName = document.getElementById('SponsorName');
	var SponsorLink = document.getElementById('SponsorLink');

	var edit_sponsor=document.getElementById('edit_sponsor');
	var cmd_add=document.getElementById('add_sponsor');
	
	if(edit_sponsor.value.length < 1) {
		var the_option =  document.createElement("Option");
		if(SponsorName.value == "")
		{
			return false;	
		}
		the_option.text = 	SponsorName.value;
		the_option.value = 	EventSponsorID.value+'|'+
							EventCalendarID.value+'|'+
							SponsorName.value+'|'+
							SponsorLink.value;
		listbox.options.add(the_option);
		the_option.onclick=function() 
							{
								populateSponsorsFields(the_option.value, the_option.index)					
							}		
		edit_sponsor.value='';
		EventSponsorID.value=''; 
		SponsorName.value=''; 
		SponsorLink.value=''; 
		cmd_add.value='Add Sponsor';
	} else {
		listbox.options[edit_sponsor.value].value=EventSponsorID.value+'|'+
												EventCalendarID.value+'|'+
												SponsorName.value+'|'+
												SponsorLink.value;
		edit_sponsor.value='';
		EventSponsorID.value=''; 
		SponsorName.value=''; 
		SponsorLink.value=''; 
		cmd_add.value='Add Sponsor';
	}
}

function removeSponsorsItem()
{
	var listbox = document.getElementById('sponsors_list');
	listbox.remove(listbox.selectedIndex);
}

function clearListbox(listbox_id)
{
	var listbox = document.getElementById(listbox_id);
	for (var i=listbox.options.length-1; i>=0; i--)
	{
		listbox.options[i] = null;
	}
	listbox.selectedIndex = -1;
}

function numbersonly(myfield, e, dec)
{

	var key;
	var keychar;
	
	if (window.event)
	   key = window.event.keyCode;
	else if (e)
	   key = e.which;
	else
	   return true;
	keychar = String.fromCharCode(key);
	
	// control keys
	if ((key==null) || (key==0) || (key==8) || 
		(key==9) || (key==13) || (key==27) )
	   return true;
	
	// numbers
	else if ((("0123456789").indexOf(keychar) > -1))
	   return true;
	
	// decimal point jump
	else if (dec && (keychar == "."))
	{
	   myfield.form.elements[dec].focus();
	   return false;
	}
	else
	   return false;
}

function addComboItem(comboId, text, value)
{
	var combo = document.getElementById(comboId);
	var opt = document.createElement("option");
	opt.text = text;
	opt.value = value;
	combo.options.add(opt);
}


function selectAll(prefix, checked)
{	
	var array_input=document.getElementsByTagName("INPUT");
	for(i=0; i<array_input.length; i++) 
	{ 
		if(array_input[i].type == "checkbox")
		{
			
			var id=array_input[i].id;
			if(id.indexOf(prefix) > -1) 
			{
				array_input[i].checked  = checked;
			}
		}
	}
}

function findSelected()
{
	var arrStr="";
	var textField = document.getElementById('multi_container');
	var array_input=document.getElementsByTagName("INPUT");
	for(i=0; i<array_input.length; i++) 
	{ 
	    var id=array_input[i].id;
		if(array_input[i].type == "checkbox" && id.indexOf("sel_") > -1 && array_input[i].checked == true )
		{
			if(arrStr == "")
			{
				arrStr = id.substring(4, id.length);
			}
			else
			{
				arrStr += "," + id.substring(4, id.length);
			}
		}
	}
	textField.value = arrStr;
}

function unselectAll()
{
	var select_all = document.getElementById('select_all');
	select_all.checked  = '';
}

/*function populateFullEvent(id, topic, dateStart, locationTime, locationDetail, sponsors)
{
	document.getElementById('send_friend_link').href = "/sendtoafriend/?article_id="+id;
	document.getElementById('event-detail-title').innerHTML = topic;
	document.getElementById('event-detail-subtitle').innerHTML = locationTime;
	document.getElementById('event-detail-date-time').innerHTML = dateStart;
	document.getElementById('event-detail-desc').innerHTML = locationDetail;
	document.getElementById('featured-event').innerHTML = "Selected Event";
}
*/

function populateFullEvent(content, id)
{
	//alert(parent.document.('send_friend_link'));
		  //cal-hover-desc

	document.getElementById('send_friend_link').href = "/sendtoafriend/?article_id="+id;
	document.getElementById('event-detail-title').innerHTML = content.getElementById('cal-hover-title').innerHTML;
	document.getElementById('event-detail-subtitle').innerHTML = content.getElementById('cal-hover-subtitle').innerHTML;
	//document.getElementById('event-detail-date-time').innerHTML = content.getElementById('event-detail-date-time').innerHTML;
	document.getElementById('event-detail-desc').innerHTML = content.getElementById('cal-hover-desc').innerHTML;
	document.getElementById('event-detail-starttime').innerHTML = content.getElementById('cal-hover-date-time').innerHTML;
	document.getElementById('featured-event').innerHTML = "Selected Event";
	
}

function populatePartner(id)
{
	alert(id);
	document.getElementById('partner_id').value = id;
}


function moveItem(listboxId,bDir) 
{ 
  var el = document.getElementById(listboxId);
  var idx = el.selectedIndex
  if (idx==-1) 
    alert("You must first select the item to reorder.")
  else {
    var nxidx = idx+( bDir? -1 : 1)
    if (nxidx<0) nxidx=el.length-1
    if (nxidx>=el.length) nxidx=0
    var oldVal = el[idx].value
    var oldText = el[idx].text
    el[idx].value = el[nxidx].value
    el[idx].text = el[nxidx].text
    el[nxidx].value = oldVal
    el[nxidx].text = oldText
    el.selectedIndex = nxidx
  }
}

function deleteItem(listboxId) 
{ 
  var el = document.getElementById(listboxId);
  var idx = el.selectedIndex;
  el.remove(idx);
}

function selectMenu(menu, section)
{
	var menuItem = document.getElementById(section);
	if(menuItem == null || menuItem == "")
		return;
	if(menu == "main")
		document.getElementById(section).style.backgroundColor= "#8FB9E1";

	if(menu == "leftnav")
	{
		document.getElementById(section).style.backgroundColor= "#A8C9E9";
	}
}

function openImg()
{
  var el = document.getElementById('files_list');
  var path = "../flash/images/" + el.value;
  
  if(el.value != "")
	  window.open(path, "mywindow");
  else
  	alert("Please select one file to preview");
}