//
// Scripts
//


function replaceAll( str, from, to ) {
	var idx = str.indexOf( from );
	while ( idx > -1 ) {
		str = str.replace( from, to );
		idx = str.indexOf( from );
	}
	return str;
}


function setHomepage(url){

	//alert('hi from '+ url);
	//this.setHomePage(url);

	this.style.behavior='url(#default#homepage)';
	this.setHomePage(url);
}


function addBookmark(url,title){

	if( window.sidebar && window.sidebar.addPanel ) {
	    //Gecko (Netscape 6 etc.) - add to Sidebar
	    window.sidebar.addPanel( title,url,'target="_content"' );
	} else if( window.external && ( navigator.platform == 'Win32' ||
	      ( window.ScriptEngine && ScriptEngine().indexOf('InScript') + 1 ) ) ) {
	    //IE Win32 or iCab - checking for AddFavorite produces errors in
	    //IE for no good reason, so I use a platform and browser detect.
	    //adds the current page as a favourite; if this is unwanted,
	    //simply write the desired page in here instead of 'location.href'
	    window.external.AddFavorite( url,title);
	} else if( window.opera && window.print ) {
	    //Opera 6+ - add as sidebar panel to Hotlist
	    //return true;
	} else if( document.layers ) {
	    //NS4 & Escape - tell them how to add a bookmark quickly (adds current page, not target page)
	    window.alert( 'Please click OK then press Ctrl+D to create a bookmark' );
	} else {
	    //other browsers - tell them to add a bookmark (adds current page, not target page)
	    window.alert( 'Please use your browser\'s bookmarking facility to create a bookmark' );
	}
	//return false;
}


var popUpWin=0;
function popUpWindow(URLStr, left, top, width, height) { 

	//alert('You dont exist, I will open you now');
	//popUpWin = open(URLStr, 'popUpWin','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbar=yes,resizable=no,copyhistory=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
	popUpWin = open(URLStr, 'popUpWin','toolbar=0,location=0,scrollbars=0,resizable=0,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
	popUpWin.moveTo(100,100);

}


// For rollover effects
function switchOn(imgName){
   if (document.images){
      imgOn=eval(imgName + "_on.src");
      document[imgName].src= imgOn;
    }
}

// For rollover effects
function switchOff(imgName){
   if (document.images){
      imgOff=eval(imgName + "_off.src");
      document[imgName].src= imgOff;
    }
}

  
// What's this? :-S
function jumpMenu(targ,selObj,restore){ //v3.0

  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

function updatePreview(){
	et = document.getElementById('eText');
	sn = document.getElementById('sName');
	rn = document.getElementById('rName');
	rm = document.getElementById('rMail');
	bt = document.getElementById('bText');
	rp = document.getElementById('recPreview');
	pl = document.getElementById('page');

	// Bother only if at least one field has something
	if ( (et.value.length > 0) || (sn.value.length > 0) || (rn.value.length > 0)  ) {
		tmp = bt.value.replace(/{RNAME}/,rn.value);
		tmp1 = tmp.replace(/{SNAME}/,sn.value);
		tmp1 = tmp1.replace(/{RMAIL}/,rm.value);		
		tmp1 = tmp1.replace(/{PROD}/,pl.value);	
		tmp1 = replaceAll(tmp1,'\n','<br>');
		tmp2 = replaceAll(et.value,'\n','<br>');
		rp.innerHTML = tmp1 + "<br><br>" + tmp2;
	}
}

function copyText(){
	bt = document.getElementById('bText');
	rp = document.getElementById('recPreview');
	bt.value = rp.innerHTML;

}

