﻿/*
 * mobile.js
 * author: Joel Stevick
 * date: 8.31.10
 * Copyright (c) 2010, CorData, Inc
 * Program Name: C.H.I.P. - CorData Hierarchical Inference Program
 */
function DoMobileProcessing() {
    /*
    * If this is not a mobile device, just return: nothing to do
    */
    if (!((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i)) || (navigator.userAgent.match(/iPad/i)))) {
        return;
    }

    /*
    * Turn on the mobile notifications
    */
    var mobile1 = document.getElementById('mobile1');
    if (mobile1 && ScrollingRequired(document.getElementById('messageBodyContentClip'))) {
        mobile1.style.display = 'block';
    }

    var mobile2 = document.getElementById('mobile2');
    if (mobile2 && ScrollingRequired(document.getElementById('answersdiv')))
        mobile2.style.display = 'block';

}

/*
 * Determine whether scrolling is required
 */
function ScrollingRequired(div) {

    var scrollHeight = div.scrollHeight;
    return parseInt(scrollHeight) > parseInt(div.clientHeight);
}

/*
 * Hide the mobile notifications, and raise the one for the profile panel
 */
function ProfilePanelMobileNotification(visible) {
  /*
   * Normal ones
   */
    if (visible) {
        /*
         * The profile is visible, so hide the others
         */
        document.getElementById('mobile1').style.display = "none";
        document.getElementById('mobile2').style.display = "none";
    } else {
    
       /*
        * Hiding the profile, so determine whether the others should be made visible
        */
        parent.DoMobileProcessing();
    }
  
  /*
  * Process the notification related to the profile
  */
    if (visible) {
        document.getElementById('mobileProfile').style.display = visible ? "block" : "none";
    } else {
        parent.document.getElementById('mobileProfile').style.display = visible ? "block" : "none";
    }
}

/*
 * Check for mobile device and prevent developer tool
 */
function DeveloperPortalMobileCheck() {
    /*
    * If this is not a mobile device, just return: nothing to do
    */
    if (!isMobile()) {
        return;
    }
    
    /*
     * This is a mobile device - disallow the developer portal
     */
    window.location.href = 'mobile_nodeveloperportal.html';
}

/*
 * Is this a mobile device?
 */
function isMobile() {
    if (!((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i)) || (navigator.userAgent.match(/iPad/i)))) {
        return false;
    } else {
        return true;
    }
}
