﻿// JScript File

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function Login()
{
    document.form1.action.value = "login";
    document.form1.submit(); 
}

function Search()
{
    document.form1.action.value = "search";
    document.form1.submit(); 
}

function LoginDay()
{
    document.form1.action.value = "loginday";
    document.form1.submit(); 
}

function Logout()
{
    document.form1.action.value = "logout";
    document.form1.submit(); 
}

function UpdateCart()
{
    document.form1.action.value = "updatecart";
    document.form1.submit(); 
}

function GoBack()
{
    document.form1.action.value = "goback";
    document.form1.submit(); 
}

function ReviewOrder()
{
    document.form1.action.value = "revieworder";
    document.form1.submit(); 
}

function ProcessSubmit()
{
    document.form1.action.value = "processsubmit";
    document.form1.submit(); 
}

function TrackingSubmit()
{
    document.form1.action.value = "trackingsubmit";
    document.form1.submit(); 
}

function UpdateOrder()
{
    document.form1.action.value = "updateorder";
    document.form1.submit(); 
}

function UpdateCustomer()
{
    document.form1.action.value = "updatecustomer";
    document.form1.submit(); 
}

function UpdateBook()
{
    document.form1.action.value = "updatebook";
    document.form1.submit(); 
}

function UpdateComplete()
{
    document.form1.action.value = "updatecomplete";
    document.form1.submit(); 
}

function SendActivation()
{
    document.form1.action.value = "sendactivation";
    document.form1.submit(); 
}

function UpdateUser()
{
    document.form1.action.value = "updateuser";
    document.form1.submit(); 
}

function SubmitLogin()
{
    if (window.event && window.event.keyCode == 13)
    {
        Login();
    }
}

function SubmitLoginDay()
{
    if (window.event && window.event.keyCode == 13)
    {
        LoginDay();
    }
}

function SubmitSearch()
{
    if (window.event && window.event.keyCode == 13)
    {
        Search();
    }
}

function placeOrder(obj)
{
    if (checkPaymentForm())
    {
        toggleLayer('ordering');
        toggleLayer('hiddenImage');
        ContinueProcessing();
    } 
    else
    {
        alert('Please fill in all required fields.');
        return false;
    } 
}

function ContinueProcessing()
{
    document.form1.action.value = "createorder";
    document.form1.submit(); 
}

function checkPaymentForm()
{
    var goodForm = true;
   
    if (document.form1.cc_number.value == '')
    {
          flagFormField(document.form1.cc_number);
          goodForm = false; 
    } 
    else
    {
          unFlagFormField(document.form1.cc_number);
    }  
    
    if (document.form1.cc_expiration_month.value == '')
    {
          flagFormField(document.form1.cc_expiration_month);
          goodForm = false; 
    } 
    else
    {
          unFlagFormField(document.form1.cc_expiration_month);
    }  
    
    if (document.form1.cc_expiration_year.value == '')
    {
          flagFormField(document.form1.cc_expiration_year);
          goodForm = false; 
    } 
    else
    {
          unFlagFormField(document.form1.cc_expiration_year);
    }  
    
    if (document.form1.cc_security.value == '')
    {
          flagFormField(document.form1.cc_security);
          goodForm = false; 
    } 
    else
    {
          unFlagFormField(document.form1.cc_security);
    }
    
    return goodForm;         
}


function CreateStory(saveType)
{
   if (ValidateCreateStory())
   {
        if (saveType == 'save')
        {
            //toggleLayer('divSavePublish');
            //toggleLayer('divSavingStory');
            
            document.form1.action.value = "save";
        }
        else
        {
            //toggleLayer('divSavePublish');
            //toggleLayer('divPublishingStory');
            document.form1.action.value = "publish";
        }
        
        document.form1.submit(); 
   } 
   else
   {
        alert("Please enter at least one section (Morning, Afternoon, or Evening).");
        return false;
   } 
}

function CreateBook()
{
    var listBookStories = document.getElementById("listBookStories");
    
    if ((listBookStories.options.length >= 15) && (listBookStories.options.length >= 15))
    {
        for (var i=0; i<listBookStories.options.length; i++) {
		    var o = listBookStories.options[i];
    		
		    document.form1.book_stories.value = document.form1.book_stories.value + ',' + o.value;
		    //alert(document.form1.book_stories.value);
		    }
        //alert(listBookStories.options.length);
        document.form1.action.value = "createbook";
        document.form1.submit(); 
    }
    else
    {
        alert("Please select 15 to 300 stories.");
        return false;
    }
}

function CreateCustomer()
{
    if (ValidateCreateCustomer())
    {
        document.form1.action.value = "createcustomer";
        document.form1.submit(); 
    }
    else
    {
        if ((document.form1.new_ship_country.value == 'United_States') && (document.form1.new_ship_state.value == ''))
        {
              alert("Please select a shipping state for U.S. address.");
              return false; 
        }
        else if ((document.form1.new_bill_country.value == 'United_States') && (document.form1.new_bill_state.value == ''))
        {
              alert("Please select a billing state for U.S. address.");
              return false; 
        }
        else
        {
            alert("Please enter all required fields.");
            return false;
        }
    }
}

function ValidateCreateCustomer()
{
    var goodForm = true;
   
    if (document.form1.new_ship_first.value == '')
    {
          flagFormField(document.form1.new_ship_first);
          goodForm = false; 
    } 
    else
    {
          unFlagFormField(document.form1.new_ship_first);
    }    
     
    if (document.form1.new_ship_last.value == '')
    {
          flagFormField(document.form1.new_ship_last);
          goodForm = false; 
    } 
    else
    {
          unFlagFormField(document.form1.new_ship_last);
    }    
   
    if (document.form1.new_ship_address_one.value == '')
    {
          flagFormField(document.form1.new_ship_address_one);
          goodForm = false; 
    } 
    else
    {
          unFlagFormField(document.form1.new_ship_address_one);
    }     
   
    if (document.form1.new_ship_city.value == '')
    {
          flagFormField(document.form1.new_ship_city);
          goodForm = false; 
    } 
    else
    {
          unFlagFormField(document.form1.new_ship_city);
    }   
    
    if (document.form1.new_ship_country.value == 'United_States')
    {
        if (document.form1.new_ship_state.value == '')
        {
              flagFormField(document.form1.new_ship_state);
              goodForm = false; 
        }
        else
        {
              unFlagFormField(document.form1.new_ship_state);
        } 
    } 
    else
    {
          unFlagFormField(document.form1.new_ship_state);
    } 
    
    if (document.form1.new_bill_country.value == 'United_States')
    {
        if (document.form1.new_bill_state.value == '')
        {
              flagFormField(document.form1.new_bill_state);
              goodForm = false; 
        }
        else
        {
              unFlagFormField(document.form1.new_bill_state);
        }    
    } 
    else
    {
          unFlagFormField(document.form1.new_bill_state);
    }       
   
    if (document.form1.new_ship_zip.value == '')
    {
          flagFormField(document.form1.new_ship_zip);
          goodForm = false; 
    } 
    else
    {
          unFlagFormField(document.form1.new_ship_zip);
    } 
    
    if (document.form1.new_ship_phone.value == '')
    {
          flagFormField(document.form1.new_ship_phone);
          goodForm = false; 
    } 
    else
    {
          unFlagFormField(document.form1.new_ship_phone);
    } 
    
    if (document.form1.new_bill_email.value == '')
    {
          flagFormField(document.form1.new_bill_email);
          goodForm = false; 
    } 
    else
    {
          unFlagFormField(document.form1.new_bill_email);
    } 
    
    if (document.form1.new_bill_first.value == '')
    {
          flagFormField(document.form1.new_bill_first);
          goodForm = false; 
    } 
    else
    {
          unFlagFormField(document.form1.new_bill_first);
    }    
     
    if (document.form1.new_bill_last.value == '')
    {
          flagFormField(document.form1.new_bill_last);
          goodForm = false; 
    } 
    else
    {
          unFlagFormField(document.form1.new_bill_last);
    }    
   
    if (document.form1.new_bill_address_one.value == '')
    {
          flagFormField(document.form1.new_bill_address_one);
          goodForm = false; 
    } 
    else
    {
          unFlagFormField(document.form1.new_bill_address_one);
    }     
   
    if (document.form1.new_bill_city.value == '')
    {
          flagFormField(document.form1.new_bill_city);
          goodForm = false; 
    } 
    else
    {
          unFlagFormField(document.form1.new_bill_city);
    }    
   
    if (document.form1.new_bill_zip.value == '')
    {
          flagFormField(document.form1.new_bill_zip);
          goodForm = false; 
    } 
    else
    {
          unFlagFormField(document.form1.new_bill_zip);
    } 
    
    if (document.form1.new_bill_phone.value == '')
    {
          flagFormField(document.form1.new_bill_phone);
          goodForm = false; 
    } 
    else
    {
          unFlagFormField(document.form1.new_bill_phone);
    } 
    
    if (goodForm)  
    { 
        return true;
    }
    else
    {
        return false;
    } 
}

function ValidateCreateStory()
{
    var noMorning = false;
    var noAfternoon = false;
    var noEvening = false;
   
    if (document.form1.morning_of_day.value == '[type here...]')
    {
          noMorning = true; 
    } 
   
    if (document.form1.afternoon_of_day.value == '[type here...]')
    {
          noAfternoon = true; 
    } 
   
    if (document.form1.evening_of_day.value == '[type here...]')
    {
          noEvening = true; 
    } 
   
    if (noMorning && noAfternoon && noEvening)
    {
        return false;
    }
    else
    {
        return true;
    }
}

function CreateAccount()
{
   if (ValidateCreateAccount())
   {
        document.form1.action.value = "createaccount";
        document.form1.submit(); 
   } 
   else
   {
        alert("Please enter all required fields.");
        return false;
   } 
}

function EditAccount()
{
   if (ValidateEditAccount())
   {
        document.form1.action.value = "editaccount";
        document.form1.submit(); 
   } 
   else
   {
        alert("Please enter all required fields.");
        return false;
   } 
}

function SendContactEmail()
{
    if (ValidateContactEmail())
   {
        document.form1.action.value = "contactemail";
        document.form1.submit(); 
   } 
   else
   {
        alert("Please enter all required fields.");
        return false;
   } 
}

function AssistedLogin()
{
    if (ValidateAssistedLogin())
   {
        document.form1.action.value = "assistedlogin";
        document.form1.submit(); 
   } 
   else
   {
        alert("Please enter all required fields.");
        return false;
   } 
}

function ValidateContactEmail()
{
    var goodForm = true;
   
    if (document.form1.new_first.value == '')
    {
          flagFormField(document.form1.new_first);
          goodForm = false; 
    } 
    else
    {
          unFlagFormField(document.form1.new_first);
    }    
     
    if (document.form1.new_email.value == '')
    {
          flagFormField(document.form1.new_email);
          goodForm = false; 
    } 
    else
    {
          unFlagFormField(document.form1.new_email);
    }     
   
    if (document.form1.new_enquiry.value == '')
    {
          flagFormField(document.form1.new_enquiry);
          goodForm = false; 
    } 
    else
    {
          unFlagFormField(document.form1.new_enquiry);
    }    
   
    if (goodForm)  
    { 
        return true;
    }
    else
    {
        return false;
    }   
}

function ValidateAssistedLogin()
{
    var goodForm = true;
   
    if (document.form1.new_first.value == '')
    {
          flagFormField(document.form1.new_first);
          goodForm = false; 
    } 
    else
    {
          unFlagFormField(document.form1.new_first);
    }    
     
    if (document.form1.new_email.value == '')
    {
          flagFormField(document.form1.new_email);
          goodForm = false; 
    } 
    else
    {
          unFlagFormField(document.form1.new_email);
    }     
   
    if (document.form1.new_keyword.value == '')
    {
          flagFormField(document.form1.new_keyword);
          goodForm = false; 
    } 
    else
    {
          unFlagFormField(document.form1.new_keyword);
    }    
   
    if (goodForm)  
    { 
        return true;
    }
    else
    {
        return false;
    }   
}

function ValidateCreateAccount()
{
    var goodForm = true;
   
    if (document.form1.new_user.value == '')
    {
          flagFormField(document.form1.new_user);
          goodForm = false; 
    } 
    else
    {
          unFlagFormField(document.form1.new_user);
    }  
   
    if (document.form1.new_pass.value == '')
    {
          flagFormField(document.form1.new_pass);
          goodForm = false; 
    } 
    else
    {
          unFlagFormField(document.form1.new_pass);
    }   
   
    if (document.form1.new_pass2.value == '')
    {
          flagFormField(document.form1.new_pass2);
          goodForm = false; 
    } 
    else
    {
          unFlagFormField(document.form1.new_pass2);
    }    
   
    if (document.form1.new_first.value == '')
    {
          flagFormField(document.form1.new_first);
          goodForm = false; 
    } 
    else
    {
          unFlagFormField(document.form1.new_first);
    }    
     
    if (document.form1.new_last.value == '')
    {
          flagFormField(document.form1.new_last);
          goodForm = false; 
    } 
    else
    {
          unFlagFormField(document.form1.new_last);
    }    
   
    if (document.form1.new_email.value == '')
    {
          flagFormField(document.form1.new_email);
          goodForm = false; 
    } 
    else
    {
          unFlagFormField(document.form1.new_email);
    }     
   
    if (document.form1.new_job.value == '')
    {
          flagFormField(document.form1.new_job);
          goodForm = false; 
    } 
    else
    {
          unFlagFormField(document.form1.new_job);
    }    
   
    if (document.form1.new_city.value == '')
    {
          flagFormField(document.form1.new_city);
          goodForm = false; 
    } 
    else
    {
          unFlagFormField(document.form1.new_city);
    } 
    
    if (goodForm)  
    { 
        return true;
    }
    else
    {
        return false;
    }   
}

function ValidateEditAccount()
{
    var goodForm = true;
   
    if (document.form1.upd_pass.value == "1")
    {
        if (document.form1.new_pass.value == '')
        {
              flagFormField(document.form1.new_pass);
              goodForm = false; 
        } 
        else
        {
              unFlagFormField(document.form1.new_pass);
        }   
       
        if (document.form1.new_pass2.value == '')
        {
              flagFormField(document.form1.new_pass2);
              goodForm = false; 
        } 
        else
        {
              unFlagFormField(document.form1.new_pass2);
        }   
    }
     
    if (document.form1.new_first.value == '')
    {
          flagFormField(document.form1.new_first);
          goodForm = false; 
    } 
    else
    {
          unFlagFormField(document.form1.new_first);
    }    
     
    if (document.form1.new_last.value == '')
    {
          flagFormField(document.form1.new_last);
          goodForm = false; 
    } 
    else
    {
          unFlagFormField(document.form1.new_last);
    }    
   
    if (document.form1.new_email.value == '')
    {
          flagFormField(document.form1.new_email);
          goodForm = false; 
    } 
    else
    {
          unFlagFormField(document.form1.new_email);
    }     
   
    if (document.form1.new_job.value == '')
    {
          flagFormField(document.form1.new_job);
          goodForm = false; 
    } 
    else
    {
          unFlagFormField(document.form1.new_job);
    }    
   
    if (document.form1.new_city.value == '')
    {
          flagFormField(document.form1.new_city);
          goodForm = false; 
    } 
    else
    {
          unFlagFormField(document.form1.new_city);
    } 
    
    if (goodForm)  
    { 
        return true;
    }
    else
    {
        return false;
    }   
}

function ChangePassword(obj)
{
    if (document.form1.new_pass.disabled)
    {
        document.form1.new_pass.disabled = false;
        document.form1.new_pass2.disabled = false;
        
        document.form1.new_pass.style.background = "#ffffff";
        document.form1.new_pass2.style.background = "#ffffff";
        
        document.form1.new_pass.style.borderWidth = "1px";
        document.form1.new_pass2.style.borderWidth = "1px";
        
        document.form1.new_pass.style.borderStyle = "solid";
        document.form1.new_pass2.style.borderStyle = "solid";
        
        document.form1.new_pass.style.borderColor = "#a5acb2";
        document.form1.new_pass2.style.borderColor = "#a5acb2";
        
        document.form1.new_pass.style.height = "16px";
        document.form1.new_pass2.style.height = "16px";
        
        document.form1.upd_pass.value = 1;
        
        if (obj != "none")
        {
            obj.innerHTML = "Leave Password Unchanged";
        }
        
        document.form1.new_pass.focus();
    }
    else
    {
        document.form1.new_pass.disabled = true;
        document.form1.new_pass2.disabled = true;
        
        document.form1.new_pass.style.background = "#c2c3c4";
        document.form1.new_pass2.style.background = "#c2c3c4";
        
        document.form1.new_pass.value = '';
        document.form1.new_pass2.value = '';
        
        textCounter(document.form1.new_pass,document.form1.rem_new_pass,25);
	    textCounter(document.form1.new_pass2,document.form1.rem_new_pass2,25);
        
        document.form1.upd_pass.value = 0;
        
        if (obj != "none")
        {
            obj.innerHTML = "Change Password";
        }
    }
    
}

function textCounter(field,cntfield,maxlimit) 
{
    if (field.value.length > maxlimit) // if too long...trim it!
    {
       field.value = field.value.substring(0, maxlimit);
       cntfield.value = maxlimit - field.value.length;
    }
    // otherwise, update 'characters left' counter
    else 
       cntfield.value = maxlimit - field.value.length;
}

function flagFormField(formField)
{
	//formField.style["border"] = "1px solid red";
	formField.style["background"] = "#FFFCCB";
}

function unFlagFormField(formField)
{
	//formField.style["border"] = "1px solid #999";
	formField.style["background"] = "#FFFFFF";
}

function toggleLayer( whichLayer )
{
  var elem, vis;
  if( document.getElementById ) // this is the way the standards work
    elem = document.getElementById( whichLayer );
  else if( document.all ) // this is the way old msie versions work
      elem = document.all[whichLayer];
  else if( document.layers ) // this is the way nn4 works
    elem = document.layers[whichLayer];
  vis = elem.style;  // if the style.display value is blank we try to figure it out here

  if(vis.display==''&&elem.offsetWidth!=undefined&&elem.offsetHeight!=undefined)
    vis.display = (elem.offsetWidth!=0&&elem.offsetHeight!=0)?'block':'none';
  vis.display = (vis.display==''||vis.display=='block')?'none':'block';
}

/* -----------------------------------------------------------------------------------
         Formats the Credit Card Number with hyphens and 
         displays in the text box below  03/30/06
----------------------------------------------------------------------------------- */
function FormatCreditCardNum() {
//alert(document.form1.cc_number.value);
     var ilen = String(document.form1.cc_number.value).length ;
     if (ilen <= 4)
     { 
        document.form1.txtCreditCardNum1.value = document.form1.cc_number.value;
     }
     else 
     {
        if (ilen > 4 && ilen <= 8)
        {
            //alert(document.form1.cc_number.value);
            document.form1.txtCreditCardNum1.value = Mid(document.form1.cc_number.value,0,4) + " - " +
                            Mid(document.form1.cc_number.value,4,ilen);
        }
        else 
        {
            if (ilen > 8 && ilen <= 12)
            {
                document.form1.txtCreditCardNum1.value = Mid(document.form1.cc_number.value,0,4) + " - " +
                                      Mid(document.form1.cc_number.value,4,4) + " - " +
                                      Mid(document.form1.cc_number.value,8,ilen);
            }
            else                                                                  
            {
                document.form1.txtCreditCardNum1.value = Mid(document.form1.cc_number.value,0,4) + " - " +
                                      Mid(document.form1.cc_number.value,4,4) + " - " +
                                      Mid(document.form1.cc_number.value,8,4) + " - " +
                                      Mid(document.form1.cc_number.value,12,ilen);
            }
        }
    }                           
}

function Mid(str, start, len)
{
    // Make sure start and len are within proper bounds
    if (start < 0 || len < 0) return "";

    var iEnd, iLen = String(str).length;
    if (start + len > iLen)
            iEnd = iLen;
    else
            iEnd = start + len;

    return String(str).substring(start,iEnd);
}
             
function toggleLayer( whichLayer )
{
  var elem, vis;
  if( document.getElementById ) // this is the way the standards work
    elem = document.getElementById( whichLayer );
  else if( document.all ) // this is the way old msie versions work
      elem = document.all[whichLayer];
  else if( document.layers ) // this is the way nn4 works
    elem = document.layers[whichLayer];
  vis = elem.style;  // if the style.display value is blank we try to figure it out here

  if(vis.display==''&&elem.offsetWidth!=undefined&&elem.offsetHeight!=undefined)
    vis.display = (elem.offsetWidth!=0&&elem.offsetHeight!=0)?'block':'none';
  vis.display = (vis.display==''||vis.display=='block')?'none':'block';
}