﻿// JScript File

    function setCorner()
    {
//        $find('RoundedCornersBehavior1').setCorner(2, false);
//        $find('RoundedCornersBehavior1').setCorner(4, false);
    }

    function EmailFieldKeyDown(e)
    {
        var ev = GetEvent(e);
        if( ev != null )
        {
            var keycode = ev.keyCode?ev.keyCode:ev.which?ev.which:ev.charCode;

            if(keycode==13)
            {
                
                if(Browser["isNS"] || Browser["isFF"]){
                    ev.preventDefault();
                    var PasswordField=document.getElementById("ctl00_ContentPlaceHolder_Password");
                    PasswordField.focus();
                }
                else if(Browser["isIE"]){
                    ev.keyCode = 9;
                }
            }
            
        }
    }
    
    function PasswordFieldKeyDown(e)
    {

        var ev = GetEvent(e);
        if( ev != null )
        {
            var keycode = ev.keyCode?ev.keyCode:ev.which?ev.which:ev.charCode;

            if(keycode==13)
            {                
                if(Browser["isNS"] || Browser["isFF"]){
                    ev.preventDefault();
                    var ButtonField=document.getElementById("ctl00_ContentPlaceHolder_btSignIn");
                    ButtonField.focus();
                }
                else if(Browser["isIE"]){
                    ev.keyCode = 9;
                }
                __doPostBack('ctl00$ContentPlaceHolder$btSignIn','');
            }
            
        }
    }

    function EmailFieldKeyDown1(e)
    {
        var ev = GetEvent(e);
        if( ev != null )
        {
            var keycode = ev.keyCode?ev.keyCode:ev.which?ev.which:ev.charCode;

            if(keycode==13)
            {
                
                if(Browser["isNS"] || Browser["isFF"]){
                    ev.preventDefault();
                    var PasswordField=document.getElementById("ctl00_Header_Password");
                    PasswordField.focus();
                }
                else if(Browser["isIE"]){
                    ev.keyCode = 9;
                }
            }
            
        }
    }
    
    function PasswordFieldKeyDown1(e)
    {

        var ev = GetEvent(e);
        if( ev != null )
        {
            var keycode = ev.keyCode?ev.keyCode:ev.which?ev.which:ev.charCode;

            if(keycode==13)
            {                
                if(Browser["isNS"] || Browser["isFF"]){
                    ev.preventDefault();
                    var ButtonField=document.getElementById("ctl00_Header_btSignIn");
                    ButtonField.focus();
                }
                else if(Browser["isIE"]){
                    ev.keyCode = 9;
                }
                __doPostBack('ctl00$Header$btSignIn','');
            }
            
        }
    }
    
        function SearchAddressFieldKeyDown(e)
        {
            var ev = GetEvent(e);
            if( ev != null )
            {
                var keycode = ev.keyCode?ev.keyCode:ev.which?ev.which:ev.charCode;

                if(keycode==13)
                {                
                    if(Browser["isNS"] || Browser["isFF"]){
                        ev.preventDefault();
                        var ButtonField=document.getElementById("ctl00_Header_btSearch");
                        ButtonField.focus();
                    }
                    else if(Browser["isIE"]){
                        ev.keyCode = 9;
                    }
                    __doPostBack('ctl00$Header$btSearch','');
                }                
            }
        }
    
function openWin(u)
{
	window.open(u,"","toolbar=0,top=50,left=130,location=0,status=0,menubar=0,scrollbars=1,resizable=1,height=550,width=650");
}

function openWin1(u)
{
	window.open(u,"","toolbar=0,top=50,left=130,location=0,status=0,menubar=0,scrollbars=1,resizable=0,height=600,width=800");
}

var Browser = { 
'isIE' : (navigator.userAgent.indexOf('MSIE') >= 0) && (navigator.userAgent.indexOf('Opera') < 0), 
'isFF' : navigator.userAgent.indexOf('Firefox') >= 0, 
'isOP' : navigator.userAgent.indexOf('Opera') >= 0, 
'isNS' : navigator.userAgent.indexOf('Netscape') >= 0
}; 

    function GetEvent(e){
        var ev = null;
        if(Browser["isNS"] || Browser["isFF"] || Browser["isOP"]){
            ev = e;
        }
        else if(Browser["isIE"]){
            ev = window.event;
        }
        return ev;
    }
    

function ChkSession()
{
    GetQuikService.ChkSession(OnCompleteChkSession);
}

function OnCompleteChkSession(result)
{
    if(result == "" )
    {
        window.setTimeout('ChkSession()', 30000 );
    }
    else
    {
        alert("Time out, please sign in again.");
        location.href = "/Pages/Common/SignIn.aspx";
    }
    
}

//Google Map for search
var icon;
var icon1;

if(typeof(GIcon)=="function") 
{
icon1 = new GIcon();
icon1.image = "/Common/Images/Start01.gif";
icon1.shadow = "/Common/Images/Start01Shandow.gif";
icon1.iconSize = new GSize(24, 24);
icon1.shadowSize = new GSize(30, 24);
icon1.iconAnchor = new GPoint(6, 20);
icon1.infoWindowAnchor = new GPoint(5, 1);

icon = new GIcon();
icon.image = "/Common/Images/redIcon.gif";
icon.shadow = "/Common/Images/redIconShadow.gif";
icon.iconSize = new GSize(16, 26);
icon.shadowSize = new GSize(24, 26);
icon.iconAnchor = new GPoint(6, 20);
icon.infoWindowAnchor = new GPoint(5, 1);


icon2 = new GIcon();
icon2.image = "/Common/Images/mm_20_red.png";
icon2.shadow = "/Common/Images/mm_20_shadow.png";
icon2.iconSize = new GSize(24, 24);
icon2.shadowSize = new GSize(30, 24);
icon2.iconAnchor = new GPoint(6, 20);
icon2.infoWindowAnchor = new GPoint(5, 1);
}

function LoadMap() {
      if (typeof(GBrowserIsCompatible)!="undefined" && GBrowserIsCompatible() && typeof(ShowMap)=="function") {
        ShowMap();
      }
}

function ShowWindowInfo(sMerchantId, eml) {
    if( markers.containsKey(sMerchantId) )
    {
        var marker = markers.get(sMerchantId);
        marker.openInfoWindowHtml(eml.attributes["info"].nodeValue);
        marker.setImage("/Common/Images/JumpingBall_blue.gif");
    }
}

//var map;
function CloseWindowInfo(sMerchantId) {
    if( markers.containsKey(sMerchantId) )
    {
        var marker = markers.get(sMerchantId);
        marker.closeInfoWindow();
        marker.setImage("/Common/Images/redIcon.gif");
    }
}

var markers = new Hashtable();
function CreateMarker(point, desc, title, ico) {
  var marker = new GMarker(point, ico);
  
  
  GEvent.addListener(marker, "click", function() {
    marker.openInfoWindowHtml(desc);
  });
  
  GEvent.addListener(marker, "mouseover", function() {
     var monitor = $get("map_monitor");
     if( monitor != null ) monitor.innerHTML = title;
  });
  GEvent.addListener(marker, "mouseout", function() {
     var monitor = $get("map_monitor");
     if( monitor != null ) monitor.innerHTML = "<font color='#888888'>Left click any mark to show restaurant name and address.</font>";
     //if( monitor != null ) monitor.innerHTML = "<font color='#888888'>Put mouse on icon, left click to show the merchant description, and right click to show the satellite map.</font>";
  });
  return marker;
}

function getEvent(){     //同时兼容ie和ff的写法  
       if(document.all)    return window.event;          
       func=getEvent.caller;              
       while(func!=null){      
           var arg0=func.arguments[0];  
           if(arg0){  
               if((arg0.constructor==Event || arg0.constructor ==MouseEvent)  
                   || (typeof(arg0)=="object" && arg0.preventDefault && arg0.stopPropagation)){      
                   return arg0;  
               }  
           }  
           func=func.caller;  
       }  
      return null;  
} 


function Hashtable(){
    this.clear = hashtable_clear;
    this.containsKey = hashtable_containsKey;
    this.containsValue = hashtable_containsValue;
    this.get = hashtable_get;
    this.isEmpty = hashtable_isEmpty;
    this.keys = hashtable_keys;
    this.put = hashtable_put;
    this.remove = hashtable_remove;
    this.size = hashtable_size;
    this.toString = hashtable_toString;
    this.values = hashtable_values;
    this.hashtable = new Array();
}

function hashtable_clear(){
    this.hashtable = new Array();
}

function hashtable_containsKey(key){
    var exists = false;
    for (var i in this.hashtable) {
        if (i == key && this.hashtable[i] != null) {
            exists = true;
            break;
        }
    }
    return exists;
}

function hashtable_containsValue(value){
    var contains = false;
    if (value != null) {
        for (var i in this.hashtable) {
            if (this.hashtable[i] == value) {
                contains = true;
                break;
            }
        }
    }
    return contains;
}

function hashtable_get(key){
    return this.hashtable[key];
}

function hashtable_isEmpty(){
    return (this.size == 0) ? true : false;
}
function hashtable_keys(){
    var keys = new Array();
    for (var i in this.hashtable) {
        if (this.hashtable[i] != null)
        keys.push(i);
    }
    return keys;
}

function hashtable_put(key, value){
    if (key == null || value == null) {
        throw 'NullPointerException {' + key + '},{' + value + '}';
        }else{
        this.hashtable[key] = value;
    }
}

function hashtable_remove(key){
    var rtn = this.hashtable[key];
    //this.hashtable[key] =null;
    this.hashtable.splice(key,1);
    return rtn;
}

function hashtable_size(){
    var size = 0;
    for (var i in this.hashtable) {
        if (this.hashtable[i] != null)
        size ++;
    }
    return size;
}

function hashtable_toString(){
    var result = '';
    for (var i in this.hashtable)
    {
        if (this.hashtable[i] != null)
        result += '{' + i + '},{' + this.hashtable[i] + '}\n';
    }
    return result;
}

function hashtable_values(){
    var values = new Array();
    for (var i in this.hashtable) {
        if (this.hashtable[i] != null)
        values.push(this.hashtable[i]);
    }
    return values;
} 


function HideAndShow(hideElmId, showElmId){
    var showElm = $get(showElmId);
    var hideElm = $get(hideElmId);
    
    if(showElm) {
        showElm.style.display='';
        showElm.style.visibility='visible';
    }
    
    if(hideElm) {
        hideElm.style.display='none';
        hideElm.style.visibility='hidden';
    }
} 