function validateNewsletterForm()
{
   //------------------------------------------------------------------- 
   // Validates the email item form for null values and email address 
   // format. Alert the user if the email address is invalid.
   //    returns true if the email address field validates, else false.
   //-------------------------------------------------------------------

   var objForm = document.newsletterForm;

   if (!isValidEmail(objForm.email.value)) {
       objForm.email.focus();
       alert ("You have entered an invalid Email Address.");
       return false;
   }


   return true;
}

function validateEmailItemForm()
{
   //------------------------------------------------------------------- 
   // Validates the email item form for null values and email address 
   // format. Alert the user if the email address is invalid.
   //    returns true if the email address field validates, else false.
   //-------------------------------------------------------------------

   var objForm = document.itemForm;
   var errorArray = new Array ("none","none","none","none");

   if (!isEmptyFields(objForm.sender_name))
       errorArray[0] = "block";

   if (!isValidEmail(objForm.sender_email.value))
       errorArray[1] = "block";

   if (!objForm.disable.checked) {
       if (!isEmptyFields(objForm.receipt_name))
           errorArray[2] = "block";

       if (!isValidEmail(objForm.receipt_email.value))
           errorArray[3] = "block";
   }

   var str = errorArray.join("");
   if (str.indexOf('block') != -1)
       return displayErrorBox (errorArray);

   return true;
}

function validateFeedbackForm()
{
   //------------------------------------------------------------------- 
   // Validates the feedback email form for null values and email address 
   // format. Alert the user if the email address is invalid.
   //    returns true if the email address field validates, else false.
   //-------------------------------------------------------------------

   var objForm = document.feedbackForm;
   var errorArray = new Array ("none","none");

   if (!isEmptyFields(objForm.sender_name))
       errorArray[0] = "block";

   if (!isValidEmail(objForm.sender_email.value))
       errorArray[1] = "block";

   var str = errorArray.join("");
   if (str.indexOf('block') != -1)
       return displayErrorBox (errorArray);

   return true;
}

function validateEmailContactForm()
{
   //------------------------------------------------------------------- 
   // Validates the contact email form for null values and email address 
   // format. Alert the user if the email address is invalid.
   //    returns true if the email address field validates, else false.
   //-------------------------------------------------------------------

   var objForm = document.contactForm;
   var errorArray = new Array ("none","none");

   if (!isEmptyFields(objForm.sender_name))
       errorArray[0] = "block";

   if (!isValidEmail(objForm.sender_email.value))
       errorArray[1] = "block";

   var str = errorArray.join("");
   if (str.indexOf('block') != -1)
       return displayErrorBox (errorArray);

   return true;
}

function displayErrorBox (errArray)
{
   //-------------------------------------------------------------------
   // When an invalid data has been entered, display the error box.
   //-------------------------------------------------------------------

   document.getElementById('errorBox').style.display = 'block';
   for (var i=1; i <= errArray.length; i++)
       document.getElementById('error_0'+i).style.display = errArray[i-1];

   return false;
}

function toggleFormFields (isCheckedEmail)
{
   //-------------------------------------------------------------------
   // Display (or hide) form fields when user toggles the checkbox.
   // If the checkbox is checked, the form field collapses and hides the other form fields.
   //-------------------------------------------------------------------
   if (isCheckedEmail) {
       document.getElementById('table_row1').style.display = 'none';
       document.getElementById('table_row2').style.display = 'none';
   }
   else
   {
       if (!window.opera) {
           document.getElementById('table_row1').style.display = 'block';
           document.getElementById('table_row2').style.display = 'block';
       }
       else {
           document.getElementById('table_row1').style.display = 'table-row';
           document.getElementById('table_row2').style.display = 'table-row';
       }
   }
}

function isValidEmail (emailAddress)
{
   //-------------------------------------------------------------------
   //    returns true if the emailAddress value is in valid format. Else false.
   //-------------------------------------------------------------------

   var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/

   return re.test(emailAddress);
}

function isEmptyFields(object)
{
   //-------------------------------------------------------------------
   // We need to verify that all the fields are not empty null.  
   // Alert the user if a particular form field is empty or null.
   //    returns true if the quantity field validates, else false.
   //-------------------------------------------------------------------   

   if (object.value.length == 0)
       return false;

   return true;
}

function isZipCode(num)
{
   //-------------------------------------------------------------------
   //    returns true if value is a number
   //-------------------------------------------------------------------

   // We now need to test for 5 digit zipcode.
   var regNum = /^\d{5}$/;
   if (regNum.test(num))
       return true;

   return false;
}


function xmlHttpRequest_init()
{
    var oXMLHTTP=false;
    /*@cc_on @*/
    /*@if (@_jscript_version >= 5)
    // JScript gives us Conditional compilation, we can cope with old IE versions.
    // and security blocked creation of the objects.
    try {
        oXMLHTTP = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
        try {
            oXMLHTTP = new ActiveXObject("Microsoft.XMLHTTP");
        } catch (e) {
            oXMLHTTP = false;
        }
    }
    @end @*/
    
    // For Mozilla browsers
    if (!oXMLHTTP && typeof XMLHttpRequest!='undefined') {
        oXMLHTTP = new XMLHttpRequest();
    }
    
    return oXMLHTTP;
}

function processOrderStatus(id)
{
    var oXMLHTTP = xmlHttpRequest_init();
    
    if (oXMLHTTP) {
        //-------------------------------------------------------------------
        // Prepare the XMLHTTP object for a HTTP POST to our validation ASP page
        // Due to security reason, the domain of the URL request destination must be 
        // the same as the one that serves up the page containing the script.
        //-------------------------------------------------------------------
        var sURL = location.protocol + "//" + location.hostname + "?id=" + id;
        oXMLHTTP.open("GET", sURL, true);
        
        //-------------------------------------------------------------------
        // With IE browser, data are being cached in the client's system. 
        // Changing the header would allow the application to reset.
        //-------------------------------------------------------------------
        oXMLHTTP.setRequestHeader('If-Modified-Since','Mon, 20 Nov 1995 00:00:01 GMT');
        
        // Execute the request
        oXMLHTTP.send(null);
        
        // Determine the state change status
        oXMLHTTP.onreadystatechange=function() {
            if (oXMLHTTP.readyState==4 && oXMLHTTP.status == 200) {
                // alert (oXMLHTTP.responseText);
                document.getElementById("").innerHTML = oXMLHTTP.responseText;
            }
        }
    }
    //else {
        // For users with browsers that don't support XMLHttpRequest Object
    //    document.form.action=document..referer.value;
    //    document.form.submit();
    //}
}

function imagePopup() {
    window.open( "/images/popimage.php", "image", "height=380, width=380, resizable=0, status=0, toolbar=0, scrollbars=1" );
}