﻿var popUp; 

// 母版ID名称改变 优先
function x( id ) {
	var ctl = document.getElementById( id + '_ID' );
	if ( ctl )
	  ctl = document.getElementById( ctl.value );
	else
	  ctl = document.getElementById( id );
	  
	return ctl;	
}

/*		
function String.prototype.Trim() {
	return this.replace(/(^\s*)|(\s*$)/g, "");
}*/

function setFocus( id ) {
	var ctl  = document.getElementById( id );
	if ( ctl != null ) {
		ctl.focus();
		ctl.select();
	}
}

function parseDurDate( dur ) {
	var rc = null;

	if ( !dur )
		return null;

	try {
  	var start = "0101";
  	var end   = "1231";
  	if ( dur.indexOf('-') != -1 || dur.indexOf('') != -1 ) {
  		var reg = /(\d+)\s*[-]/g.exec(dur); 
			if ( reg )
				start = reg[1];
		  
			reg = /[-]\s*(\d+)/g.exec(dur); 
			if ( reg) {
				end   = reg[1];
			}
		}
		else {
  		var reg = /(\d+)/g.exec(dur); 
			if ( reg ) {
  			start = reg[1];
  			end   = reg[1];
			}
		}
		
		var now = new Date();
		if ( start.toString().length == 4 )
			start = now.getFullYear() + '-' + start.substr(0,2) + '-' + start.substr(2,2);
		else if ( start.toString().length == 6 )
			start = now.getFullYear().toString().substr(0,2) + start.substr(0,2) + '-' + start.substr(2,2) + '-' + start.substr(4,2);
		
		if ( end.toString().length == 4 )
			end = now.getFullYear() + '-' + end.substr(0,2) + '-' + end.substr(2,2);
		else if ( end.toString().length == 6 )
			end = now.getFullYear().toString().substr(0,2) + end.substr(0,2) + '-' + end.substr(2,2) + '-' + end.substr(4,2);
		
		if ( start && end ) {
			var tStart = new Date( eval(start.substr(0,4)), eval(start.substr(5,2))-1, eval(start.substr(8,2)) );
			var tEnd   = new Date( eval(end.substr(0,4)), eval(end.substr(5,2))-1, eval(end.substr(8,2)) );
			if ( tStart.getTime() > tEnd.getTime() )  {
				if ( now.getMonth() >= 5 )
					end = tEnd.getFullYear() + 1 + '-' + (tEnd.getMonth() + 1) + '-' + tEnd.getDate();
				else
					start = tStart.getFullYear() - 1 + '-' + (tStart.getMonth() + 1) + '-' + tStart.getDate();
			}
		}
		
		rc ={
			"start": start,
			"end": end
		};
	}		
	catch(e) { alert(e.message)}
	
	return rc;
}

function OpenAlarm() {
	var newWin = window.open('AlarmList.aspx', 'AlarmWindow',	'width=250,height=250,left=200,top=200','false');
	newWin.focus();
}

//ͨõ۵չ
//forcedExpand = true ôǿչ
function collapseNode(id, img, forcedExpand) {
	
	var node = x(id);
	img	 = x(img);
	if (node.style.display == "none") {
		node.style.display = "block";
		img.src = "images/igpnl_up.gif";
		img.alt = "";
	}
	else {
		node.style.display = "none";
		img.src = "images/igpnl_dwn.gif";
		img.alt = "չ";
	}
	
	if (forcedExpand) {
		//ǿչ
		node.style.display = "block";
		img.src = "images/igpnl_up.gif";
		img.alt = "";
	}
	
	if ( event )
		event.cancelBubble = true;
}

function OpenOrderFaxs(sOrderID)
{
	popUp = window.open('OrderFaxs.aspx?OrderID=' + sOrderID ,
	    'FaxDetail' + sOrderID,
      'scrollbars=yes,titlebar =no,toolbar=no,location=no,resizable=yes,' +
      'directories=no,status=no,menubar=no,width=720,height=720,top=5,left=5');
      
      //'scrollbars=no,toolbar=no,location=no,resizable=no,' +
      //'directories=no,status=no,menubar=no,width=240,height=240,top=160,left=160');
	popUp.focus();
}

function OpenOrderFax(sOrderID, sHotelID)
{
	popUp = window.open('OrderFax.aspx?OrderID=' + sOrderID + '&HotelID=' + sHotelID,
	    'FaxDetail' + sOrderID + '_' + sHotelID,
      'scrollbars=yes,titlebar =no,toolbar=no,location=no,resizable=yes,' +
      'directories=no,status=no,menubar=no,width=720,height=720,top=5,left=5');
      
      //'scrollbars=no,toolbar=no,location=no,resizable=no,' +
      //'directories=no,status=no,menubar=no,width=240,height=240,top=160,left=160');
	popUp.focus();
}

function PopWindow(sHref, sID) {
  // open cardetail.aspx page in new window and bring to front
  var newWin = window.open(sHref, sID, "scrollbars=yes,statusbar=no,resizable=no,status=no,width=720,height=400,left=100,top=20" ); //,
      //'scrollbars=yes,toolbar=no,location=no,resizable=yes,' +
      //'directories=no,status=no,menubar=no,width=820,height=680,top=5,left='+lft+"'");
  if ( newWin )
    newWin.focus()
}



function openTicket(sHref, sID) {
  // open cardetail.aspx page in new window and bring to front
	var lft = screen.width-830;
  var newWin = window.open(sHref, sID,
      'scrollbars=yes,toolbar=no,location=no,resizable=yes,' +
      'directories=no,status=no,menubar=no,width=820,height=680,top=5,left='+lft+"'");
  if ( newWin )
    newWin.focus()
}

function openWindow(href, id) {
	try {
		// open new order in new window and bring to front
		if (id == '0') {
			newWindow( href );
		}
		else {
			var newWin = window.open(href, id);
			if ( newWin )
				newWin.focus();
		}
	}
	catch(e) {}
}

function openOrder(href, orderID) {
	try {
		// open new order in new window and bring to front
		if (orderID == '0' || href.indexOf('OrderID=0') > 0 ) {
			newWindow( href );
		}
		else {
			var name = 'Order'+ orderID;
			var newWin = window.open(href, name );
			if ( newWin )
				newWin.focus()
		}
	}
	catch(e) {}
}


function newWindow(href) {
	try {
		var now = new Date();
		var id = "NW"+ now.getHours() + now.getMinutes() + now.getSeconds() + now.getMilliseconds();		  
		if ( href.indexOf("?") > 0 )
			href += '&winID=' + id;
		else
			href += '?winID=' + id;
		var newWin = window.open(href, id );
		if ( newWin )
			newWin.focus();
	}
	catch(e) {}
}

function openFaxWindow(sHref, sOrderID) {
	// open cardetail.aspx page in new window and bring to front
	var newWin = window.open(sHref, 'FaxDetail' + sOrderID,
			'scrollbars=yes,toolbar=no,location=no,resizable=yes,' +
			'directories=no,status=no,menubar=no,width=720,height=640,top=5,left=5');
	if ( newWin )
	  newWin.focus()
}

																		 //showModalDialog
function openModalWindow(sHref, sOrderID) {
	// open cardetail.aspx page in new window and bring to front
	var newWin = window.showModalDialog(sHref, 'FaxDetail' + sOrderID,
			'edge: Raised; resizable: yes; center: yes; help: no; status: no; dialogWidth: 720px; dialogHeight: 640px;dialogTop: 5px; dialogLeft: 5px;');
	if ( newWin )
	  newWin.focus() 
}

// Select City Name
function SelectCityName(i)
{
	if (i==0) {
		//document.forms[0].txCity.value=document.forms[0].lsCity.options[document.forms[0].lsCity.selectedIndex].text;
		//document.forms[0].txCityVal.value=document.forms[0].lsCity.options[document.forms[0].lsCity.selectedIndex].value;
	}
	else {
		document.forms[0].txCity.value=document.forms[0].lsCity.options[document.forms[0].lsCity.selectedIndex].text;
		//document.forms[0].lsCity.
		//document.forms[0].txCityVal.value=document.forms[0].select2.options[document.fmHotelSearch.select2.selectedIndex].value;
	}
}

function ProvinceCitySelected(selectCtrl, itemName)
{
	var provincecitynull = new Array(new Array("", "----"));
	
	if( ProvinceIDs.search(","+itemName+",") >=0 ) {
		var itemArray = eval("ProvinceCities"+itemName);
	}
	else {
		var itemArray = provincecitynull;
	}
	
	for( i=selectCtrl.options.length; i>=0; i-- ) {
		selectCtrl.options[i] = null;
	}
	
	for(i=0;i<itemArray.length;i++) {
		selectCtrl.options[i] = new Option(itemArray[i][1]);
		if(itemArray[i][0]!=null)
		{
			selectCtrl.options[i].value = itemArray[i][0];
		}
	}
	selectCtrl.selectedIndex=0;
	SelectCityName(1);
}

function showItem(strtype)
{
  document.getElementById(strtype).style.display="block";
}
function hideItem(strtype)
{
  document.getElementById(strtype).style.display="none";
}

function rnd() { 
	rnd.today=new Date(); 
	rnd.seed=rnd.today.getTime(); 

rnd.seed = (rnd.seed*9301+49297) % 233280; 
return rnd.seed/(233280.0); 
}

function rand(number) { 
return Math.ceil(rnd()*number); 
}

function isDateString(sDate) {	
	var iaMonthDays = [31,28,31,30,31,30,31,31,30,31,30,31]
	var iaDate = new Array(3)
	var year, month, day

	if (arguments.length != 1) return false
	iaDate = sDate.toString().split("-")
	
	if (iaDate.length != 3) 
		return false
	if (iaDate[1].length > 2 || iaDate[2].length > 2) 
		return false
	if (isNaN(iaDate[0])||isNaN(iaDate[1])||isNaN(iaDate[2])) 
		return false

	year = parseFloat(iaDate[0])
	month = parseFloat(iaDate[1])
	day=parseFloat(iaDate[2])

	if (year < 1900 || year > 2100) 
		return false
	if (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0)) 
		iaMonthDays[1]=29;
	if (month < 1 || month > 12) 
		return false
	
	if (day < 1 || day > iaMonthDays[month - 1]) 
		return false
	
	return true
}

function stringToDate(sDate) {	
	if ( isDateString(sDate) ){  
		var iaDate = sDate.toString().split("-")
		var year = parseFloat(iaDate[0])
		var month = parseFloat(iaDate[1]) - 1
		var day=parseFloat(iaDate[2])
		return (new Date(year,month,day))
	}
	else 
		//return (new Date(1900,0,1));
		return null;
}

//javascript中读取url中形如a=b&c=d的参数
  function getpara(name)
  {

    paras=window.location.search;
    if(!paras)
       return null;
   //alert(paras.indexOf("?",2))
   if (paras.indexOf("?",2)==17)paras=paras.substr(18);
    else paras=paras.substr(1);
    //alert(paras);
    paraarray=paras.split("&");
    for(i=0;i<paraarray.length;i++)
    {
     //alert(paraarray[i]);
     temp=paraarray[i].split("=");
     if(temp[0].toUpperCase()==name.toUpperCase())
      return temp[1].replace("%20"," ");
    }
    return null;
  }
  
//判断中文字符
function isCn(obj)   
{   
  var reg = /^[\u0391-\uFFE5]+$/;   
  return reg.test(obj);
}   
  
function fnGetLength(str)   
{   
  var length = 0;   
  for(var i=0;i<str.length;i++)   
  {   
    if(isCn(str.charAt(i)))   
    {     
      length += 2;   
    }   
    else   
    {   
      length++;   
    }   
  }   
  return length;   
} 
  
//
//获取元素位置
function getPos(ele)
{
	//var ele = ele);
	var obj = ele;
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft;
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	var obj = ele;	
	var curtop = 0;
	if (obj.offsetParent) {
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop;
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;

	return {x:curleft, y:curtop};
}
function selectChecked(selectID, option) {
    for (i = 0; i < x(selectID).options.length; i++) {

        if (x(selectID).options[i].text == option) {
            x(selectID).options[i].selected = true;
            break;
        }
    }

}
function getRadioValue(RadioName) {
    var radioGroup = document.getElementsByName(RadioName);

    for (i = 0; i < radioGroup.length; i++) {
        if (radioGroup[i].checked == true) {
            return radioGroup[i].value;
        }

    }
}
//填写错误的input Text焦点定位，并更改父结点的背景颜色，errorLog为input Text显示的错误信息，ZXB
function focusError(errorLog, focusID) {
    gE(focusID).focus();
    gE(focusID).value = errorLog;
    gE(focusID).parentNode.style.backgroundColor = "#ffe6e6";
    gE(focusID).parentNode.style.border = "1px solid #ffd0d0";
    gE(focusID).style.color = "red";
    gE(focusID).onclick = function() {
        if (gE(focusID).value == errorLog) gE(focusID).value = "";
        gE(focusID).style.color = "#333";
    }
    return false;
}
