function launchwin(url, name, width, height)
{
  var str = "height=" + height + ",innerHeight=" + height;
  str += ",width=" + width + ",innerWidth=" + width;
  if (window.screen) {
    var ah = screen.availHeight - 30;
    var aw = screen.availWidth - 10;

    var xc = (aw - width) / 2;
    var yc = (ah - height) / 2;

    str += ",left=" + xc + ",screenX=" + xc;
    str += ",top=" + yc + ",screenY=" + yc;
  }
	win = window.open(url,name,str);
}
function launchwin2(url, name, width, height, parameters)
{
  var str = "height=" + height + ",innerHeight=" + height;
  str += ",width=" + width + ",innerWidth=" + width;
  if (window.screen) {
    var ah = screen.availHeight - 30;
    var aw = screen.availWidth - 10;

    var xc = (aw - width) / 2;
    var yc = (ah - height) / 2;

    str += ",left=" + xc + ",screenX=" + xc;
    str += ",top=" + yc + ",screenY=" + yc;
  }
  str += "," + parameters
	win = window.open(url,name,str);
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


function addRowToTable(tableId, fieldName, title){
    	var tbl = document.getElementById(tableId);
    	var lastRow = tbl.rows.length;
    	// if there's no header row in the table, then iteration = lastRow + 1
    	var iteration = lastRow+1;	
    	var row = tbl.insertRow(lastRow);
    	
    	// sceneName Label
    	var cell0 = document.createElement('td');
		cell0.setAttribute('class', 'tdLabel');
    	var textNode = document.createTextNode(title + ":");
    	cell0.appendChild(textNode);
    	row.appendChild(cell0);
    	
    	// sceneName Text Field
    	var cell1 = document.createElement('td');
		cell1.setAttribute('class', 'tdEntry');
    	var el = document.createElement('input');
    	el.setAttribute('type', 'text');
    	el.setAttribute('name', fieldName + iteration);
    	el.setAttribute('id', fieldName + iteration);
		var but = document.createElement('button');
		but.setAttribute('type', 'button');
		but.setAttribute('value', 'Remove Feature');
    	cell1.appendChild(el);
    	
    	row.appendChild(cell1);
    }
    
    function removeRowFromTable(tableId){
    	var tbl = document.getElementById(tableId);
    	       	
    	var lastRow = tbl.rows.length;
    	if (lastRow > 2) tbl.deleteRow(lastRow - 1);
    }
function showDiv(divid){
   if (document.layers) document.layers[divid].display="block";
   else document.getElementById(divid).style.display="block";
}
function hideDiv(divid){
   if (document.layers) document.layers[divid].display="none";
   else document.getElementById(divid).style.display="none";
}

function changeClass(Elem, myClass) {
	var elem;
	if(document.getElementById) {
		var elem = document.getElementById(Elem);
	} else if (document.all){
		var elem = document.all[Elem];
	}
	elem.className = myClass;
}


function HighlightAll(theField) {
	var tempval=eval("document."+theField)
	tempval.focus()	
	tempval.select()	
	if (document.all){	
		therange=tempval.createTextRange()		
		therange.execCommand("Copy")		
		window.status="Contents highlighted and copied to clipboard!"		
		setTimeout("window.status=''",1800)	
	}
}
function confirmSubmit(whichAction){
	if(whichAction == 'unbrandedTour'){
		var agree=confirm('Are you sure you want to upgrade to an unbranded tour?');
		if (agree){
			document.upgradeTour.purchaseType.value  = 'unbrandedTour';
			document.upgradeTour.submit();
			// window.location=URL;
		}else{
			return false ;
		}
	}else if(whichAction == 'premiumTour'){
		var agree=confirm('Are you sure you want to upgrade to a premium tour?');
		if (agree){
			document.upgradeTour.purchaseType.value  = 'premiumTour';
			document.upgradeTour.submit();
			// window.location=URL;
		}else{
			return false ;
		}
	}
	else if(whichAction == 'realtorDotCom'){
		var agree=confirm('Are you sure you want to submit this tour to realtor.com Standard?');
		if (agree){
			document.upgradeTour.purchaseType.value  = 'realtorDotCom';
			document.upgradeTour.submit();
			// window.location=URL;
		}else{
			return false ;
		}
	}
	else if(whichAction == 'realtorDotComSC'){
		var agree=confirm('Are you sure you want to submit this tour to realtor.com ShowCase?');
		if (agree){
			document.upgradeTour.purchaseType.value  = 'realtorDotComSC';
			document.upgradeTour.submit();
			// window.location=URL;
		}else{
			return false ;
		}
	}
	else if(whichAction == 'TourNarration'){
			var agree=confirm('Are you sure you want to upgrade tour to have Tour voice narration?');
			if (agree){
				document.upgradeTour.purchaseType.value  = 'TourNarration';
				document.upgradeTour.submit();
				// window.location=URL;
	        }
	  else{
		return false ;
	}		
	}else if(whichAction == 'CategoryNarration'){
		var agree=confirm('Are you sure you want to upgrade tour to have category voice narration?');
		if (agree){
			document.upgradeTour.purchaseType.value  = 'CategoryNarration';
			document.upgradeTour.submit();
			// window.location=URL;
        }
		else{
			return false ;
		}		
	}
	else if(whichAction == 'VideoTour'){
		var agree=confirm('Are you sure you want to upgrade tour to have Video Tour ?');
		if (agree){
			document.upgradeTour.purchaseType.value  = 'VideoTour';
			document.upgradeTour.submit();
			// window.location=URL;
		}
		else{
			return false ;
		}		
	}
	else if(whichAction == 'DomainListing'){
			var agree=confirm('Are you sure you want to upgrade tour to have domain Listing ?');
			if (agree){
				document.upgradeTour.purchaseType.value  = 'DomainListing';
				document.upgradeTour.submit();
				// window.location=URL;
	        }
			else{
				return false ;
			}		
	}
	 else{
		return false ;
	}
}

//Text Counter
function textCounter(field, countfield, maxlimit) {
if (field.value.length > maxlimit) // if too long...trim it!
field.value = field.value.substring(0, maxlimit);
// otherwise, update 'characters left' counter
else 
countfield.value = maxlimit - field.value.length + " Characters Left";
}

// Confirm Delete
function confirmDelete(message)
{
var agree=confirm(message);
if (agree)
	return true ;
else
	return false ;
}