// JavaScript Document
/**
 * 获取页面指定ID公用函数
 * @param str 字符串，页面中控件或节点的ID
 */ 
function getId(str)
{
	//如果页面中存在该对象
	if(document.getElementById(str))
	{
		return document.getElementById(str);  //返回，返回值为该对象
	}
	return false;  //没有对象返回false
}

/**
 * 获取页面指定Name公用函数
 * @param str 字符串，页面中控件或节点的Name
 */
function getName(str)
{
	//如果页面中存在该对象
	if(document.getElementsByName(str))
	{
		return document.getElementsByName(str);  //返回，返回值为该对象
	}
	return false;  //没有对象返回false
}

//设置滚动条的定位
function setScroll(x,y){
	window.scrollTo(x,y); 
}

/***********************************************************
* 点击面版切换函数
* Level1page：面版一的名称
* Level2page: 面版二的名称
* id: 当前选中ID
* defaultstyle: 默认样式
* selectedstyle: 选中样式
* nostyle: 不希望改变的样式
***************************************************************/
function switchTab(Level1page,Level2page,id,defaultstyle,selectedstyle,nostyle)
{	
	var menu="Menu";
	var links="Link";
	var m=menu+id;
	var l=links+id;
	var oItem = getId(Level1page); 
	
	
	//获取导航处的大标签	
	for(var i=0;i<oItem.childNodes.length;i++)
	{
		if(oItem.childNodes[i].className != nostyle)
		{
			var x = oItem.childNodes[i];
			x.className = defaultstyle;
		}
	}
		//把样式名selected给传入的标签，改变所选菜单样式
	getId(m).className = selectedstyle;

	//得到内容部分的div标签
	var divcss=getId(Level2page).getElementsByTagName("div");
	
	//根据dTab名判断内容显示或隐藏
	
	for (var i=0;i<divcss.length;i++)
	{
		if (divcss[i].id==('2'+m))
		{
			divcss[i].style.display='block';
		}else{
			divcss[i].style.display='none';
		}
	}
	//得到子栏目部分的div标签
}
 
//极联下拉筐
function changeselect(selvalue,IdName){

	var selvalue = selvalue;
	 
	var i;
	getId(IdName).length=0;
	getId(IdName).options[getId(IdName).length]=new Option("==请选择类别==","");
	for (i = 0 ;i <spe.length;i++){
		if(spe[i][0]==selvalue){
			getId(IdName).options[getId(IdName).length]=new Option(spe[i][1],spe[i][2]);
		}
	}
}

//*** 图片浏览开始 ***
function pictureSelected(targetObj,w,h){      
document.all.pictureTd.innerHTML = "<img src='"+targetObj.value+"' width='"+w+"' height='"+h+"'>";
}
//*** 图片浏览结束 ***


function open_window(url,id,w,h,t,l)
{
	window.open(""+url+"?id="+id,"","scrollbars=yes,resizable=no,menubar=no,width="+w+",height="+h+",top="+t+",left="+l+"")

}

//跳转菜单
function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

function createCheckCode(rStrLen)
{
	var str = "abcdefghijklmnopqrstuvwxyz0123456789";
	var returnStr="";
	for(var i=0;i<rStrLen;i++)
	{
		returnStr+=new String(str).charAt(Math.random()*35).toString();
	}
	return returnStr;
}

//设置默认选项
function setSelectedIndex(id,value){
	for(var i = 0; i < getId(id).length; i++) {
		if (getId(id).options[i].value==value){
			 getId(id).selectedIndex = i;
		}
	}
}

//判断输入是否为数字
function checkNumber(event)
{
	if(document.all)
	{
    	eventKey = window.event.keyCode; //将当前按下的键ASC赋予变量
    	if(!(eventKey>=48&&eventKey<=57)){  //如果不是0-9，则当前没有键入
    	    window.event.keyCode = 0;
    	}
	}
	else
	{
    	eventKey = event.which; //将当前按下的键ASC赋予变量
		curElement = event.target;
    	if(!(eventKey>=48&&eventKey<=57)){  //如果不是0-9，则当前没有键入
			lastLetter = curElement.value.substr(curElement.value.length-1,1);
    	    curElement.value = curElement.value.substr(0,curElement.value.length-1);
    	}
	}
}


//检测输入的是否为货币格式 0-9(48-57),","(44),"."(46)
function checkMoney(event)
{ 
	var str=window.event.srcElement.value;
	var pos1=str.indexOf(".");
		eventKey = window.event.keyCode;
		if((eventKey>=48&&eventKey<=57) || eventKey==46 ){
		   if(pos1!=-1 && eventKey==46){
				window.event.keyCode = 0;
			}
		}
		else{
	 		window.event.keyCode = 0;
		}
}


function getTimes(){
var noon; 
var time=new Date(); 
var hour=time.getHours(); 
var minute=time.getMinutes(); 
var today=new Date;
var week=new Array(7); 
week[0]="天"; 
week[1]="一"; 
week[2]="二"; 
week[3]="三"; 
week[4]="四"; 
week[5]="五"; 
week[6]="六"; 
if (hour<5) noon="凌晨";
if (hour>4 & hour<8) noon="早晨";
if (hour>7 & hour<12) noon="上午";
if (hour==12) noon="中午";
if (hour>12 & hour<19) noon="下午";
if (hour>18 & hour<23) noon="晚上";
if (hour>22) noon="深夜";
if (hour>12) hour=hour-12;
if (hour<10) hour="0"+hour;
if (minute<10) minute="0"+minute;

document.write(today.getYear()+"年"+(today.getMonth()+1)+"月"+today.getDate()+"日 星期"+week[today.getDay()]+"  "+noon+" "+hour+":"+minute+"  "); 	

}

// Description: 获取浏览器窗口大小
// autor: 杜仲
function getWindowInfo()
{
	var scrollX=0,scrollY=0,width=0,height=0,contentWidth=0,contentHeight=0;
	if(typeof(window.pageXOffset)=='number')
	{
		scrollX=window.pageXOffset;
		scrollY=window.pageYOffset;
	}
	else if(document.body&&(document.body.scrollLeft||document.body.scrollTop))
	{
		scrollX=document.body.scrollLeft;
		scrollY=document.body.scrollTop;
	}
	else if(document.documentElement&&(document.documentElement.scrollLeft||document.documentElement.scrollTop))
	{
		scrollX=document.documentElement.scrollLeft;
		scrollY=document.documentElement.scrollTop;
	}
	if(typeof(window.innerWidth)=='number')
	{
		width=window.innerWidth;
		height=window.innerHeight;
	}
	else if(document.documentElement&&(document.documentElement.clientWidth||document.documentElement.clientHeight))
	{
		width=document.documentElement.clientWidth;
		height=document.documentElement.clientHeight;
	}
	else if(document.body&&(document.body.clientWidth||document.body.clientHeight))
	{
		width=document.body.clientWidth;
		height=document.body.clientHeight;
	}
	if(document.documentElement&&(document.documentElement.scrollHeight||document.documentElement.offsetHeight))
	{
		if(document.documentElement.scrollHeight>document.documentElement.offsetHeight)
		{
			contentWidth=document.documentElement.scrollWidth;
			contentHeight=document.documentElement.scrollHeight;
		}
		else
		{
			contentWidth=document.documentElement.offsetWidth;
			contentHeight=document.documentElement.offsetHeight;
		}
	}
	else if(document.body&&(document.body.scrollHeight||document.body.offsetHeight))
	{
		if(document.body.scrollHeight>document.body.offsetHeight)
		{
			contentWidth=document.body.scrollWidth;
			contentHeight=document.body.scrollHeight;
		}
		else
		{
			contentWidth=document.body.offsetWidth;
			contentHeight=document.body.offsetHeight;
		}
	}
	else
	{
		contentWidth=width;
		contentHeight=height;
	}
	if(height>contentHeight)
		height=contentHeight;
	if(width>contentWidth)
		width=contentWidth;
	var rect=new Object();
	rect.ScrollX=scrollX;
	rect.ScrollY=scrollY;
	rect.Width=width;
	rect.Height=height;
	rect.ContentWidth=contentWidth;
	rect.ContentHeight=contentHeight;
	return rect;
}

/*Ajax Tab 效果
*@para prefix ID标识前缀
*@para tabNum tab数量
*@para curId 当前Tab的索引
*/
function tab(prefix,tabNum,curId){

	for(var i=1;i<=tabNum;i++){
		if(i==curId){
			document.getElementById(prefix+i).className="current";
			document.getElementById(prefix+'sub_'+i).style.display="block";
		}else{
			document.getElementById(prefix+i).className="";
			document.getElementById(prefix+'sub_'+i).style.display="none";
		}
	}
	
	 
}

function tabHref(prefix,tabNum,curId,id){

getId("more").href="flower/list.php?id="+id;
	for(var i=1;i<=tabNum;i++){
		if(i==curId){
			document.getElementById(prefix+i).className="current";
			document.getElementById(prefix+'sub_'+i).style.display="block";
		}else{
			document.getElementById(prefix+i).className="";
			document.getElementById(prefix+'sub_'+i).style.display="none";
		}
	}
	
	
}

//让2个不同的层高度一致
//调用方法：oneHeight('left_nav','rightConent')
function oneHeight(){
   var maxHeight=0;
   var a=[];
   for(var i=0,n=arguments.length;i<n;i++){
     a[i]=document.getElementById(arguments[i]);
     if(a[i].scrollHeight>maxHeight)
       maxHeight=a[i].scrollHeight;
   }
   for(i=0;i<n;i++)
     a[i].style.height=maxHeight+'px';
}


//显示与隐藏
function showsubmenu(sid)
{
	var whichEl = document.getElementById("submenu"+sid);

	if (whichEl.style.display == "none")
	{
		document.getElementById("submenu"+sid).style.display="block";
		document.getElementById("showsubmenu"+sid).className="current";
	}
	else
	{
		document.getElementById("submenu"+sid).style.display="none";
		document.getElementById("showsubmenu"+sid).className="";
	}
}


//将复选筐的值给隐藏域
function checkbox(name,id)
{

	theValue = '';
	thePermition = document.getElementsByName(name);
	for(i=0;i<thePermition.length;i++)
	{
		if(thePermition[i].checked)
		{
			if(theValue == '')
				theValue = thePermition[i].value;
			else
				theValue += ','+thePermition[i].value;
		}
	}
	getId(id).value = theValue;
}

//将复选筐的值给隐藏域
function setButton(id)
{
	getId(id).disabled = false;
}

//让不同的层永远等高度
function oneHeight(){
   var maxHeight=0;
   var a=[];
   for(var i=0,n=arguments.length;i<n;i++){
     a[i]=document.getElementById(arguments[i]);
     if(a[i].scrollHeight>maxHeight)
       maxHeight=a[i].scrollHeight;
   }
   for(i=0;i<n;i++)
     a[i].style.height=maxHeight+'px';
}

//每个页面调用函数
/*window.onload=function(){
	oneHeight('sideBar','RightMain');
}
*/

//屏蔽JS报错
function error()
{
   return true;
}
//window.onerror = error;


//加入购物车
function car(id)
{
	//location = "http://localhost/php/114hua/product/car.php?id="+id;
  	location.href = "http://www.114hua.com/product/car.php?id="+id;
}

//查询订单详细信息
function showOrder(id)
{
	window.open("orderinfo.php?id=" + id,"order",'scrollbars=1,resizable=0,width=700,height=500,top=100,left=250');
	return false;
}

//查询订单详细信息
function showOrderPrint(id)
{
	window.open("order_print.php?id=" + id,"order",'scrollbars=1,resizable=0,width=700,height=500,top=100,left=250');
	return false;
}
