function writeLoginStage(docName) {
   var myQueryString=document.location.search;
   // remove the '?' sign if exists
   if (myQueryString[0]='?') {
      myQueryString=myQueryString.substr(1, myQueryString.length-1);
   }
   //Output the flash object
   document.write(
      '<object type="application/x-shockwave-flash" data="'+docName+'" width="250" height="140">\n'+
      '   <param name="movie" value="'+docName+'" />\n'+
      '   <param name="allowFullScreen" value="true" />\n'+
      '   <param name="salign" value="lt" />\n'+
      '   <param name="flashvars" value="'+myQueryString+'" />\n'+
      '</object>');	
}

function showFlashContent(docName, p_width, p_height) {
   var myQueryString=document.location.search;
   // remove the '?' sign if exists
   if (myQueryString[0]='?') {
      myQueryString=myQueryString.substr(1, myQueryString.length-1);
   }
   document.write(
      '<object type="application/x-shockwave-flash" data="'+docName+'" width="'+p_width+'" height="'+p_height+'">\n'+
      '   <param name="movie" value="'+docName+'" />\n'+
      '   <param name="allowFullScreen" value="true" />\n'+
      '   <param name="salign" value="lt" />\n'+
      '</object>');
}

function setCookie(passed_id) {
   var ExpireDate = new Date ();
   var oneDay = (1 * 24 * 3600 * 1000);
   var oneHour = (1 * 3600 * 1000);
   var halfHour = (0.5 * 3600 * 1000);
   var quarterHour = (0.25 * 3600 * 1000);
   var hasCookieAlready = checkCookie(passed_id);
   //Currently set to quarterHour
   ExpireDate.setTime(ExpireDate.getTime() + quarterHour);
   document.cookie ="ID="+passed_id+"; expires='"+ExpireDate.toGMTString()+"'; path=/";   
   if ( !hasCookieAlready ){
      location.replace('agents/');
   }
}

function checkCookie( passed_id ) {
   //Check if the cookie exists
   var chk_all_cookies = document.cookie.split( ';' );
   var chk_cookie_found = false;
   for ( i = 0; i < chk_all_cookies.length; i++ ) {
      if (chk_all_cookies[i] == "ID="+passed_id){
         chk_cookie_found = true;
         return true;
      }
   }
   if ( !chk_cookie_found ) {
      return false;
   }
}

function getCookie( passed_id ) {
   //Check if the cookie exists: refresh it if it does, go to home page if it does not.
   var all_cookies = document.cookie.split( ';' );
   var cookie_found = false;
   for ( i = 0; i < all_cookies.length; i++ ) {
      if (all_cookies[i] == "ID="+passed_id){
         cookie_found = true;
         //refresh the cookie
         setCookie(passed_id)
         return true;
      }
   }
   if ( !cookie_found ) {
      location.replace('http://www.xlmeeting.com');
   }
}	