

function modalWin(url, width, height, argWindowName) {
	var nameW;
		if (argWindowName==null)
			nameW='_dialog';
		else
			nameW = argWindowName;

 if (navigator.appVersion.indexOf('4') != -1) {
 // Vars for centering the new window on Version 4 Browsers
 xTop = screen.width/2 - (width/2);
 yTop = screen.height/2 - (height/2);
 }

if (window.showModalDialog) {
		window.showModalDialog(url,nameW,
		"dialogWidth:"+width+"px;dialogHeight:"+height+"px");
	} else {
		window.open(url,nameW,
		'height='+height+',width='+width+',toolbar=no,directories=no,status=no,continued from previous linemenubar=no,scrollbars=no,resizable=no,modal=yes');
	}
}



function newWindow(url, width, height, argWindowName) {
    if (argWindowName==null)
			nameW='_dialog';
		else
			nameW = argWindowName;
 if (navigator.appVersion.indexOf('4') != -1) 
 {
	 // Vars for centering the new window on Version 4 Browsers
	 xTop = screen.width/2 - (width/2);
	 yTop = screen.height/2 - (height/2);
//	 window.open(url,nameW,'dependent,height=' + height + ',width=' + width +',scrollbars=yes,resizable=yes,menubar=no,toolbar=no,status=no,location=no,directories=no,left=' + xTop + ',top=' + yTop + '');
 	// below works, the commented out does not work - why?
 	window.open(url,nameW,
		'height='+height+',width='+width+',scrollbars=yes,resizable=yes,modal=yes,toolbar=no,directories=no,status=no,continued from previous linemenubar=no');
 
 } 
	 else 
	 {
	 	window.open(url,nameW,'dependent,height='+height+',width='+width+',scrollbars=yes,resizable=yes,menubar=no,toolbar=no,status=no,location=no,directories=no,left=150,top=200');
	 }
}


// -->

/*
window.open(url, nameW, 'dependent, height=' + height + ',width=' + width +', scrollbars=yes, resizable=yes,menubar=no,toolbar=no,status=no,location=no,directories=no,left=' + xTop + ',top=' + yTop + '');
 } else {
 window.open(url, nameW, 'dependent, height='+height+',width='+width+', scrollbars=yes, resizable=yes,menubar=no,toolbar=no,status=no,location=no,directories=no,left=150,top=200');
*/

function addScrollyToUrl(urlstr, scrolly)
{
		var b = urlstr;
		var temp = new Array();
		var straction="";
		temp = b.split('?');
		
		if (temp[1]!=null)
		{
			args = temp[1].split('&');
			for (var i in args)
			{
				a = args[i].split('=');
				if (a[0]!="scrolly")
				{
					straction=straction +  args[i] + '&';
				}
			}
		}
		straction = temp[0] + '?' + straction; 
		urlstr = straction + 'scrolly='+scrolly;
		return urlstr;
}

function getScrollXY() {
  var scrOfX = 0, scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
  }
  return [ scrOfX, scrOfY ];
}

function saveScrollCoordinates(obj) {
	sxy = getScrollXY();
	
  //sx = (document.all)?document.documentElement.scrollLeft:window.pageXOffset;
  //sy = (document.documentElement)?document.documentElement.scrollTop:window.pageYOffset;
//  sx = (document.all)?document.body.scrollLeft:window.pageXOffset;
//  sy = (document.all)?document.body.scrollTop:window.pageYOffset;
	obj.href=addScrollyToUrl(obj.href,sxy[1]);
} 

function confirmbox(obj,text) {
	saveScrollCoordinates(obj);
	return confirm(text);
} 

function refreshParent(scrolly) {
	
	if (scrolly!=null)
	{
		var b = window.opener.location.href;
		var temp = new Array();
		temp = b.split('?');
		newurl = addScrollyToUrl(window.opener.location.href, scrolly);
		//window.opener.location.href = temp[0] + '?scrolly='+scrolly;
		window.opener.location.href =newurl;
	}
	else
		window.opener.location.href = window.opener.location.href;

  if (window.opener.progressWindow)
		
 {
    window.opener.progressWindow.close()
  }
  window.close();
}



function addScrollyToFormAction(formid, scrolly)
{
		var newurl;
		var straction;
		form = document.getElementById(formid);
		straction = form.action;
		newurl = addScrollyToUrl(straction, scrolly);
		//newurl = addScrollyToUrl('http://tangofestivals.localhost/sections/festivals/calendar_myevents.php?_qf_EventsForm_display=true&scrolly=0', scrolly);
		form.action = newurl;
}

function old_addScrollyToFormAction(formid, scrolly)
{
		form = document.getElementById(formid);
		var b = form.action;
		var temp = new Array();
		temp = b.split('?');
		var straction = temp[0]; 
		args = temp[1].split('&');
		for (var i in args)
		{
			a = args[i].split('=');
			if (a[0]!="scrolly")
			{
				straction=straction + '&' + args[i];
			}
		}
		form.action = straction + '?scrolly='+scrolly;
}

/*only works in IE...*/
function openChild(url, width, height) 
{
    var MyArgs;
    var WinSettings = "center:yes;resizable:no;dialogHeight:300px";
    //ALTER BELOW LINE - supply correct URL for Child Form
    var MyArgs = window.showModalDialog(url);
}

function OriginalOpenChild(url, width, height) 
{
    var ParmA = retvalA.value;
    var ParmB = retvalB.value;
    var ParmC = retvalC.value;
    var MyArgs = new Array(ParmA, ParmB, ParmC);
    var WinSettings = "center:yes;resizable:no;dialogHeight:300px"
    //ALTER BELOW LINE - supply correct URL for Child Form
    var MyArgs = window.showModalDialog(
   url, MyArgs, WinSettings);
    if (MyArgs == null)
    {
        window.alert(
          "Nothing returned from child. No changes made to input boxes")
    }
    else
    {
        retvalA.value=MyArgs[0].toString();
        retvalB.value=MyArgs[1].toString();
        retvalC.value=MyArgs[2].toString();
    }
}

function findselected(optionlist_id) 
{
  var optionsitem = document.getElementById(optionlist_id);
	if (optionsitem.options[optionsitem.selectedIndex]) {
    return optionsitem.options[optionsitem.selectedIndex].value;
		//window.alert('You selected item ' +
    //  (optionsitem.options[optionsitem.selectedIndex].value));
     // (optionsitem.selectedIndex + 1));
    }
	else {
    //window.alert('You did not select and item');
    return null;
		}
 }

function findthemany( ) {
  var outvar = '';
  var whichitem = 0;
  while (whichitem < document.form04.field02.length) {
    if (document.form04.field02.options[whichitem].selected) {
      outvar = outvar + ('You selected item ' + (whichitem + 1) + ': ' +
        document.form04.field02.options[whichitem].text) + '\n';
      }
      whichitem++;
    }
  if (outvar == '') { outvar = 'You did not select an item.'; }
  window.alert(outvar);
  }

function getyscroll() {
	sxy = getScrollXY();

//  sy = (document.all)?document.body.scrollTop:window.pageYOffset;
	return sxy[1];
} 


/***********************************************
* Disable "Enter" key in Form script- By Nurul Fadilah(nurul@REMOVETHISvolmedia.com)
* This notice must stay intact for use
* Visit http://www.dynamicdrive.com/ for full source code
***********************************************/
                
function handleEnter (field, event) {
		var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
		if (keyCode == 13) {
			var i;
			for (i = 0; i < field.form.elements.length; i++)
				if (field == field.form.elements[i])
					break;
			i = (i + 1) % field.form.elements.length;
			field.form.elements[i].focus();
			return false;
		} 
		else
		return true;
	}      

function rightTrim(sString)
{
	while (sString.substring(sString.length-1, sString.length) == ' ')
	{
	sString = sString.substring(0,sString.length-1);
	}
	return sString;
}
