

var hexcase=0;var b64pad="";function hex_sha1(a){return rstr2hex(rstr_sha1(str2rstr_utf8(a)))}function hex_hmac_sha1(a,b){return rstr2hex(rstr_hmac_sha1(str2rstr_utf8(a),str2rstr_utf8(b)))}function sha1_vm_test(){return hex_sha1("abc").toLowerCase()=="a9993e364706816aba3e25717850c26c9cd0d89d"}function rstr_sha1(a){return binb2rstr(binb_sha1(rstr2binb(a),a.length*8))}function rstr_hmac_sha1(c,f){var e=rstr2binb(c);if(e.length>16){e=binb_sha1(e,c.length*8)}var a=Array(16),d=Array(16);for(var b=0;b<16;b++){a[b]=e[b]^909522486;d[b]=e[b]^1549556828}var g=binb_sha1(a.concat(rstr2binb(f)),512+f.length*8);return binb2rstr(binb_sha1(d.concat(g),512+160))}function rstr2hex(c){try{hexcase}catch(g){hexcase=0}var f=hexcase?"0123456789ABCDEF":"0123456789abcdef";var b="";var a;for(var d=0;d<c.length;d++){a=c.charCodeAt(d);b+=f.charAt((a>>>4)&15)+f.charAt(a&15)}return b}function str2rstr_utf8(c){var b="";var d=-1;var a,e;while(++d<c.length){a=c.charCodeAt(d);e=d+1<c.length?c.charCodeAt(d+1):0;if(55296<=a&&a<=56319&&56320<=e&&e<=57343){a=65536+((a&1023)<<10)+(e&1023);d++}if(a<=127){b+=String.fromCharCode(a)}else{if(a<=2047){b+=String.fromCharCode(192|((a>>>6)&31),128|(a&63))}else{if(a<=65535){b+=String.fromCharCode(224|((a>>>12)&15),128|((a>>>6)&63),128|(a&63))}else{if(a<=2097151){b+=String.fromCharCode(240|((a>>>18)&7),128|((a>>>12)&63),128|((a>>>6)&63),128|(a&63))}}}}}return b}function rstr2binb(b){var a=Array(b.length>>2);for(var c=0;c<a.length;c++){a[c]=0}for(var c=0;c<b.length*8;c+=8){a[c>>5]|=(b.charCodeAt(c/8)&255)<<(24-c%32)}return a}function binb2rstr(b){var a="";for(var c=0;c<b.length*32;c+=8){a+=String.fromCharCode((b[c>>5]>>>(24-c%32))&255)}return a}function binb_sha1(v,o){v[o>>5]|=128<<(24-o%32);v[((o+64>>9)<<4)+15]=o;var y=Array(80);var u=1732584193;var s=-271733879;var r=-1732584194;var q=271733878;var p=-1009589776;for(var l=0;l<v.length;l+=16){var n=u;var m=s;var k=r;var h=q;var f=p;for(var g=0;g<80;g++){if(g<16){y[g]=v[l+g]}else{y[g]=bit_rol(y[g-3]^y[g-8]^y[g-14]^y[g-16],1)}var z=safe_add(safe_add(bit_rol(u,5),sha1_ft(g,s,r,q)),safe_add(safe_add(p,y[g]),sha1_kt(g)));p=q;q=r;r=bit_rol(s,30);s=u;u=z}u=safe_add(u,n);s=safe_add(s,m);r=safe_add(r,k);q=safe_add(q,h);p=safe_add(p,f)}return Array(u,s,r,q,p)}function sha1_ft(e,a,g,f){if(e<20){return(a&g)|((~a)&f)}if(e<40){return a^g^f}if(e<60){return(a&g)|(a&f)|(g&f)}return a^g^f}function sha1_kt(a){return(a<20)?1518500249:(a<40)?1859775393:(a<60)?-1894007588:-899497514}function safe_add(a,d){var c=(a&65535)+(d&65535);var b=(a>>16)+(d>>16)+(c>>16);return(b<<16)|(c&65535)}function bit_rol(a,b){return(a<<b)|(a>>>(32-b))};


//document.domain='ispaces.com';

var menus={};

var REGEX_EMAIL=/^[\w\-\.]+\@[a-zA-Z0-9\.\-]+\.[a-zA-Z]{2,}$/;
var REGEX_ALPHA=/^[a-z]+$/i;                 // alpha
var REGEX_ALPHA_S=/^[a-z\s]+$/i;             // alpha, spaces, case insensitive
var REGEX_ALPHA_SA=/^[a-z\s']+$/i;           // alpha, spaces, apostrophe, case insensitive
var REGEX_ALPHANUMERIC=/^[a-z0-9]+$/i;       // alphanumerica, case insensitive
var REGEX_ALPHANUMERIC_UH=/^[a-z0-9_-]+$/i;  // alphanumerica, underscores, hyphens, case insensitive
var REGEX_ALPHANUMERIC_S=/^[a-z0-9\s]+$/i;   // alphanumerica, spaces, case insensitive

var Validator=function(){};
Validator.email=function(x){return x.match(REGEX_EMAIL)};
Validator.notemail=function(x){return !x.match(REGEX_EMAIL)};
Validator.minlen=function(x,len){if(x.length<len)return false;return true;};
Validator.maxlen=function(x,len){if(x.length>len)return false;return true;};
Validator.alpha_s=function(x){return x.match(REGEX_ALPHA_S)};
Validator.alpha_sa=function(x){return x.match(REGEX_ALPHA_SA)};
Validator.alnum=function(x){return x.match(REGEX_ALPHANUMERIC)};
Validator.alnum_s=function(x){return x.match(REGEX_ALPHANUMERIC_S)};
Validator.alnum_uh=function(x){return x.match(REGEX_ALPHANUMERIC_UH)};

function isArray(o){return o instanceof Array}

var contextUrl='http://www.ispaces.com';
var cloudUrl='https://cloud.ispaces.com';
var millis=function(){return new Date().getTime()};
function $(i){return document.getElementById(i)};
var txt=function(t){return document.createTextNode(t)};
//var update=function(id,r){$(id).innerHTML=r};
var update=function(id,r){
  $(id).innerHTML=r;
  document.body.scrollTop=0;
};
var go=function(url,id){new Ajax(url,[update,id]).doGet()};
var goSync=function(url,id){new Ajax(url,[update,id]).doGetSync()};
var go2=function(url,id,menuItemId){
  //alert('go2('+url+', '+id+', '+menuItemId+')');
  var update2=function(r){
    //alert('update2(r)');
    $(id).innerHTML=r;
    active($(menuItemId));
    document.body.scrollTop=0;
  };
  //new Ajax(url,[update,id]).doGet();
  new Ajax(url,update2).doGet();
};
var goHome=function(url,id){
  clearTimeout(quoteInterval);
  var callback=function(r){
    $(id).innerHTML=r;
    startQuotes();
  };
  new Ajax(url,callback).doGet()
};
var active2=function(x){

  var menu=menus[x.getAttribute('menuName')];
  if(menu){
    activeItem=menu.activeItem;
    //alert('activeItem = '+activeItem);
    if(activeItem){
      activeItem.className='';
    }
  }
};
var activeId=function(x){active($(x))};
var active=function(x){
  //alert('active('+x+')');

  var menuName=x.getAttribute('menuName');
  var menu=menus[menuName];

  if(!menu)menus[menuName]=menu={};

  var activeItem;

  if(menu){
    activeItem=menu.activeItem;
    if(activeItem){
      activeItem.className='';
    }
  }
  activeItem=x;
  activeItem.className='active';
  menu.activeItem=activeItem;
};
var IframeRequest=function(url,callback){
  //alert('IframeRequest('+url+', '+callback+')');
  this.doIframe=function(){
    var iframe=document.createElement('iframe');
    iframe.src=url;
    iframe.onload=callback;
    iframe.style.display='none';
    document.body.appendChild(iframe);
  }
};
var Ajax=function(url,callback){
  //alert('Ajax('+url+', '+callback+')');
  var xhr=new XMLHttpRequest();
  xhr.onreadystatechange=processRequest; // registering the callback function cannot have any arguments
  this.doGetSync=function(){
    xhr.open('GET',url,false);xhr.send(null);
    var r=xhr.responseText;
    update(callback[1],r);
  };
  this.doGet=function(){xhr.open('GET',url,true);xhr.send(null);};
  this.doPost=function(){
    //alert("doPost: url = "+url);
    var queryStringIndex=url.indexOf('?');
    var server,params;
    if(queryStringIndex>0){
      server=url.substring(0,queryStringIndex);
      params=url.substring((queryStringIndex+1));
      xhr.open('POST',server,true);
      xhr.setRequestHeader('Content-type','application/x-www-form-urlencoded');
      xhr.setRequestHeader('Content-length',params.length);
    }else{
      server=url;
      params=null;
      xhr.open('POST',server,true);
    }
    //alert("doPost: server = "+server+", params = "+params);
    xhr.setRequestHeader('Connection','close');
    xhr.send(params);
  };
  function processRequest(){
    if(xhr.readyState==4){
      this.response=xhr.responseText;
      if(callback){
        if(typeof callback=='function'){
          callback(this.response);
        }else if(callback instanceof Array){
          callback[0](callback[1],this.response);
        }else if(typeof callback==OBJECT){
          callback._this[callback.fn].apply(callback._this,[this.response,callback.args]);
        }
      }
    }
  }
};

var clickLi=function(li){
  var ul=li.parentNode;
  if(ul.opened){
    ul.className=ul.cn;
    ul.opened=false;
  }else{
    ul.cn=ul.className;
    ul.className=ul.cn+'-open';
    ul.opened=true;
    return;
  }
  var lis=ul.getElementsByTagName('li');
  var selected;
  for(var i=0;i<lis.length;i++){
    if(lis[i]!=li) {
      lis[i].className='';
    }else{
      lis[i].className='selected';
      selected = lis[i];
    }
  }
  return selected;
};
var clickUl=function(id){
  var ul=$(id);
  clickLi(ul.firstChild);
};
var clickLanguage=function(li,locale){
  var selected=clickLi(li);
  if(selected){
    window.location=contextUrl+'/ispaces?'+locale;
  }
};
function removeChildren(node){
  //if(node.hasChildNodes()) while(node.childNodes.length>= 1) node.removeChild(node.firstChild);
  while(node.hasChildNodes()) node.removeChild(node.firstChild);
}
function tutor(lang){
  //alert('tutor('+lang+')');
  /*
  $('greyout').style.display='block';
  $('tutordiv').style.display='block';
  */
  if(lang=='en'){
    playVideo2('http://www.youtube.com/v/u2i-FnSEGdo?version=3','Tutor');
  } else if(lang=='es') {
    playVideo2('http://www.youtube.com/v/ij5RFWZsw9M?version=3','Tutor');
  }
}
function closetutor(){
  //alert('closetutor()');
  $('tutordiv').style.display='none';
  $('greyout').style.display='none';
  $('tutor_en').style.display='none';
  $('tutor_es').style.display='none';
}
function closevideo(){
  //alert('closevideo()');
  $('videodiv').style.display='none';
  $('greyout').style.display='none';
}
function clickGreyout(){
  hideModals();
  hideGreyout();
}
function hideGreyout(){$('greyout').style.display='none'}
function hideModals(){
  $('forgotdiv').style.display='none';
  $('feedbackdiv').style.display='none';
  $('videodiv').style.display='none';
  $('forgotusernamediv').style.display='none';
}
function playEmbedded(url,id){
  //alert('playEmbedded("'+url+'", "'+id+'")');

  var player=$(id+'player');
  var output=$(id+'output');
  removeChildren(output);

  var video=createYouTubeObject(url);
  output.appendChild(video);
  player.style.display='block';
}
function playYouTube(url,id){
  //alert('playYouTube("'+url+'", "'+id+'")');
  var video=createYouTubeObject(url);
  var tag=$(id);
  removeChildren(tag);
  alert('playYouTube("'+url+'", "'+id+'"): '+tag+'.appendChild('+video+')');
  tag.appendChild(video);
  tag.style.display='block';
}
function createYouTubeObject(url){
  //alert('createYouTubeObject("'+url+'")');
  var object=document.createElement('object');
  object.setAttribute('width','100%');
  object.setAttribute('height','100%');
  object.appendChild(createParam('movie',url));
  object.appendChild(createParam('allowFullScreen','true'));
  object.appendChild(createParam('allowScriptAccess','always'));

  var embed=createYouTubeEmbed(url);
  object.appendChild(embed);

  return object;
}
function createYouTubeEmbed(url){
  //alert('createYouTubeEmbed("'+url+'")');

  var embed=document.createElement('embed');
  embed.setAttribute('src',url);
  embed.setAttribute('width','100%');
  embed.setAttribute('height','100%');
  embed.setAttribute('type','application/x-shockwave-flash');
  embed.setAttribute('allowfullscreen','true');
  embed.setAttribute('allowScriptAccess','always');

  return embed;
}
function playVideo(url,name){
  //alert('playVideo("'+url+'", "'+name+'")');

  $('greyout').style.display='block';

  var output=$('videovideo');
  var player=$('videodiv');
  var videoName=$('videoname');
  var video=createYouTubeObject(url);

  removeChildren(output);
  removeChildren(videoName);

  output.appendChild(video);
  videoName.appendChild(txt(name));

  player.style.display='block';
}
function playVideo2(url,name){
  //alert('playVideo2("'+url+'", "'+name+'")');
  //alert('playVideo2("'+url+'", "'+name+'"): document.body.scrollTop = '+document.body.scrollTop);

  $('greyout').style.display='block';

  var output=$('videovideo');
  var player=$('videodiv');
  var videoName=$('videoname');
  var video=createYouTubeObject(url);

  var height=400;
  var margin=((height/2)+50);
  //alert('playVideo2("'+url+'", "'+name+'"): margin = '+margin);

  margin=document.body.scrollTop-margin;
  //alert('playVideo2("'+url+'", "'+name+'"): margin = '+margin);

  player.style.marginTop=margin+'px';

  removeChildren(output);
  removeChildren(videoName);

  output.appendChild(video);
  videoName.appendChild(txt(name));

  player.style.display='block';
}

function createParam(name,value){
  //alert('createParam('+name+','+value+')');
  var param=document.createElement('param');
  param.setAttribute('name',name);
  param.setAttribute('value',value);
  return param;
}
function createVideoObject(videoName){
  //alert('createVideoObject('+videoName+')');

  var object=document.createElement('object');
  object.setAttribute('classid','clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B');
  object.setAttribute('codebase','http://www.apple.com/qtactivex/qtplugin.cab');
  object.setAttribute('width','100%');
  object.setAttribute('height','100%');
  object.appendChild(createParam('src',contextUrl+'/content/'+videoName));
  object.appendChild(createParam('autoplay','true'));
  object.appendChild(createParam('controller','true'));
  object.appendChild(createParam('href',contextUrl+'/content/'+videoName));
  object.appendChild(createParam('type','video/quicktime'));

  var embed=createVideo(videoName);
  object.appendChild(embed);

  return object;
}
function createVideo(videoName){
  //alert('createVideo('+videoName+')');

  var embed=document.createElement('embed');
  embed.setAttribute('src',contextUrl+'/content/'+videoName);
  embed.setAttribute('width','100%');
  embed.setAttribute('height','100%');
  embed.setAttribute('type','video/mp4');
  embed.setAttribute('controller','true');
  embed.setAttribute('autoplay','true');
  embed.setAttribute('pluginspage','http://www.apple.com/quicktime/download/');

  return embed;
}
var stopEvent=function(e){e=e||window.event;e.cancelBubble=true;if(e.stopPropagation)e.stopPropagation()};
var stopDefaultEvent=function(e){e=e||window.event;e.returnValue=false;if(e.preventDefault)e.preventDefault();};
var killEvent=function(e){stopEvent(e);stopDefaultEvent(e)};
var serializeForm=function(form){
  //alert('serializeForm()');
  var a=[],i,j,first;
  var add=function(n,v){a.push(encodeURIComponent(n)+'='+encodeURIComponent(v))};
  var elems=form.elements;
  for(i=0;i<elems.length;i+=1,first=false){
    if(elems[i].name&&elems[i].name.length>0){
      switch(elems[i].type){
        case 'select-one':first=true;
        case 'select-multiple':
          for(j=0;j<elems[i].options.length;j+=1){
            if(elems[i].options[j].selected){
              add(elems[i].name,elems[i].options[j].value);
              if(first){break}
            }
          }
          break;
        case 'checkbox':
        case 'radio':if(!elems[i].checked){break} /* else continue */
        default:add(elems[i].name,elems[i].value);break;
      }
    }
  }
  a.push('ajax=true');
  a.push('ms='+millis());
  return a.join('&');
};
function filterLogin(){
  //alert('filterLogin()');
  var password=document.getElementById('password').value;
  document.getElementById('password').value='';
  var passwordSha1=hex_sha1(password);
  document.getElementById('hash').value=passwordSha1;
}
function filterRegister(formId){
  //alert('filterRegister('+formId+')');
  return validateRegister(formId);
}
function validateRegister(id){
  //alert('validateRegister('+id+')');

  var validationObject={
    firstName:[
      {fn:'minlen',args:2,message:'(minimum length is 2)'}
      ,{fn:'maxlen',args:20,message:'(maximum length is 20)'}
      ,{fn:'alpha_s',message:'(alpha characters only)'}
    ]
    ,lastName:[
      {fn:'minlen',args:2,message:'(minimum length is 2)'}
      ,{fn:'maxlen',args:20,message:'(maximum length is 20)'}
      ,{fn:'alpha_sa',message:'(alpha characters only)'}
    ]
    ,email:[
      {fn:'email',message:'(invalid e-mail address)'}
      ,{fn:'maxlen',args:128,message:'(maximum length is 128)'}
    ]
    ,username:[
      {fn:'minlen',args:3,message:'(minimum length is 3)'}
      ,{fn:'maxlen',args:20,message:'(maximum length is 20)'}
      ,{fn:'alnum_uh',message:'(must be alphanumeric)'}
      ,{fn:'notemail',message:'(cannot be an e-mail address).'}
    ]
    ,password:[
      {fn:'minlen',args:8,message:'(minimum length is 8)'}
      ,{fn:'maxlen',args:20,message:'(maximum length is 20)'}
      ,{fn:'alnum',message:'(alphanumeric characters only)'}
    ]
    ,confirmpassword:[
      {fn:'minlen',args:8,message:'(minimum length is 8)'}
      ,{fn:'maxlen',args:20,message:'(maximum length is 20)'}
      ,{fn:'alnum',message:'(alphanumeric characters only)'}
    ]
  };

  var form=$(id+'form');

  var formValid=true;
  var elems=form.elements;
  for(var i=0;i<elems.length;i++){

    var elem=elems[i],name=elem.name,value=elem.value;
    //alert('validateAndSubmit('+id+'): name = '+name+', value = '+value);

    var validations=validationObject[name];

    if(validations){ // Does this field require validation?

      for(var j=0;j<validations.length;j++){

        var validation=validations[j];
        var fn=validation.fn;
        args=validation.args;

        var valid=Validator[fn](value,args);
        //alert('validateAndSubmit('+id+'): valid = '+valid);

        if(!valid){
          $(name+'label').className='invalid';
          $(name+'error').innerHTML=validation.message;
          if(formValid)elem.focus();
          formValid=false;
          break;
        }else{
          $(name+'label').className='valid';
          $(name+'error').innerHTML='';
        }

      }
    }
  } // for(var i=0;i<elems.length;i++)

  if(formValid){

    var username=form['username'].value;
    var password=form['password'].value;
    var confirmpassword=form['confirmpassword'].value;

    if(password!=confirmpassword){
      form['confirmpassword'].focus();
      $('confirmpasswordlabel').className='invalid';
      $('confirmpassworderror').innerHTML='(passwords do not match)';
      return false;
    }

    if(username==password){
      form['password'].focus();
      $('passwordlabel').className='invalid';
      $('passworderror').innerHTML='(username cannot be the same as password)';
      return false;
    }

  }

  return formValid;
}
function postForm(name,id){
  //alert('postForm('+name+', '+id+')');
  var form=$(name);
  //alert('postForm('+name+'): form.action = '+form.action);
  var queryString=serializeForm($(name));
  //alert('postForm('+name+'): queryString = '+queryString);
  var x=[form.action,'?',queryString]
  new Ajax(x.join(''),[updateId,id]).doGet();
}
var updateId=function(id,r){
  //alert('updateId('+id+', '+r+')');
  $(id).innerHTML=r;
  $(id+'content').style.display='none';
};

function submitModal(id){
  //alert('submitModal('+id+')');
  $(id+'button').value=$(id+'button').getAttribute('value1');
  $(id+'button').setAttribute('disabled','true');
  var form=$(id+'form');

  var email;
  var elems=form.elements;
  //alert('elems.length = '+elems.length);
  for(i=0;i<elems.length;i++){
    if(elems[i].name=='email'){
      //alert('elems['+i+'].value = '+elems[i].value);
      email=elems[i].value;
      //alert('Validator.validEmail('+email+') = '+Validator.validEmail(email));
      //alert('validEmail('+email+') = '+validEmail(email));
      return;
    }
  }

  var queryString=serializeForm(form);

  //alert('submitModal('+id+'): queryString = '+queryString);
  //new Ajax([form.action,'?',queryString].join(''),[updateModal,id+'header']).doGet();
  new Ajax([form.action,'?',queryString].join(''),[updateModal,id]).doGet();
}

function parens(s){return '('+s+')'}

var updateModal=function(id,r){
  //alert('updateModal('+id+', '+r+')');

  var o=eval(parens(r));
  if(o){
    $(id+'header').innerHTML=o.message;
    //alert('updateModal('+id+', '+r+'): o.success = '+o.success);
    if(o.success){
      window['success'+id]();
    }else{
      //window['enable'+id]();
      window['failed'+id]();
    }
  }
};
function getFormValue(form,name){
  var elems=form.elements;
  for(i=0;i<elems.length;i+=1,first=false){
    if(elems[i].name==name)return elems[i].value;
  }
}
function feedback(){
  //alert('feedback()');
  var feedbackDiv=$('feedbackdiv');
  if(!feedbackDiv.hasChildNodes())goSync('http://www.ispaces.com/ispaces/feedback?ajax=true','feedbackdiv'); // First time, go get the HTML.
  $('greyout').style.display='block';
  $('feedbackdiv').style.display='inline-block';
  escapeKeyFunction=closefeedback;
}
function closefeedback(){
  //alert('closefeedback()');
  $('feedbackdiv').style.display='none';
  hideGreyout();
  $('feedbackheader').innerHTML='Feedback';
  $('feedbackcontent').style.display='block';
  if(feedbackCloser)clearTimeout(feedbackCloser);
}
function postfeedback(){
  //alert('postfeedback()');

  var form=$('feedbackform');
  //alert('postfeedback(): form.action = '+form.action);
  var queryString=serializeForm(form);
  var x=[form.action,'?',queryString].join('');
  //alert('postfeedback(): x = '+x);

  var json="{success:true,message:'Thank you for your feedback.'}";
  var callback=function(){updateModal('feedback',json);};
  new IframeRequest(x,callback).doIframe();
}
function successfeedback(){
  //alert('successfeedback()');
  $('feedbackcontent').style.display='none';
  var feedbackCloser=setTimeout('closefeedback()',5000);
  //$('feedbackform').reset();
  //$('feedbackform').reset();

  $('feedbackform').elements['comment'].value='';
  //$('feedbackform').elements['type'].value='';
}
function forgotUsername(){
  //alert('forgotUsername()');
  var forgotUsernameDiv=$('forgotusernamediv');
  if(!forgotUsernameDiv.hasChildNodes())goSync('http://www.ispaces.com/ispaces/forgot-username?ajax=true','forgotusernamediv'); // First time, go get the HTML.
  $('greyout').style.display='block';
  $('forgotusernamediv').style.display='inline-block';
  escapeKeyFunction=closeforgotusername;

  var height=100;
  var margin=((height/2)+50);
  margin=document.body.scrollTop-margin;
  $('forgotusernamediv').style.marginTop=margin+'px';
}
function closeforgotusername(){
  //alert('closeforgotusername()');
  hideModals();
  hideGreyout();
  enableforgotusername();
  $('forgotusernameform').reset();
  $('forgotusernameheader').innerHTML='Forgot Username';
  $('forgotusernamecontent').style.display='block';
  $('forgotusernamediv').style.display='none';
}
function enableforgotusername(){
  //alert('enableforgotusername()');
  $('forgotusernamebutton').value=$('forgotusernamebutton').getAttribute('value0');
  $('forgotusernamebutton').removeAttribute('disabled');
}
function forgot(){
  //alert('forgot()');
  var forgotDiv=$('forgotdiv');
  if(!forgotDiv.hasChildNodes())goSync('http://www.ispaces.com/ispaces/forgot?ajax=true','forgotdiv'); // First time, go get the HTML.
  $('greyout').style.display='block';
  $('forgotdiv').style.display='inline-block';
  escapeKeyFunction=closeforgot;
  var height=100;
  var margin=((height/2)+50);
  margin=document.body.scrollTop-margin;
  $('forgotdiv').style.marginTop=margin+'px';
}
function postforgotusername(){
  //alert('postforgotusername()');
  var forgotusernamebutton=$('forgotusernamebutton');
  forgotusernamebutton.value=forgotusernamebutton.getAttribute('value1');
  forgotusernamebutton.setAttribute('disabled','true');
  var username=$('forgotusernameusername').value;
  var json="{success:true,message:'Check your e-mail.'}";
  var callback=function(){updateModal('forgotusername',json);};
  new IframeRequest([cloudUrl,'/forgotusername/',username].join(''),callback).doIframe();
}
function successforgotusername(){
  //alert('successforgotusername()');
  $('forgotusernamecontent').style.display='none';
  setTimeout('closeforgotusername()',5000);
}
function failedforgot(){
  //alert('failedforgotusername()');
  enableforgotusername();
}
function enableforgotusername(){
  //alert('enableforgotusername()');
  $('forgotusernamebutton').value=$('forgotusernamebutton').getAttribute('value0');
  $('forgotusernamebutton').removeAttribute('disabled');
}
function closeforgotusername(){
  //alert('closeforgotusername()');
  hideModals();
  hideGreyout();
  enableforgotusername();
  $('forgotusernameform').reset();
  $('forgotusernameheader').innerHTML='Forgot Username';
  $('forgotusernamecontent').style.display='block';
}
function postforgot(){
  //alert('postforgot()');
  var forgotbutton=$('forgotbutton');
  forgotbutton.value=forgotbutton.getAttribute('value1');
  forgotbutton.setAttribute('disabled','true');
  var username=$('forgotpasswordusername').value;
  var json="{success:true,message:'Check your e-mail.'}";
  var callback=function(){updateModal('forgot',json);};
  new IframeRequest([cloudUrl,'/forgot/',username].join(''),callback).doIframe();
}
function successforgot(){
  //alert('successforgot()');
  $('forgotcontent').style.display='none';
  setTimeout('closeforgot()',5000);
}
function failedforgot(){
  //alert('failedforgot()');
  enableforgot();
}
function closeforgot(){
  //alert('closeforgot()');
  hideModals();
  hideGreyout();
  enableforgot();
  $('forgotform').reset();
  $('forgotheader').innerHTML='Forgot Password';
  $('forgotcontent').style.display='block';
}
function enableforgot(){
  //alert('enableforgot()');
  $('forgotbutton').value=$('forgotbutton').getAttribute('value0');
  $('forgotbutton').removeAttribute('disabled');
}
window.onkeypress=function(e){keyPress(e)};
function keyPress(e){
  var key=e.keyCode;
  if(key==27){ // ESC
    escapeKey();
    return false;
  }
};
var escapeKey=function(){if(escapeKeyFunction)escapeKeyFunction();escapeKeyFunction=null;};

var quotes=[
  [
    ['iSpaces chosen as 1 of 3 Best Start Ups in the Cloud Computing World Series!']
    ,'The Cloud Computing World Series Awards'
    ,18
  ]
  ,[
    [
      'iSpaces is named one of Europe\'s TOP 25'
      ,'Cloud Computing Rising Stars!'
    ]
    ,'CloudTweaks'
    ,23
  ]
  ,[
    ['I like this idea... I can see it will be useful to me...'
    ,'Keep it going... it will change the way I work.']
    ,'Barry Schofield'
    ,23
  ]
  ,[
    ['With iSpaces, every computer is my computer.']
    ,'Donnie Masterson'
    ,23
  ]
  ,[
   ['god my life is now way easier']
    ,'Rian Murphy'
    ,23
  ]
  ,[
    [
      'Overall, the first impression about this service is great!'
      ,'Keep up the great work.'
    ]
    ,'SK Mezanul Haque, My Technology Guide'
    ,23
  ]
  ,[
    ['The \'persistence\' of iSpaces is priceless!']
    ,'Linda Hamilton, Research & Data Analyst'
    ,23
  ]
  ,[
    ['iSpaces named one of the 8 amazing tech advances on the horizon.']
    ,'John Brandon, Tech Radar'
    ,23
  ]
  ,[
    [
      'The ability to browse web pages, save the browsing history, and access them through various computers is very appealing,'
      ,'especially to those who run their business online. This is going to save valuable time in the long run and may be one of'
      ,'the reasons that people are going to love iSpaces.'
    ]
    ,'Ivan, Cloud Business Review'
    ,15
  ]
  ,[
    [
      'Their unique NonStopWeb persistence technology keeps me logged in and out of iSpaces'
      ,'from multiple computers and I never again have to reopen my applications and documents - a big time saver.'
    ]
    ,'SK Mezanul Haque, My Technology Guide'
    ,18
  ]
  ,[
    [
      'We have seen cloud based desktop services, but none like iSpaces'
      ,'where you never have to worry about the state of last usage of your desktop.'
    ]
    ,'Abdul Jaleel Kavungal Kunnumpurath, Cloud Computing Journal'
    ,18
  ]
  ,[
    //['I discovered your beta a couple of days ago and I am absolutely amazed','by your CloudBrowser! Congrats!!!']
    ['I discovered your beta a couple of days ago and I am absolutely amazed','by your CloudBrowser! Congrats!!!']
    ,'Sylvain B, iSpaces User'
    ,23
  ]
  ,[
    ['Awesome concept!']
    ,'Phil G, iSpaces User'
    ,23
  ]
];
var quoteElement;
var quoteIndex=0;
var quoteInterval;
var quoteCount=quotes.length;
function startQuotes(){
  quoteElement=$('quote');
  nextQuote();
  quoteInterval=setInterval("nextQuote()",7777);
}
function nextQuote(){
  if(quoteIndex>=quoteCount)quoteIndex=0;
  var quote=quotes[quoteIndex++];
  var lines=quote[0];
  var credit=quote[1];
  var fontSize=quote[2];
  var div=document.createElement('div');
  for(var i=0;i<lines.length;i++){
    if(i>0)div.appendChild(document.createElement('br'));
    div.appendChild(document.createTextNode(lines[i]));
    div.onclick=nextQuote;
    div.style.cursor='pointer';
  }
  if(credit){
    div.appendChild(document.createElement('br'));
    var span=document.createElement('span');
    span.appendChild(document.createTextNode(credit));
    span.style.color='#474747';
    span.style.fontSize='13px';
    span.style.fontStyle='italic';
    div.appendChild(span);
  }
  if(fontSize)quoteElement.style.fontSize=fontSize+'px';
  //$('quote').appendChild(document.createTextNode(quote[0]));
  //$('quote').replaceChild(document.createTextNode(quote[0]),$('quote').firstChild);
  quoteElement.replaceChild(div,quoteElement.firstChild);
}


