﻿function popup(mylink, windowname) {
    if (!window.focus) return true;
    var width = 900;
    var height = 700;
    var left = parseInt((screen.availWidth / 1.7) - (width / 2.3));
    var top = parseInt((screen.availHeight / 2) - (height / 2));
    var windowFeatures = "width=" + width + ",height=" + height + ",status=no,resizable=yes,scrollbars=yes,menubar=no,toolbar=no,left=" + left + ",top=" + top + "screenX=" + left + ",screenY=" + top + ""
    var href;
    if (typeof (mylink) == 'string')
        href = mylink;
    else
        href = mylink.href;
    window.open(href, windowname, windowFeatures);
    return false;
}

function popupPDFReport(mylink, windowname) {
    if (!window.focus) return true;
    var width = 800;
    var height = 700;
    var left = parseInt((screen.availWidth / 1.7) - (width / 2.3));
    var top = parseInt((screen.availHeight / 2) - (height / 2));
    var windowFeatures = "width=" + width + ",height=" + height + ",status=no,resizable=yes,scrollbars=yes,menubar=no,toolbar=no,left=" + left + ",top=" + top + "screenX=" + left + ",screenY=" + top + ""
    var href;
    if (typeof (mylink) == 'string')
        href = mylink;
    else
        href = mylink.href;
    window.open(href, windowname, windowFeatures);
    return false;
}

function popupEmailPage(mylink, windowname) {
    if (!window.focus) return true;
    var width = 450;
    var height = 130;
    var left = parseInt((screen.availWidth / 2) - (width / 2));
    var top = parseInt((screen.availHeight / 2) - (height / 2));
    var windowFeatures = "width=" + width + ",height=" + height + ",status=no,resizable=no,scrollbars=no,menubar=no,toolbar=no,left=" + left + ",top=" + top + "screenX=" + left + ",screenY=" + top + ""
    var href;
    if (typeof (mylink) == 'string')
        href = mylink;
    else
        href = mylink.href;
    window.open(href, windowname, windowFeatures);
    return false;
}

function popupNormalPage(mylink, windowname) {
    if (!window.focus) return true;
    var width = 900;
    var height = 700;
    var left = parseInt((screen.availWidth / 1.7) - (width / 2.3));
    var top = parseInt((screen.availHeight / 2) - (height / 2));
    var windowFeatures = "width=" + width + ",height=" + height + ",status=no,resizable=yes,scrollbars=yes,menubar=yes,toolbar=yes,left=" + left + ",top=" + top + "screenX=" + left + ",screenY=" + top + ""
    var href;
    if (typeof (mylink) == 'string')
        href = mylink;
    else
        href = mylink.href;
    window.open(href, windowname, windowFeatures);
    return false;
}

function ClientSideValidation() {
    var ddTypeRef = document.getElementById('ddType');
    if (ddTypeRef == null) {
        return false;
    }
    else {
        if (ddTypeRef.selectedIndex == 0) {
            alert('You must select a provider type in order to carry on search.');
            return false;
        }
        else {
            return true;
        }
    }
}



//-------------------------------------------------------------------------------
//For user move mouse on the gridview row 
var oldgridSelectedColor;

function setMouseOverColor(element) {
    oldgridSelectedColor = element.style.backgroundColor;
    element.style.backgroundColor = '#FFCC66';
    element.style.cursor = 'hand';
    element.style.textDecoration = 'underline';
}

function setMouseOutColor(element) {
    element.style.backgroundColor = oldgridSelectedColor;
    element.style.textDecoration = 'none';
}

function refreshPage() {
    alert("ok");
    //location.reload(true);
}

function cleanWarningMessage() {
//    alert("PPPPPP");
//    var labelText = document.getElementById("lbWarningMsg");
//    if (labelText != null) {
//        labelText.innerText = '';
//    }

    document.getElementById("lbWarningMsg").innerText = '';

}

// Validate the USA Zip code, must be 5 number 
function control_onkeyup(ctl)
{
    var ctlRef;
    var allowedChars = '0123456789';var blnNotNumber = new Boolean(0);
    ctlRef = document.getElementById(ctl);
    if (ctlRef!=null)
       {
       if (ctlRef.value.length>0) 
           {
           var ascii_value;
           var indx=0;
           for (indx=0;indx<ctlRef.value.length;indx++)
               {
               ascii_value=ctlRef.value.charAt(indx);
               if (allowedChars.indexOf(ascii_value)==-1)
                   {
                   alert('Only number is allowed!');
                   blnNotNumber = true;
                   break;
                   }
               }
           if (blnNotNumber==true)
               {
               var correctedValue = '';
               var i=0;
               for (i=0;i<ctlRef.value.length;i++)
                   {
                   ascii_value=ctlRef.value.charAt(i);
                   if (allowedChars.indexOf(ascii_value)>-1) 
                       correctedValue = correctedValue + ctlRef.value.charAt(i);
                   }
               ctlRef.value = correctedValue;
               }
           }
       }

}

function validateUserInput() {
    var retValue = true;
    var strErrorMsg = "";
    var tbxZip = document.getElementById("tbxUSAZip");
    if (tbxZip != null) {
        if (tbxZip.value == "") {
            strErrorMsg = "ZIP Code is required field";
            retValue = false;

        }
        else if (tbxZip.value.length < 5) {
            strErrorMsg = "ZIP Code must be a 5 digits number.";
            retValue = false;
        }
    }
    if (retValue == false )
    {
        alert(strErrorMsg);
    }
    return retValue;
}

// Clean Email Box error message when user re-click textbox 
function cleanErrorMessage() {
    var lbErrorMsg = document.getElementById("lbWarningMessage");
    //alert(lbErrorMsg.innerText);
    lbErrorMsg.innerText = "";
    return true;
}

