var newwin ='';

function setPointer(theRow,classn)
{
	if (typeof(theRow.style) == 'undefined') {
        return false;
    }

    /*
    if (typeof(theRow.style) == 'undefined' || typeof(theRow.cells) == 'undefined') {
        return false;
    }

    var row_cells_cnt           = theRow.cells.length;
    for (var c = 0; c < row_cells_cnt; c++) {
        	theRow.cells[c].bgColor = thePointerColor;
    }*/

    theRow.className = classn;
}

function sure()
{
	return confirm('Are you sure you would like to remove this?');
}

function newWd(mode,company) {
	var hide_search = 0;

	if (newWd.arguments.length == 3) {
		hide_search = newWd.arguments[2];
	}

    newwin = window.open('search.php?mode='+mode+'&search='+company+'&hide_search='+hide_search, 'Search', 'screenX=20,screenY=20,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=500,height=350');
	newwin.focus();
}

function checkAmount(frmFld)
{

	var places = 2;
	if(checkAmount.arguments.length > 1)
		places = checkAmount.arguments[1];
	if (!validateDollars(frmFld.value)) {
		frmFld.value = '0.00';
		alert("Invalid Amount");
		return false;
	}
	else {
		frmFld.value = dollars(frmFld.value,places);
		return true;
	}
}

// round to 2 decimal places
function dollars(x)
{
	var places = 2;
	var zeroes='';
	var amount;
	var roundto;
	if(dollars.arguments.length > 1)
		places = dollars.arguments[1];
	for(var i=0; i < places ;i++){
		zeroes +='0'
	}
	roundto = parseInt(1 + zeroes);
	// round number
	amount = Math.round(x*roundto)/roundto;
	// convert to string
	amount = amount.toString();
	// get position of decimal
	dPlace = amount.indexOf('.',0);


	if (dPlace == -1)  // no decimal found
		return amount + '.' + zeroes;
		//return amount + '.00';
	else {
		decimals = amount.substring(dPlace+1,amount.length);
		if (decimals.length == places)
			return amount;
		else
			return amount + '0';
	}
}

function validateDollars(string)
{
    if (!string) return false;
    var chars = "0123456789.";

    for (var i = 0; i < string.length; i++) {
       if (chars.indexOf(string.charAt(i)) == -1)
          return false;
    }
    return true;
}

function toggleGroup(theCheckBox, thePseudoGroup, startAt)
{

	if (!startAt)
	  startAt = 0;
	var i = startAt;
	//alert(thePseudoGroup + i);
  while (document.getElementById(thePseudoGroup + i) != null) {
  	//alert(thePseudoGroup + i);
  	//alert(!theCheckBox.checked);
  	//document.getElementById(thePseudoGroup + i).value = '';
    document.getElementById(thePseudoGroup + i).disabled = !theCheckBox.checked;
    i++;
  }
}

function showPhone(phone,phone2) {
	var putItThere = null;
	var chasm = screen.availWidth;
	var mount = screen.availHeight;
	var w = 0;
	var h = 0;

	newwin = window.open('', 'BigPic', 'screenX=20,screenY=20,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width=300,height=85,left=' + ((chasm - w - 10) * .5) + ',top=' + ((mount - h - 30) * .5));
	newwin.document.write('<center><span style="font-family:Verdana,Arial;font-size:32px;">'+phone+'</span><br><span style="font-family:Verdana,Arial;font-size:8px;"><a href="#" onClick="window.close();return false;">CLOSE WINDOW</a></span></center>');

	// check for flash 5

	if ( (navigator.appName == "Microsoft Internet Explorer" &&
              navigator.appVersion.indexOf("3.1") == -1) ||
     		 (navigator.mimeTypes && navigator.mimeTypes["application/x-shockwave-flash"]  &&
     		  navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin &&
     		  navigator.plugins && navigator.plugins["Shockwave Flash"]) )
    {
		newwin.document.write('<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/_flash/swflash.cab#version=5,0,0,0" WIDTH=5 HEIGHT=5 id="phone" ALIGN="">');
		newwin.document.write('<PARAM NAME=movie VALUE="phone.swf?phone=1'+phone2+'"><EMBED src="phone.swf?phone=1'+phone2+'" WIDTH=5 HEIGHT=5 NAME="phone" ALIGN="" TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer"></EMBED></OBJECT>');
	}

	newwin.focus();
}

function add2ActiveEdit(html)
{
	var sel = DHTMLSafe.DOM.selection.createRange();
	sel.pasteHTML(html);
	DHTMLSafe.DOM.focus();
}

function selectProduct(product_id)
{
	newwin = window.open('search.php?hide_menu=true&mode=products', 'Products', 'screenX=20,screenY=20,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=500,height=350');
	newwin.focus();
}


function inArray(needle, haystack)
{
	for (var i = 0; i < haystack.length; i++) {
		if (needle == haystack[i])
		  return true;
	}
	return false;
}

function arrayUnion(arrays)
{

  if (!arrays || arrays.length == 0)
    return new Array();

	var new_array = new Array();

	for (var i = 0; i < arrays.length; i++) {

		for (var j = 0; j < arrays[i].length; j++) {

			if (!inArray(arrays[i][j], new_array)) {
				new_array.push(arrays[i][j]);
			}

		}

	}

	return new_array;

}

function arrayIntersect(arrays)
{

  if (!arrays || arrays.length == 0)
    return new Array();

	var controlArray = arrays[0];

	var new_array = new Array();

	for (var i = 0; i < controlArray.length; i++) {

  	include = true;

		for (var j = 0; j < arrays.length; j++) {

			if (!inArray(controlArray[i], arrays[j])) {
				include = false;
			}

		}

		if (include) new_array.push(controlArray[i]);

	}

	//alert(new_array);

	return new_array;

}

function getCheckedRadioChoice(radio_array)
{
  for (var i = 0; i < radio_array.length; i++) {
  	if (radio_array[i].checked)
  		return radio_array[i];
  }
  return false;
}

function checkrow (row, val, fieldName) {
	field = document.forms.seatForm[fieldName];
	for (i=0;i<field.length;i++) {
		if (field[i].id.indexOf(row) != -1) {
			field[i].checked = val;
		}
	}
}

function checkall (val, fieldName) {
	field = document.forms.seatForm[fieldName];
	for (i=0;i<field.length;i++) {
		field[i].checked = val;
	}
	field = document.forms.seatForm['r[]'];
	for (i=0;i<field.length;i++) {
		field[i].checked = val;
	}
	field = document.forms.seatForm['c[]'];
	for (i=0;i<field.length;i++) {
		field[i].checked = val;
	}
}

function checkdistrict (row, val, fieldName) {
	field = document.forms.seatForm[fieldName];
	for (i=0;i<field.length;i++) {
		if (field[i].id.indexOf(row) != -1) {
			field[i].checked = val;
		}
	}
	field = document.forms.seatForm['r[]'];
	for (i=0;i<field.length;i++) {
		if (field[i].id.indexOf(row) != -1) {
			field[i].checked = val;
		}
	}
	field = document.forms.seatForm['c[]'];
	for (i=0;i<field.length;i++) {
		if (field[i].id.indexOf(row) != -1) {
			field[i].checked = val;
		}
	}
}

function closePlayer() {
  document.getElementById('floaterplayer').style.display = 'none';
  document.getElementById('floaterplayerbox').style.visibility = 'hidden';
}

function wopen(url, name, w, h) {
  wleft = (screen.width - w) / 2;
  wtop = (screen.height - h) / 2;
  var win = window.open(url, name, 'width=' + w + ', height=' + h + ', ' + 'left=' + wleft + ', top=' + wtop + ', ' + 'location=no,menubar=no,' + 'status=no,toolbar=no,scrollbars=no,resizable =no');
  win.resizeTo(w, h);
  win.moveTo(wleft, wtop);
  win.focus();
  return win;
}

function setFlashPlayer(vid){
  if (!vid) {
    return;
  }
  /*
  document.getElementById('floaterplayerbox').style.zIndex = 100;
  document.getElementById('floaterplayerbox').style.visibility = 'visible';
  document.getElementById('floaterplayerbox').style.display = 'block';
  document.getElementById('floaterplayer').style.display = 'block';
  document.getElementById('floaterplayerbox').show = 'true';
  document.getElementById('floaterplayer').show = 'true';
  */

  playFlash(vid);
}

function stopFlash(playerdivID) {
  document.getElementById(playerdivID).innerHTML = '';
}

function playFlash(vid, playerdivID, width, height, autoStart){
  if (autoStart == null) {
  	autoStart = false;
  }
  var url = vid;

  if (!vid) {
    return;
  }

  if (! width || ! height) {
    width = 320;
    height = 240;
  }

  var str = '<object id="objMovie0" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" height="' + height + '" width="' + width + '">';
  str += '<param name="movie" value="/_flash/FLVPlayer_Progressive.swf" />';
  str += '<param name="salign" value="lt" />';
  str += '<param name="quality" value="high" />';
  str += '<param name="scale" value="noscale" />';
  str += '<param name="FlashVars" value="&MM_ComponentVersion=1&skinName=/_flash/Clear_Skin_1&streamName=' + url + '&autoPlay=' + autoStart + '&autoRewind=false" />';
  str += '<embed src="/_flash/FLVPlayer_Progressive.swf" flashvars="&MM_ComponentVersion=1&skinName=/_flash/Clear_Skin_1&streamName=' + url + '&autoPlay=' + autoStart + '&autoRewind=false" quality="high" scale="noscale" height="' + height + '" width="' + width + '" name="FLVPlayer" salign="LT" type="application/x-shockwave-flash" />';
  str += '</object>';

  if (playerdivID) {
    //divID = 'playerdiv';
    //divID = 'floaterplayer';
    divID = playerdivID;
    document.getElementById(divID).innerHTML = str;

    var divHeight = height + 'px';
    document.getElementById(divID).style.height = divHeight;
  }
  else {
    win_width = width + 30;
    win_height = height + 40;

    win = wopen('', '_video', win_width, win_height);
    win.document.open();
    win.document.write(str);
    win.document.close();
  }
}
