YAHOO.util.Event.on(window, 'load', qsAttachHandlers);

//Global vars for quickstart
var count=0;
var origLinkBackColor; 
var origLinkBackColor;
var flashColor = new Array();
var origLinkFontWeight;
var flashText = new Array();



//attach the events to specific elements related to QuickStart
function qsAttachHandlers(){

     //members area link to open ithe div
     if (document.getElementById('qs_link')) { //This element only appears on the control panel
	     document.getElementById('qs_link').onclick=function() {
		     document.getElementById('divQuickStart').style.display="block";
               qsSetOpenCloseQS("open");
          //log...deliberately not capturing the response.
               YAHOO.util.Connect.asyncRequest("GET", '/controlpanel/quickstart/log.cmp?logItem=qs_link');
	     }
     }
  
   //button on the div to close the wizard
	document.getElementById('qs_close').onclick=function() {
     	document.getElementById('divQuickStart').style.display="none";
   
          qsSetOpenCloseQS("closed");
          //log...deliberately not capturing the response.
          YAHOO.util.Connect.asyncRequest("GET", '/controlpanel/quickstart/log.cmp?logItem=qs_close');
	}


     //function definition the asynchronous call below.
     function qsRedirect( o ) {
          this.style.cursor="auto";
          this.disabled=false;
          document.body.style.cursor="auto";
          window.location = qsButtonData[o.argument];
          //console.log (arguments);
     } 

     var qsButtonData = new Object();
     qsButtonData['qs_button_domain']        = "/domreg/domainNameNotify.bml";
     qsButtonData['qs_demo_domain']          = "/domreg/domainNameNotify.bml";

     qsButtonData['qs_button_email']         = "/webControl/emailpack/mailcentral.bml?createmailbox=1";
     qsButtonData['qs_demo_email']           = "/webControl/emailpack/mailcentral.bml?createmailbox=1";

     qsButtonData['qs_button_siteEditor']    = "/controlpanel/site-editing-options/index.bml";
     qsButtonData['qs_demo_site']      = "/controlpanel/site-editing-options/index.bml";

     //attach the handlers with the appropriate 
     for(var x in qsButtonData) {
          if (document.getElementById(x) ) {//button may or may not exist

               document.getElementById(x).onclick = function() {
                    this.style.cursor="progress";
                    this.disabled=true;
                    document.body.style.cursor="progress";
                    if (x.substr(0,7) == 'qs_demo'){
                      qsSetOpenCloseQS('open');
                    }
                    //log
                    YAHOO.util.Connect.asyncRequest("GET", '/controlpanel/quickstart/log.cmp?logItem='+this.id, {success:qsRedirect, argument:this.id, scope:this});
                                        

               }
          }
     }
}

function qsSetOpenCloseQS(qsState){     
     //set the date (5 days out
     var qsExDate = new Date();
     qsExDate.setDate(qsExDate.getDate()+90);
 
     var myhost = document.location.host;
     var myhostarray = myhost.split('.');
     var myhostsplice = myhostarray.splice(1,(myhostarray.length-1));
     var qsDomain = myhostsplice.join('.');
     var qsValue = (qsState == "open") ? 1 : 0;
     var qsCookie = "qsOpenClose="+qsValue+"; expires="+qsExDate+"; path=/; domain=."+qsDomain;
     document.cookie = qsCookie;     
}

function flashElements() {

     var theLink = document.getElementById('qs_link');

     if (count == 0){                                  //Capture the initial position
          origLinkFontWeight = theLink.style.fontWeight;
          flashText[0]    = theLink.style.color
          flashText[1]    = "Red";
          theLink.style.fontWeight = "bold";
          count++;
          setTimeout(flashElements, 200);
          return 0;
     } else if (count<19) {                            //flash the link
          theLink.style.color = flashText[count % 2];     
     } else{                                           //put things back
          theLink.style.fontWeight = origLinkFontWeight;
          theLink.style.color = flashText[0] 
          count=0;                    
          return 0;
     }
     count++;
     setTimeout(flashElements, 150);
}
