

window.onload = StartPopUp;

// after window gets loaded, invoke the StartPopUp function to generate popup message
//--------------------------FUNCTION StartPopUp----------------------------    
    function StartPopUp() {
     //******************START KS*****************
     if (CountryTag=="KS") {
		//var curScheduleYear; 
        //var curScheduleMonth; 
        //var curDate; 
        var found = false;
        var update = false;
        //var curScheduleDateArr;
        
        found = true;
        //curScheduleYear=2009;
        //curScheduleMonth=1;
        //curScheduleDateArr=14;
        if(found) {
            showPopup();
        }
        else
        {
            //alert("No schedule date is found!");
        }
       }
     //******************START US*****************
     else if(CountryTag=="US")  
     {
		var found = false;
		var d = new Date();
		var day=d.getDate();
		var hours=d.getHours();
 		if ( (day>=27&& day<=31)||(day==1 && hours<=12) ){ found = true;} 
       
        //found = true;
        if(found) {
			
            showPopup_US();
        }
        else
        {
            //alert("No schedule date is found!");
        }     
    }
      //******************START Cananda*****************
     else if(CountryTag=="CA")  
     {
		var found = false;
		var d = new Date();
		var day=d.getDate();
		var hours=d.getHours();
 		if ( (day>=28 && day<=31)||(day==1 && hours<=12) ){ found = true;} 
        
        //found = true;
        if(found) {
            showPopup_CA();
        }
        else
        {
            //alert("No schedule date is found!");
        }     
       } 
	//******************end Cananda*****************      
    }
 //--------------------------FUNCTION myOnClick----------------------------       
    function myOnClick(e) {
	   		var currlocation;
	   		var newlocation="";
	   		currlocation=window.location.toString();
			var strSub1="";
			var strSub2="";
			
			var strStart=currlocation.indexOf(".asp?"); 
			var strLength;
			
			if (strStart>0){ 
			   strLength=currlocation.length;
			   strSub1 =currlocation.substring(0,strStart+5)
			   if (strLength > strStart+5){
			      strSub2="&"+currlocation.substring(strStart+5,strLength);}
			      newlocation=strSub1+"oksave=1"+ strSub2;
			}
			else
			{newlocation=currlocation+"?oksave=1";}	
			
			//alert(newlocation);
	   		//if (currlocation.indexOf("home.asp")>0 || currlocation.indexOf("favority.asp")>0 ||  currlocation.indexOf("Express.asp")>0){
	   		 //newlocation=currlocation+"?oksave=1"
	   		//} 
	   		//if(currlocation.indexOf("display_dept.asp")>0){
	   		 //newlocation=currlocation+"&oksave=1"
	   		//}
	   		
	   		if (LangTag=="Kor") {
	   		 	alert("½ÅÃ»ÀÌ ¿Ï·áµÇ¾ú½À´Ï´Ù.");
	   		 	window.location=newlocation;
	   		 	//window.location="home.asp?oksave=1" 

	   		 	//closePopup();
	   		 	  
	   		     }
	   		else{		
   	 			alert("Your application is successfully accepted."); 
	   		 	window.location=newlocation;
	   		 	//window.location="home.asp?oksave=1" 
	   		 	//closePopup();  
	   		} 
	   }	

 //--------------------------FUNCTION showPopup_US----------------------------       
    function showPopup_US() {
        
        //var period1 = true;
        //var period2 = true;
		var msgtitle;
		var msg1;
		var msg2;
		var msg3;
		var msg4;
		var msgbutton;
		var msgconfirm;
		var msgclose;
	   	
	   	var d = new Date();
		var day=d.getDate();
		var nextday=d.getDate()+1; //last day of the month
		var hours=d.getHours();
		var showmsg
		if (day>=27&& day<=31){ showmsg = 1;} 
		if (day==1 && hours<=12){ showmsg = 2;} 
		

       if (LangTag=="Spn") {
           
				if (showmsg==1){
					msg1="Sunrider IBOs, please be aware that all orders, Product Pack/Gift Set serial number transfers, and Sales Volume (SV) transfers made after 9:00 pm, PDST on the last day of the month will be applied to the next month,Wholesale Price Bonus cycle."
					msg2="For further information regarding the Wholesale Price Bonus please, contact the Business Services department at (310) 781-8096, M - F 8:00 am - 4:00 pm.";
					msg3="";
					msg4="";
				}
				else if (showmsg==2){
					msg1="¡Información Importante!"
					msg2="Por favor tenga en cuenta que toda transacción ingresada en el sistema después de las 9:00 pm. tiempo del pacifico, en el último día del mes serán procesada y contadas automáticamente con el VV del próximo mes. Por lo tanto, para ser contado para el VV del mes actual: patrocinio, compras de productos, transferencias de Paquete de Producto/Set de Obsequio u otras transacciones debe ser completadas a mas tardar a las 9 p.m. Horario de Pacifico.";
					msg4="Si tiene alguna pregunta referente a este tema, por favor envíenos un correo electrónico a Servicio a Negocio a info@sunrider.com. Gracias";
					msg3=""
				}
				msgclose="Close";
  
        }
       else if (LangTag=="Chu") {
				if (showmsg==1){
					msg1="Sunrider IBOs, please be aware that all orders, Product Pack/Gift Set serial number transfers, and Sales Volume (SV) transfers made after 9:00 pm, PDST on the last day of the month will be applied to the next month,Wholesale Price Bonus cycle."
					msg2="For further information regarding the Wholesale Price Bonus please, contact the Business Services department at (310) 781-8096, M - F 8:00 am - 4:00 pm.";
					msg3="";
					msg4="";
				}
				
				
				
				
				
				else if (showmsg==2){
					msg1="­«­n«H®§¡I"
					msg2="½Ðª`·N¡G©Ò¦³¨C¤ëªº³Ì«á¤@¤Ñ¦b¦è©¤®É¶¡±ß¤W9:00¥H«á¤Uªº¥æ©ö«ü¥O¡A³£·|¦Û°Ê°O¤J¤U­Ó¤ëªº·~ÁZ¤¤³B²z©Mµ²ºâ¡C¦]¦¹¡A¥]¬A·s¤Hµn°O¡B²£«~­qÁÊ¡BSVÂà²¾¡B²£«~®M²°/Â§²°Âà²¾¡A©Î¨ä¥¦¥ô¦ó§ó°Ê¡A¨ä«ü¥O¥²¶·©ó¦è©¤®É¶¡±ß¤W9:00¥H«e§¹¦¨¡A¤~¯à­p¤J·í¤ëSV¤¤¡C";
					msg4="¦p±z¹ï¦¹¦³¥ô¦óºÃ°Ý¡A½Ð¥H¹q¶l«t¸ß¥ø·~ªA°È³¡¡Rinfo@sunrider.com¡CÁÂÁÂ¡I";
					msg3=""
				}

				
				
				
				
				
				msgclose="Close";
  
           }          
       else{
			
				if (showmsg==1){
					msg1="Sunrider IBOs, please be aware that all orders, Product Pack/Gift Set serial number transfers, and Sales Volume (SV) transfers made after 9:00 pm, PDST on the last day of the month will be applied to the next month,Wholesale Price Bonus cycle."
					msg2="For further information regarding the Wholesale Price Bonus please, contact the Business Services department at (310) 781-8096, M - F 8:00 am - 4:00 pm.";
					msg3="";
					msg4="";

				}
				
				else if (showmsg==2){				
					msg1="Important information!"
					msg2="Please note that all transactions entered in the system after 9 p.m. PDT. on the last day of the month will automatically be processed and counted with the next month’s SV.  Therefore,  to be counted for the current SV month: sponsoring, product purchases, SV transfers, Product Pack/Gift Set transfers, or any other transactions must be completed by 9 p.m., PDT.";
					msg4="If you have any questions regarding this issue, please email Business Service Reps at info@sunrider.com.  Thank you. ";
					msg3=""
				}	
					msgclose="Close";	
       
       }          
		// check for DOM if all elements are ready to parse
        //if(document && document.getElementsByTagName && document.getElementById && document.body) {
            
            // search for body element     
            var bodyElement = document.getElementsByTagName("body")[0];
            
            // create header for popup message
            var headerElement = document.createElement("div");
            headerElement.id = "header";
            
            // create close tag
            var closeLink = document.createElement("div");
            closeLink.id = "closeTag";
            closeLink.onclick = closePopup;
            closeLink.appendChild(document.createTextNode(msgclose));
            
            headerElement.appendChild(closeLink);
           
                 
            // create message title
            var msgElement = document.createElement("div");
            //msgElement.id = "msgbody";
            //msgElement.style.fontFamily = "Verdana";
            //msgElement.style.fontSize = "12px";
            //msgElement.style.padding = "10px";
			//msgElement.style.margin = "auto";
            //msgElement.style.width = "95%";
            //msgElement.appendChild(document.createTextNode(msg1));
			//var myText = document.createTextNode(msg1);
			//var font = document.createElement("font");
			//font.setAttribute('style', 'font-weight:bold;');
			//font.appendChild(myText);
			//msgElement.appendChild(font);
            
            // list messages
			var orderListElement = document.createElement("ol");
			
			//message 1                 
			var listElement = document.createElement("");;
			listElement.className = "listItem";
			listElement.appendChild(
			document.createTextNode(msg1)); 
			orderListElement.appendChild(listElement); 
			orderListElement.appendChild(document.createElement("br"));
			orderListElement.appendChild(document.createElement("br"));
			
			//message 2                 
			var listElement = document.createElement("");;
			listElement.className = "listItem";
			listElement.appendChild(
			document.createTextNode(msg2)); 
			orderListElement.appendChild(listElement); 
			orderListElement.appendChild(document.createElement("br"));			                       
			msgElement.appendChild(orderListElement);
			//message 3                 
			var listElement = document.createElement("");;
			listElement.className = "listItem";
			listElement.appendChild(
			document.createTextNode(msg3)); 
			orderListElement.appendChild(listElement); 
			orderListElement.appendChild(document.createElement("br"));	
			orderListElement.appendChild(document.createElement("br"));			                       
				                       
			msgElement.appendChild(orderListElement);
			//message 4                 
			var listElement = document.createElement("");;
			listElement.className = "listItem";
			listElement.appendChild(
			document.createTextNode(msg4)); 
			orderListElement.appendChild(listElement); 
			orderListElement.appendChild(document.createElement("br"));			                       
			msgElement.appendChild(orderListElement);
         
            // create popup message box
            var cutoffMsgElement = document.createElement("div");
            cutoffMsgElement.id = "cutoffmsg";
            
            // append header and message body to popup message box
            cutoffMsgElement.appendChild(headerElement);
            cutoffMsgElement.appendChild(msgElement);
            
            // append popup message box to body
            bodyElement.appendChild(cutoffMsgElement);
            
            // setup popup box location
            var LeftPosition = (screen.width) ? (screen.width-420)/2 : 0;
            var TopPosition = (screen.height) ? (screen.height-700)/2 : 0;
            
            // show up message box at desired location
            cutoffMsgElement.style.left = LeftPosition + "px";
            cutoffMsgElement.style.top = TopPosition + "px";
            cutoffMsgElement.style.display = "block";
            
            // make the popup window dragable
            DragHandler.attach(cutoffMsgElement);
        }  
  //--------------------------FUNCTION showPopup_CA----------------------------       
    function showPopup_CA() {
        
        //var period1 = true;
        //var period2 = true;
		var msgtitle;
		var msg1;
		var msg2;
		var msg3;
		var msg4;
		var msgbutton;
		var msgconfirm;
		var msgclose;
		
		var d = new Date();
		var day=d.getDate();
		var nextday=d.getDate()+1; //last day of the month
		var hours=d.getHours();
		var showmsg
		if (day>=28 && day<=31){ showmsg = 1;} 
		if (day==1 && hours<=12){ showmsg = 2;} 
		
		
       if (LangTag=="Fre") {
				if (showmsg==1){
					msg1="Sunrider IBOs, please be aware that all orders, Product Pack/Gift Set serial number transfers, and Sales Volume (SV) transfers made after 9:00 pm, PDST on the last day of the month will be applied to the next month,Wholesale Price Bonus cycle."
					msg2="For further information regarding the Wholesale Price Bonus please, contact the Business Services department at (310) 781-8096, M - F 8:00 am - 4:00 pm.";
					msg3="";
					msg4="";
				}
				
				else if (showmsg==2){				
					msg1="Important information!"
					msg2="Please note that all transactions entered in the system after 9 p.m. PDT. on the last day of the month will automatically be processed and counted with the next month’s SV.  Therefore,  to be counted for the current SV month: sponsoring, product purchases, SV transfers, Product Pack/Gift Set transfers, or any other transactions must be completed by 9 p.m., PDT.";
					msg4="If you have any questions regarding this issue, please email Business Service Reps at info@sunrider.com.  Thank you. ";
					msg3=""
				}	
					msgclose="Close";	
  
            }
       else{
			
				if (showmsg==1){
					msg1="Sunrider IBOs, please be aware that all orders, Product Pack/Gift Set serial number transfers, and Sales Volume (SV) transfers made after 9:00 pm, PDST on the last day of the month will be applied to the next month,Wholesale Price Bonus cycle."
					msg2="For further information regarding the Wholesale Price Bonus please, contact the Business Services department at (310) 781-8096, M - F 8:00 am - 4:00 pm.";
					msg3="";
					msg4="";
				}
				
				else if (showmsg==2){				
					msg1="Important information!"
					msg2="Please note that all transactions entered in the system after 9 p.m. PDT. on the last day of the month will automatically be processed and counted with the next month’s SV.  Therefore,  to be counted for the current SV month: sponsoring, product purchases, SV transfers, Product Pack/Gift Set transfers, or any other transactions must be completed by 9 p.m., PDT.";
					msg4="If you have any questions regarding this issue, please email Business Service Reps at info@sunrider.com.  Thank you. ";
					msg3=""
				}	
					msgclose="Close";	

       
       }          
		// check for DOM if all elements are ready to parse
        //if(document && document.getElementsByTagName && document.getElementById && document.body) {
            
            // search for body element     
            var bodyElement = document.getElementsByTagName("body")[0];
            
            // create header for popup message
            var headerElement = document.createElement("div");
            headerElement.id = "header";
            
            // create close tag
            var closeLink = document.createElement("div");
            closeLink.id = "closeTag";
            closeLink.onclick = closePopup;
            closeLink.appendChild(document.createTextNode(msgclose));
            
            headerElement.appendChild(closeLink);
           
       
          
            // create message title
            var msgElement = document.createElement("div");
           // msgElement.id = "msgbody";
           // msgElement.style.fontFamily = "Verdana";
           // msgElement.style.fontSize = "12px";
           // msgElement.style.padding = "10px";
		   //msgElement.style.margin = "auto";
           // msgElement.style.width = "95%";
           // msgElement.appendChild(document.createTextNode(msg1));
           
            // list messages
			var orderListElement = document.createElement("ol");
			
			//message 1                 
			var listElement = document.createElement("");;
			listElement.className = "listItem";
			listElement.appendChild(
			document.createTextNode(msg1)); 
			orderListElement.appendChild(listElement); 
			orderListElement.appendChild(document.createElement("br"));
			orderListElement.appendChild(document.createElement("br"));
			
			//message 2                 
			var listElement = document.createElement("");;
			listElement.className = "listItem";
			listElement.appendChild(
			document.createTextNode(msg2)); 
			orderListElement.appendChild(listElement); 
			orderListElement.appendChild(document.createElement("br"));			                       
			msgElement.appendChild(orderListElement);
			
			//message 3                 
			var listElement = document.createElement("");;
			listElement.className = "listItem";
			listElement.appendChild(
			document.createTextNode(msg3)); 
			orderListElement.appendChild(listElement); 
			orderListElement.appendChild(document.createElement("br"));	
			orderListElement.appendChild(document.createElement("br"));			                       	                       
			msgElement.appendChild(orderListElement);
			//message 4                 
			var listElement = document.createElement("");;
			listElement.className = "listItem";
			listElement.appendChild(
			document.createTextNode(msg4)); 
			orderListElement.appendChild(listElement); 
			orderListElement.appendChild(document.createElement("br"));			                       
			msgElement.appendChild(orderListElement);
         
            // create popup message box
            var cutoffMsgElement = document.createElement("div");
            cutoffMsgElement.id = "cutoffmsg";
            
            // append header and message body to popup message box
            cutoffMsgElement.appendChild(headerElement);
            cutoffMsgElement.appendChild(msgElement);
            
            // append popup message box to body
            bodyElement.appendChild(cutoffMsgElement);
            
            // setup popup box location
            var LeftPosition = (screen.width) ? (screen.width-420)/2 : 0;
            var TopPosition = (screen.height) ? (screen.height-700)/2 : 0;
            
            // show up message box at desired location
            cutoffMsgElement.style.left = LeftPosition + "px";
            cutoffMsgElement.style.top = TopPosition + "px";
            cutoffMsgElement.style.display = "block";
            
            // make the popup window dragable
            DragHandler.attach(cutoffMsgElement);
        }  
 //--------------------------FUNCTION showPopup----------------------------       
    function showPopup() {
        
        //var period1 = true;
        //var period2 = true;
		var msgtitle;
		var msg1;
		var msgbutton;
		var msgconfirm;
		var msgclose;
 
       if (LangTag=="Kor") {
     	    msgtitle="»õ·Î¿î ÇÁ·£Â÷ÀÌÁî »ç¾÷ Âü°¡½ÅÃ»¼­";
		    msg1="º»ÀÎÀº ½ã¶óÀÌ´õÄÚ¸®¾Æ°¡ 2009³â 1¿ù 31ÀÏÀÚ·Î ´Ù´Ü°èÆÇ¸Å¾÷À» Æó¾÷ÇÔ¿¡ µû¶ó ±âÁ¸ÀÇ µ¶¸³ ºñÁî´Ï½º ¿À³Ê(´Ù´Ü°èÆÇ¸Å¿ø)·Î¼­ÀÇ ÁöÀ§°¡ ÇØÁöµÇ¸ç, 2¿ù 1ÀÏºÎÅÍ ½ÃÇàµÇ´Â ½ã¶óÀÌ´õÀÇ »õ·Î¿î ÇÁ·£Â÷ÀÌÁî »ç¾÷(°¡¸Í»ç¾÷)¿¡ Âü¿©ÇÏ±â¸¦ Èñ¸ÁÇÏ¸ç, ÀÌ¿¡ ½ÅÃ»ÇÕ´Ï´Ù.";
            msgbutton="½ÅÃ»ÇÏ±â"; 
			msgconfirm="½ÅÃ»ÀÌ ¿Ï·áµÇ¾ú½À´Ï´Ù."; 
			msgclose="´Ý±â";
  
            }
       else{
			msgtitle="New Franchise Business Application"
			msg1="I confirm that my existing Independent Business Ownership (MLM sales person) will be terminated according to closing MLM business of Sunrider Korea effective on January 31, 2009 and I wish to join Sunrider new franchise business so, I am applying on it.";
			msgbutton="Apply now"; 
			msgconfirm="Your application is successfully accepted."; 
			msgclose="Close";
       
       }          
		// check for DOM if all elements are ready to parse
        //if(document && document.getElementsByTagName && document.getElementById && document.body) {
            
            // search for body element     
            var bodyElement = document.getElementsByTagName("body")[0];
            
            // create header for popup message
            var headerElement = document.createElement("div");
            headerElement.id = "header";
            
            // create close tag
            var closeLink = document.createElement("div");
            closeLink.id = "closeTag";
            closeLink.onclick = closePopup;
            closeLink.appendChild(document.createTextNode(msgclose));
            
            headerElement.appendChild(closeLink);
           
       
            // create message title
            var msgElement = document.createElement("div");
            msgElement.id = "msgbody";
            msgElement.style.fontFamily = "Verdana";
            msgElement.style.fontSize = "12px";
            msgElement.style.padding = "10px";
            msgElement.style.margin = "auto";
            msgElement.style.width = "95%";
            msgElement.appendChild(document.createTextNode(msgtitle));
            
            // list messages
            //if(period1 || period2) {
                 var orderListElement = document.createElement("ol");
 
                 //message 1                 
                 var listElement = document.createElement("");;
                 listElement.className = "listItem";
                 listElement.appendChild(
                 document.createTextNode(msg1)); 
                 orderListElement.appendChild(listElement); 
                 orderListElement.appendChild(document.createElement("br"));
                  
                
                 //mybutton
                 mybutton=document.createElement("BUTTON");
				 mybutton.style.height=30
				 mybutton.style.width=85;
				 mybutton.value=msgbutton;
				 mybutton.onclick=myOnClick;
 
				//hyper link
				//var link = document.createElement ('A');
				//link.appendChild (document.createTextNode (msgbutton));
				//link.setAttribute ('href', 'home.asp?oksave=1');	
 				//link.onclick=myOnClick;


                      
                 msgElement.appendChild(orderListElement);
                 msgElement.appendChild(mybutton);
                 //msgElement.appendChild(link);
               

            //}
            
            // create popup message box
            var cutoffMsgElement = document.createElement("div");
            cutoffMsgElement.id = "cutoffmsg";
            
            // append header and message body to popup message box
            cutoffMsgElement.appendChild(headerElement);
            cutoffMsgElement.appendChild(msgElement);
            
            // append popup message box to body
            bodyElement.appendChild(cutoffMsgElement);
            
            // setup popup box location
            var LeftPosition = (screen.width) ? (screen.width-420)/2 : 0;
            var TopPosition = (screen.height) ? (screen.height-700)/2 : 0;
            
            // show up message box at desired location
            cutoffMsgElement.style.left = LeftPosition + "px";
            cutoffMsgElement.style.top = TopPosition + "px";
            cutoffMsgElement.style.display = "block";
            
            // make the popup window dragable
            DragHandler.attach(cutoffMsgElement);
        }    
   // }
 //--------------------------FUNCTION closePopup----------------------------           
    // remove popup message box
    function closePopup() {
        if(document.getElementById("cutoffmsg")) {
            var bodyElement = document.getElementsByTagName("body")[0];
            var removeTarget = document.getElementById("cutoffmsg");
            removeTarget.style.display = "none";
            
            bodyElement.removeChild(removeTarget);
            
        }
    

        
    }
    
/*************************************/
/*  Crossbrowser Drag & Drop Handler
/*************************************/
var DragHandler = {
    // private property
    _dragObj:   null,
    
    // publich method to register the handler to the event 
    attach:     function(targetObj) {
        targetObj.onmousedown = DragHandler._dragStart;
        return targetObj;
    },   
    
    // private methid to start the drag action
    _dragStart: function(e) {
          // initialize the dragable object
          DragHandler._dragObj = this;
          // create short name
          var targetObj = DragHandler._dragObj;
          
          // determine the initial object location
          if(isNaN(parseInt(targetObj.style.top)))
            targetObj.style.top = "0px";
          if(isNaN(parseInt(targetObj.style.left)))
            targetObj.style.left = "0px";
          
          // e = e : for firefox ; e = window.event : for IE
          e = e ? e : window.event;
          
          // determine the initial mouse location
          targetObj.mouseX = e.clientX;
          targetObj.mouseY = e.clientY;
          
          // register handler to events
          document.onmousemove = DragHandler._dragMove;
          document.onmouseup = DragHandler._dragEnd;
          
          // prevent browser default action (e.g. hightlight)
          return false;
    },
    
    // private method to unregister the event handlers
    _dragEnd:   function() {
        // unregister the handler and object
        document.onmousemove = null;
        document.onmouseup = null;
        DragHandler._dragObj = null;
    },
    
    // private method to update the object location 
    _dragMove:  function(e) {
        // create short name
        var targetObj = DragHandler._dragObj;
        
        // determine the current object location
        var top = parseInt(targetObj.style.top);
        var left = parseInt(targetObj.style.left);
        
        // e = e : for firefox ; e = window.event : for IE
        e = e ? e : window.event;
        
        // update the object location
        targetObj.style.top = top + (e.clientY - targetObj.mouseY) + "px";
        targetObj.style.left = left + (e.clientX - targetObj.mouseX) + "px";
        
        // update the mouse location
        targetObj.mouseX = e.clientX;
        targetObj.mouseY = e.clientY;
        
        // prevent browser default action (e.g. hightlight)
        return false;      
    }
};       