﻿// 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 LoginDay()
{
    document.form1.action.value = "loginday";
    document.form1.submit(); 
}

function Logout()
{
    document.form1.action.value = "logout";
    document.form1.submit(); 
}

function SubmitLogin()
{
    if (window.event && window.event.keyCode == 13)
    {
        Login();
    }
}

function SubmitLoginDay()
{
    if (window.event && window.event.keyCode == 13)
    {
        LoginDay();
    }
}

function UpdatePage()
{
    document.form1.action.value = "updatepage";
    document.form1.submit(); 
}

function UpdateStore()
{
    document.form1.action.value = "updatestore";
    document.form1.submit(); 
}

function AddStore()
{
    document.form1.action.value = "addstore";
    document.form1.add_id.value = document.form1.stores.value;
    document.form1.submit(); 
}

function RemoveStore(storeID)
{
    document.form1.action.value = "removestore";
    document.form1.delete_id.value = storeID;
    document.form1.submit(); 
}

function AddPage()
{
    document.form1.action.value = "addpage";
    document.form1.add_id.value = document.form1.pages.value;
    document.form1.submit(); 
}

function RemovePage(pageID)
{
    document.form1.action.value = "removepage";
    document.form1.delete_id.value = pageID;
    document.form1.submit(); 
}

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 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';
}
