﻿function handleErrors() { return true;}
//window.onerror = handleErrors;

function closeWindow(id)
{
    jQuery('#clubankMessage_window').modalWindowClose(true);
}
function showWindow(id,url,w,h,title)
{
      __showModalWindow(url,w,h,title);
      if (title){
        jQuery("#clubankMessage_title").html(title);
      }
      
      return;
}
function __showModalWindow(url,w,h)
{
    __iniMesasge(url,true);
    __showClubankWindow(w,h);
    jQuery('#clubankMessage_content').attr("src",url);
    
     function  completeLoad()   
     {   
         if(document.all.clubankMessage_content.readyState=="complete") 
         {
             jQuery('#clubankMessage_window').unblock();
             //document.all.clubankMessage_content.focus();
         } 
     } 
     try{  
        if (document.all.clubankMessage_content){
            jQuery('#clubankMessage_window').block('<h2 >Please wait...</h2>');
            document.all.clubankMessage_content.onreadystatechange   =   completeLoad; 
        }
    }
    catch(e){
        jQuery('#clubankMessage_window').unblock();
    }
}

function __showClubankWindow(w,h)
{
     var question = jQuery('#clubankMessage_window'); 
     jQuery("#clubankMessage_table_content").css("height",h);
	
	jQuery('#clubankMessage_window').width(w);
	jQuery('#clubankMessage_window').height(h);
	
	question.clubankModalWindow({center:true});
	
//	jQuery("#clubankMessage_window").Draggable(
//			{
////			    ghosting:	true,
////				opacity:	0.5,
////				fx:			300
//			});
}

function __iniMesasge(msgStr,iframe,w,h)
{
        if(!jQuery('#clubankMessage_window'))
            jQuery('#clubankMessage_window').modalWindowClose();
        var tableStr = "<table class='table_window' id='clubankMessage_row1' >";
//        //标题头
        tableStr = tableStr + "<tr>";
        tableStr = tableStr + "<td class='spread_nw'  ></td>";
        tableStr = tableStr + " <td class='spread_n' >";
        tableStr = tableStr + "<div class='spread_title title_window' id='clubankMessage_title'  >";
        tableStr = tableStr + "温馨提示</div></td>";
        tableStr = tableStr + "<td class='spread_ne'></td></tr>";
        tableStr = tableStr + "</table>";

        //内容区               
        tableStr = tableStr + "<table class='table_window' id='clubankMessage_row2' >";
        tableStr = tableStr + "<tr><td class='spread_w'></td>";
        tableStr = tableStr + "<td class='spread_content' id='clubankMessage_table_content'  >";
        
        if (iframe){ //iframe
            tableStr = tableStr + "<iframe id='clubankMessage_content' width='100%' height='100%' style='overflow: visible;' name='clubankMessage_content' src='' frameborder='0'  ></iframe>";
        }
        else{ //inline
            tableStr = tableStr + msgStr;
        }
        
        tableStr = tableStr + "</td><td class='spread_e'></td></tr>";
        tableStr = tableStr + "</table>";
        
        //底部区域--可扩展为拖动
        tableStr = tableStr + "<table class='table_window' id='clubankMessage_row3' >";
        tableStr = tableStr + "<tr><td class='spread_sw'></td><td class='spread_s ' >";
        tableStr = tableStr + "<div class='status_bar' id='clubankMessage_bottom'  >";
        tableStr = tableStr + "<span style='float: left; width: 1px; height: 12px'></span>"
        tableStr = tableStr + "</div></td><td class='spread_se'></td></tr>";
        tableStr = tableStr + "</table>";
        
        var $Msg = jQuery("<div id='clubankMessage_window' class='clubank_window' style='display:none; cursor: default;position:absolute;'> ");
        jQuery("body").append($Msg);

        //关闭按钮        
        var closebutton = "<div class='spread_close' id='clubankMessage_close' />";
        $Msg.append(jQuery(closebutton));
        
        $Msg.append(jQuery(tableStr));
}

//function callRegister(url)
//{
//    window.location = "/Client/RegisterClient.aspx?gotoUrl="+url;
//}

function showMessage(key)
{
     jQuery.ajax({
        url: '/Common/GetMessage.aspx?key=' + key,
        type: 'GET',
        dataType: 'html',
        timeout: 1000,
        error: function(){
            alert('error loading data');
        },
        success: function(data){
            showPopup(data);
        }
    });
}


function showOrderComment(key)
{
     jQuery.ajax({
        url: '/Booking/OrderComment.aspx?key=' + key,
        type: 'GET',
        dataType: 'html',
        timeout: 1000,
        error: function(){
            alert('error loading data');
        },
        success: function(data){
            showPopup(data);
        }
    });
}
 
 /*
var timeInv = 1000*60;
var timerID = 0 ; 

function keepSession(tips)
{
    if (tips != "1")
	{
		top.location = top.location;
		return;
	}
	timerID = window.setTimeout("keepSessionData()",timeInv);
}
function onFailedKeepSession()
{
     keepSession("Error");
}
function keepSessionData()
{
    GolfBooking.Web.Common.CommonService.KeepClubankSession("Session",keepSession,onFailedKeepSession);
}

*/
function showPopup(msg)
{
    if (msg == null)
    {
        msg = _$lastMessage;
    }
    __iniMesasge(msg);
    __showClubankWindow(330,200);
}
        
function doNothing() {   return false;}

document.ns = navigator.appName == "Microsoft Internet Explorer";
if(document.ns) 
{
    var oColl = document.all.tags("Select");
    var i = oColl.length-1;
    for(i; i >= 0 ; i--)
    {
        var oObj = oColl[i];
        if(!oObj.onmousewheel)
        {
            oObj.onmousewheel = doNothing;
        }
    }
}


 function gotoManager()
  {
    window.location = "/TeeTime/ClientBookingList.aspx?OrderType=04";
}
function callbackClientToolbox()
{
    top.location =  window.location ;
}

//function sysCheckLogon(url)
//{
//    //var url = "/TeeTime/GolfBookingMain.aspx";
//    //var teeTimeUrl = "/Client/OpenLogin.aspx?javaScript=callbackClientToolbox3&Url=" + url;
//    
//    var teeTimeUrl = "/Client/OpenLogin.aspx?" +  url;
//    showWindow("OpenLogin",teeTimeUrl,220,145,"请登录");
//    
//}


var __needOpenLogon = true;

//function openLogon()
//{
//   if (!__needOpenLogon) return
//   var teeTimeUrl = "/Client/OpenLogin.aspx?javaScript=callbackClientToolbox";
//   showWindow("OpenLogin",teeTimeUrl,220,145,"请登录");
//   __needOpenLogon = false;
//}

//function openInviteFriend()
//{
//   var teeTimeUrl = "/Client/InviteFriend.aspx";
//   showWindow("OpenInviteFriend",teeTimeUrl,360,230);
//  // win = new Window( { id:"OpenLogin",className: 'mac_os_x', url: teeTimeUrl, width:400,height:300, destroyOnClose: true, recenterAuto:false } ); 
//  // win.showCenter(true);
//}


//function register()
//{
//    top.location = "/Client/RegisterClient.aspx";
//}

//function logout()
//{
//    top.location = "/Client/AjaxUserManager.aspx?key=logout";
//    
//   
//}


// 计算两个日期的间隔天数  
function DateDiff(sDate1, sDate2){ //sDate1和sDate2是2002-12-18格式 
    if (checkIsValidDate(sDate1)) return 0;
  
    var aDate, oDate1, oDate2, iDays   
    aDate = sDate1.split("-")   
    oDate1 = new Date(aDate[1] + '-' + aDate[2] + '-' + aDate[0]) //转换为12-18-2002格式    
    aDate = sDate2.split("-")   
    oDate2 = new Date(aDate[1] + '-' + aDate[2] + '-' + aDate[0])   
    iDays = parseInt(Math.abs(oDate1 - oDate2) / 1000 / 60 / 60 /24) //把相差的毫秒数转换为天数   
    return iDays   
} 
//current Add int days 
function string2Date(sDate1){ //sDate1 = 2007-12-06
    if (checkIsValidDate(sDate1)) return new Date();
    var aDate= new Array()
    var newDate  
    aDate = sDate1.split("-")  
   
    newDate = new Date(aDate[0],aDate[1] - 1,aDate[2],0,0,0);
    return newDate;
}

//current Add int days 
function DateAddDays(sDate1, days){ //sDate1 = 2007-12-06
    if (checkIsValidDate(sDate1)) return "";
    var newDate  
    newDate = string2Date(sDate1);

    var tempdays = newDate.getDate();
    tempdays = tempdays + days;
    var ss = newDate.setDate(tempdays);
       
    var month = newDate.getMonth() + 1;
    if (month < 10) month = "0" + month;
    var rtn =newDate.getYear()+"-" + month + "-" + newDate.getDate();
    return rtn
} 
/**
*校验字符串是否为日期型
*返回值：
*如果为空，定义校验通过，           返回true
*如果字串为日期型，校验通过，       返回true
*如果日期不合法，                   返回false    参考提示信息：输入域的时间不合法！（yyyy-MM-dd）
*/
function checkIsValidDate(str)
{
    //如果为空，则通过校验
    if(str == "")
        return true;
    var pattern = /^((\\d{4})|(\\d{2}))-(\\d{1,2})-(\\d{1,2})$/g;
    if(!pattern.test(str))
        return false;
    var arrDate = str.split("-");
    if(parseInt(arrDate[0],10) < 100)
        arrDate[0] = 2000 + parseInt(arrDate[0],10) + "";
    var date =  new Date(arrDate[0],(parseInt(arrDate[1],10) -1)+"",arrDate[2]);
    if(date.getYear() == arrDate[0]
       && date.getMonth() == (parseInt(arrDate[1],10) -1)+""
       && date.getDate() == arrDate[2])
        return true;
    else
        return false;
}
/**
*校验两个日期的先后
*返回值：
*如果其中有一个日期为空，校验通过,          返回true
*如果起始日期早于等于终止日期，校验通过，   返回true
*如果起始日期晚于终止日期，                 返回false    参考提示信息： 起始日期不能晚于结束日期。
*/
function checkDateEarlier(strStart,strEnd)
{
    if(checkIsValidDate(strStart) == false || checkIsValidDate(strEnd) == false)
        return false;
    //如果有一个输入为空，则通过检验
    if (( strStart == "" ) || ( strEnd == "" ))
        return true;
    var arr1 = strStart.split("-");
    var arr2 = strEnd.split("-");
    var date1 = new Date(arr1[0],parseInt(arr1[1].replace(/^0/,""),10) - 1,arr1[2]);
    var date2 = new Date(arr2[0],parseInt(arr2[1].replace(/^0/,""),10) - 1,arr2[2]);
    if(arr1[1].length == 1)
        arr1[1] = "0" + arr1[1];
    if(arr1[2].length == 1)
        arr1[2] = "0" + arr1[2];
    if(arr2[1].length == 1)
        arr2[1] = "0" + arr2[1];
    if(arr2[2].length == 1)
        arr2[2]="0" + arr2[2];
    var d1 = arr1[0] + arr1[1] + arr1[2];
    var d2 = arr2[0] + arr2[1] + arr2[2];
    if(parseInt(d1,10) > parseInt(d2,10))
       return false;
    else
       return true;
}


//显示提示层
function showhintinfo(obj, objleftoffset,objtopoffset, title, info , objheight, showtype ,objtopfirefoxoffset)
{
   var p = getposition(obj);
   
   if((showtype==null)||(showtype =="")) 
   {
       showtype =="up";
   }
   document.getElementById('hintiframe'+showtype).style.height= objheight + "px";
   document.getElementById('hintinfo'+showtype).innerHTML = info;
   document.getElementById('hintdiv'+showtype).style.display='block';
   
   if(objtopfirefoxoffset != null && objtopfirefoxoffset !=0 && !isie())
   {
        document.getElementById('hintdiv'+showtype).style.top=p['y']+parseInt(objtopfirefoxoffset)+"px";
   }
   else
   {
        if(objtopoffset == 0)
        { 
			if(showtype=="up")
			{
				 document.getElementById('hintdiv'+showtype).style.top=p['y']-document.getElementById('hintinfo'+showtype).offsetHeight-40+"px";
			}
			else
			{
				 document.getElementById('hintdiv'+showtype).style.top=p['y']+obj.offsetHeight+5+"px";
			}
        }
        else
        {
			document.getElementById('hintdiv'+showtype).style.top=p['y']+objtopoffset+"px";
        }
   }
   document.getElementById('hintdiv'+showtype).style.left=p['x']+objleftoffset+"px";
}



//隐藏提示层
function hidehintinfo()
{
    document.getElementById('hintdivup').style.display='none';
    document.getElementById('hintdivdown').style.display='none';
}

function getposition(obj)
{
	var r = new Array();
	r['x'] = obj.offsetLeft;
	r['y'] = obj.offsetTop;
	while(obj = obj.offsetParent)
	{
		r['x'] += obj.offsetLeft;
		r['y'] += obj.offsetTop;
	}
	return r;
}