
(function BreakInOrOut()
{
 try{if(top.document.domain!=document.domain){}}catch(e){top.location.href=location.href;}
  
 var qs = (qs=location.href.match(/\/(\w+)\.\w+(\?|$)/)) ? qs[1] : '';
 var inFrame = top != self;
 var appName=!inFrame?qs:'' ;
 var targetUrl=inFrame ? (self.location.href+'?stayout') : '../index.php?'+appName;

 if(inFrame && location.search.match('stayout'))
  top.location.href = self.location.href.split('?')[0];
 
 if( location.href.indexOf('/files/') != - 1 ) 
  document.write('<a style="z-index:10;position:fixed;top:10px;right:10px;color:#000;background-color:#eee;border:2px outset #000;padding:0.2em;text-decoration:none;margin-top:8px" title="'+ (inFrame?'Break out of frame':'Return to Script Menu') +'" href="#" onclick="top.location.href=\''+targetUrl+'\';return false;">'+(inFrame?'Full Screen':'Restore List')+'<\/a><br \/>');

 try
 {
  if(top.location==self.location && self.location.href.match(/^http/i) && !location.href.search(/\bstayout\b/i))
   top.location.href='http://scripterlative.com?'+appName;
 }
 catch(e){ top.location.href='http://scripterlative.com?'+appName }
 
 try{ if(opener && opener != self){ opener.location.href = self.location.href; } }catch( e ){} 
 
})();

var Survey=
{
 sent:false,
 
 getPageXY:function()
 {
  var xy = {}, dde = document.documentElement;
  
  xy.y = document.body.scrollTop + (dde ? dde.scrollTop : 0);
  xy.x = document.body.scrollLeft + (dde ? dde.scrollLeft : 0);
   
  return xy;
 },
 
 change:function()
 {
  if(this.readyState==4 && this.status==200)
  {
   window.status = 'Returned: ' + this.responseText;
   ///////////window.location.href = Survey.dlURL;
  }
 },
 
 makePOSTRequest:function( url, parameters ) 
 {
  if(window.XMLHttpRequest) 
  { 
   this.rq = new XMLHttpRequest();

   if(this.rq.overrideMimeType) 
    this.rq.overrideMimeType('text/html');

   this.rq.onreadystatechange=this.change;
     
   this.rq.open('POST', url, true);

   this.rq.setRequestHeader("Content-type", "application/x-www-form-urlencoded; charset=UTF-8");

   this.rq.setRequestHeader("Content-length", parameters.length); 

   this.rq.setRequestHeader("Connection", "close");

   this.rq.send(parameters);
  } 
 },

 send:function( obj, url ) 
 {
  var postStr = "", set = obj.reason;
/*********
  for(var i=0, len = set.length; i < len; i++)
   if( set[i].checked )
    postStr += encodeURI("reason=" + i);
   
  if( set[len-1].checked )
   postStr+="&explain=" + encodeURI( obj.explain.value );
***********/  
  this.dlURL = url; 
  
  setTimeout( (function(obj, data){return function(){obj.makePOSTRequest('dlreasons.php', data);}})(this, postStr), 1000);  
  
 },

 formOK:function( formRef )
 {
  var ok = false;
  
  for(var i=0, len=formRef.reason.length; i<len && !formRef.reason[i].checked; i++)
  ;
  
  if(i==len)
   alert('Please select a reason');
  else
   if( i==len-1 && ( !/\S/.test( formRef.explain.value ) || this.defaultOther.indexOf(formRef.explain.value) > -1 ) ) 
    alert('Please type your other reason in the text field');
   else
    ok = true;
    
  return ok;
 },
 
 ask:function( app )
 {    
  var box = document.createElement('div'), 
      form,
      elemText = [ 'It appears to suit my needs exactly', 'I want to test its suitability further', 'I\'m curious about  how this is done','I want to compare it to my own code', 'Another Reason'],
      btn, tempE, tempL,
      theBody = document.getElementsByTagName('body')[0],
      parag;
      
  try{ form = document.createElement('<form>'); }catch(e){ form = document.createElement('form'); };    
   
  with(box.style)
  {
   backgroundColor='#eee';
   color='#000';
   padding='10px';
   zIndex='100';
   position='absolute';
   border='solid 2px #f00';
  }

  box.appendChild( document.createElement('p') ).appendChild(document.createElement('b')).appendChild( document.createTextNode('If prompted for an action, select "Save".') );
    
  box.appendChild( document.createElement('p') ).appendChild(document.createElement('b')).appendChild( document.createTextNode('The script file is supplied with a .j_s extension and may not open when clicked.') );
  
  box.appendChild( document.createElement('p') ).appendChild(document.createElement('b')).appendChild( document.createTextNode('Just open the file with your usual text editor, then save it with a .js extension.') );
    
 /********************   
  box.appendChild( document.createElement('p') ).appendChild(document.createElement('b')).appendChild( document.createTextNode('Please take a moment to answer just 1 question.') );
  
  box.appendChild( document.createElement('p')).appendChild( document.createTextNode('I am downloading this script because:') );
  
  box.appendChild( document.createElement('p'));  
   
  for( var i=0; i < elemText.length; i++ )
  {      
   tempL = document.createElement('label');
   tempL['for'] = 'option' + i;
   
   try{tempE = document.createElement('<input type="radio" name="reason">');}catch(e){tempE = document.createElement('input');};
   
   tempE.xText = elemText[i];
   
   with( tempE )
   {
    type = 'radio';
    value = 'option' + i;    
    name = 'reason';
    style.border='none';
    onclick=function(){this.form.explain.style.display=(/^another/i.test(this.xText)?'block':'none') ;}
   }     
   
   tempL.appendChild( tempE );   
   
   tempL.appendChild( document.createTextNode( elemText[ i ] ) );
   
   form.appendChild(tempL);
   
   form.appendChild( document.createElement('p') );
  } 
  
  try{tempE = document.createElement('<textarea name="explain">'); }catch(e){ tempE = document.createElement('textarea'); };
  
  with( tempE )
  {
   name='explain';
   cols="40";
   rows="3";
   style.display='none';
   value = "I am downloading " +app.toUpperCase()+ " because";
  }
  
  this.defaultOther = tempE.value;
  
  form.appendChild(tempE);
  *****************************/
  
  form.appendChild( document.createElement('p') );
  
    
  btn = document.createElement('a');
  btn.style.border = "outset 2px #444";
  btn.style.padding= "4px";
  btn.style.color='#000';  
  btn.style.backgroundColor='#fff';  
  btn.href = 'dlog.php?src='+app;
  btn.onclick = function(){ /*if( Survey.formOK(form) )*/{ Survey.send( form, 'dlog.php?src='+app ); box.style.display='none'; Survey.sent = true;}/*else return false;*/ }     
  
  btn.appendChild( document.createTextNode('PROCEED WITH DOWNLOAD') );
    
  form.appendChild( btn ); 
 
  box.appendChild( form );
 
  if( !this.sent )
  {
   theBody.insertBefore(box, theBody.firstChild);
   box.style.left = this.getPageXY().x + screen.width/2 - box.offsetWidth/2 + 'px';
   box.style.top = 150 + this.getPageXY().y + 'px';   
  }
  else
   location.href = 'dlog.php?src='+app;
    
  return false;
 }
} 