

function oo(obj){return document.getElementById(obj)}

function n(obj){obj.value=obj.value.replace(/\D/g,'')}	//只能输入数字
	

function m(obj){	//只能输入数字或小数点
	var tmp=obj.value.replace(/[^\d\.]/g,"").replace(/(\.\d{2}).+$/,"$1");
	var txt = tmp.split(".");obj.value=txt[0]+(txt.length>1?"."+txt[1]:"");
}

function isNumber(oNum) 
{ 
  if(!oNum) return false; 
  var strP=/^\d+(\.\d+)?$/; 
  if(!strP.test(oNum)) return false; 
  try{ 
  if(parseFloat(oNum)!=oNum) return false; 
  } 
  catch(ex) 
  { 
   return false; 
  } 
  return true; 
}

//document.onkeydown =stop_ctrlF5
function stop_ctrlF5()
{
/*(ctrlKey == true && keyCode == 82)   Ctrl+R   ---刷新
(keyCode == 116)                     F5       ---刷新
(ctrlKey == true && keyCode == 116) Ctrl+F5 ---强制刷新*/
    var k = event.keyCode;
    if((event.ctrlKey == true && k == 82) || (k == 116) || (event.ctrlKey == true && k == 116))
    {
        event.keyCode = 0;
        event.returnValue = false;
        event.cancelBubble = true;
    }
}



//禁止刷新，回退document.onkeydown = stop_refsh_back;  
function stop_refsh_back() 
{ 
if ( (event.altKey) || ((event.keyCode == 8) && 
(event.srcElement.type != "text" && 
event.srcElement.type != "textarea" && 
event.srcElement.type != "password")) || 
((event.ctrlKey) && ((event.keyCode == 78) || (event.keyCode == 82)) ) || 
(event.keyCode == 116) ) { 
 event.keyCode = 0; 
 event.returnValue = false; 
 } 
} 
function stop_rightKey(){ return false }   	//这个是禁用鼠标右键 document.oncontextmenustop_rightKey; 

//two函数适用于日期当中，如月分,日 小于两位数，可以在前面加补0，构成两位数
function two(s){var r=s;if (parseInt(s)<10) r='0'+s;return r }

//参数a from database str   //必须注意传进来日期格式 月 日一定要两位数的
function repeate_date(s,a){	
	var r=false
	if(-1==a.indexOf(s))r=true // -1表示不重复
	return r
}


//给定一个时间，获得价格,每天的价格都会有变化.so we need it.
//必须注意dbstr字符串格式 examp:	dbstr='2008-12-23,300|2009-12-19,540|2009-06-03,200,'2009-12-19'
//时间和价格之间用逗号分开,每一组用|分开
//函数最终返回的是个价格
function public_getPrice_fromDate(dbstr,datestr){
	var ss=dbstr;var s=datestr
	if(s!=''&ss!=''){
		tmp=ss.split(s+',')
		if(parseInt(tmp.length)<2)return
		if(tmp[1].split('|').length<2)return(tmp[1])
		else return(tmp[1].split('|')[0])
	}
}

function orderbystr(s){
		return(
			s.split('|').sort(function (a, b) {
				return (
					new Date(a.replace(/\,.+/,'').replace(/-/g, '/')).valueOf() - new Date(b.replace(/\,.+/,'').replace(/-/g, '/')).valueOf()
				) ;
			}).join('|')
		);
}


/*****************登际函数begin,用于直接登陆,非div***********************/
function public_CheckLoginForm(returnstr){
	var u=oo('frmuname').value;var p=oo('frmpassword').value	
	
	if(u=='' || p=='')return;	
	var url='/reg/reg_save.asp'
	var para='tmp='+new Date().getTime()+'&action=login&uname='+escape(u)+'&pwd='+p+'&returnUrl='+returnstr
	//alert(para)
	//window.location.href=url+'?'+para
	public_Request_user(url,para,'html','login')
}

function public_Request_user(getUrl,para,dType,action){
	$.ajax({type:'post',url:getUrl,data:para,async:false,dataType:dType,success:function(content){
			content=content.split('[*]')[0];var s='注册成功！系统已为您自动登际.';
			if(action=='login')s='登陆成功！系统会载入到指定页';if(action=='modify')s='修改成功！';
			switch(content){
				case '0':$("#close").click();window.location.reload();break;					

				case '1':break;

				case '2':alert('验证码错误');$('#code').select();break;

				case '3':alert('用户名已存在!');$('#uname').select();break;
				default:alert(content);break;
				
			}
	}});
}
/*****************登际函数end***********************/


//---------------------------------------------------------------
/**js动态创建表单并提交**/
//helper function to create the form
  function getNewSubmitForm()
  {
    var submitForm = document.createElement("FORM");
    document.body.appendChild(submitForm);
    submitForm.method = "POST";
    return submitForm;
  }

//helper function to add elements to the form
  function createNewFormElement(inputForm, elementName, elementValue)
  {
    var newElement = document.createElement("input");
    newElement.setAttribute("name",elementName);
    newElement.setAttribute("type","hidden");
    newElement.setAttribute("value",elementValue);
    inputForm.appendChild(newElement);
    return newElement;
  }


function open_reg_div(action,returnstr){
	var myAlert = document.getElementById("alert"); 
	var mClose = document.getElementById("close"); 
	
	if (action=='login') $('#alert_div_state').html('登陆')
	
	$("#alert_cont").load('/reg/reg.asp?action='+action,'');
	
	document.getElementById("alert").style.display = "block"; 
	myAlert.style.position = "absolute"; 
	myAlert.style.top = "50%"; 
	myAlert.style.left = "50%"; 
	myAlert.style.marginTop = "-75px"; 
	myAlert.style.marginLeft = "-150px"; 

	mybg = document.createElement("div"); 
	mybg.setAttribute("id","mybg"); 
	mybg.style.background = "#000"; 
	mybg.style.width = "100%"; 
	mybg.style.height = "100%"; 
	mybg.style.position = "absolute"; 
	mybg.style.top = "0"; 
	mybg.style.left = "0"; 
	mybg.style.zIndex = "500"; 
	mybg.style.opacity = "0.3"; 
	mybg.style.filter = "Alpha(opacity=30)"; 
	document.body.appendChild(mybg); 
	document.body.style.overflow = "hidden"; 

	mClose.onclick = function() 
	{ 
	myAlert.style.display = "none"; 
	mybg.style.display = "none"; 
	document.body.style.overflow = ""; 
	} 
}

function logout(){
//window.location.href='/reg/do_user.asp?t='+new Date().getTime();return
	$.ajax({type:'post',url:'/reg/do_user.asp?t='+new Date().getTime(),data:'action=logout',async:false,dataType:'html',success:function(content){
		window.location.reload();	

	}});

}


function navigation(s)
{
	if   (typeof(provinceArr_JQJD)   ==   'undefined') return
	s=s.replace(/\s+/g, "");
	var obj=provinceArr_JQJD;var id=0
	for(var i=0;i<obj.length;i++){	if(obj[i][1]==s)id=obj[i][0]	}
	if(id!=0)window.location.href='md.asp?id='+id
}




/**********************************************escape
将这个函数放入pub.js中
参数str　取决于在哪个位置打开
一种情况在Head被打开，查出后得到的结果将通过点击后去getorder.asp?uid=
另种情况在getorder.asp中打开,用于快速追捕USER ,查询后得到的结果通过点击重载getorder.asp页面URL附带uid参数
**********************************************/
function open_show_div_bySearchUser(str){


	var s='<link rel="stylesheet" type="text/css" href="/travel/css/reg.css" />'
	s+='<div id="alert"  style="display:none;filter:alpha(opacity=100);opacity:1;">'
	s+='<h4><span id="alert_div_state">查找用户</span><span id="close">关闭</span></h4>'
	s+='<div id="alert_cont"></div></div>'

	//if(cbox==null||typeof(cbox)=="undefined")
	if(top.frames['main'].document.getElementById("alert")==null){
		top.frames['main'].document.body.innerHTML+=s; 
	}
	var myAlert = top.frames['main'].document.getElementById("alert"); 
	var mClose = top.frames['main'].document.getElementById("close"); 
	var id=top.frames['main'].document.getElementById("alert_cont")
	
	$(id).load('/admin/user/searchUser_byDiv.asp?str='+str+'&tmp='+new Date().getTime(),'');
	
	//$(id).load('/admin/user/a.html','');
	myAlert.style.display = "block"; 
	myAlert.style.position = "absolute"; 
	myAlert.style.top = "50%"; 
	myAlert.style.left = "50%"; 
	myAlert.style.marginTop = "-75px"; 
	myAlert.style.marginLeft = "-150px"; 

	mybg = top.frames["main"].document.createElement("div"); 
	mybg.setAttribute("id","mybg"); 
	//mybg.style.background = "#000"; 
	mybg.style.width = "100%"; 
	mybg.style.height = "100%"; 
	mybg.style.position = "absolute"; 
	mybg.style.top = "0"; 
	mybg.style.left = "0"; 
	mybg.style.zIndex = "500"; 
	mybg.style.opacity = "0.3"; 
	mybg.style.filter = "Alpha(opacity=30)"; 
	top.frames['main'].document.body.appendChild(mybg); 
	top.frames['main'].document.body.style.overflow = "hidden"; 


	mClose.onclick = function() 
	{ 
	myAlert.style.display = "none"; 
	mybg.style.display = "none"; 
	top.frames['main'].document.body.style.overflow = ""; 

	} 
	
	//showWin('url','/admin/user/searchUser_byDiv.asp?str='+str+'&tmp='+new Date().getTime(),'',600,200)
}

