﻿//去掉字符串前后空格
String.prototype.Trim = function()
{
  return this.replace(/(^\s*)|(\s*$)/g, "");
}


function popwin(url,width,height)
{
    window.open(url,"","toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,width="+width+",height="+height);
}

function popwinbar(url,width,height)
{
    window.open(url,"","toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=0,width="+width+",height="+height);
}

function popwinchart(url,width,height)
{
    var enddate=document.getElementById("txtEndDate").value;
    var startdate=document.getElementById("txtStartDate").value;
    
    window.open(url+"?start="+startdate+"&end="+enddate,"","toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=0,width="+width+",height="+height);
}

function Survey()
{
    var url="/product/SurveyView.aspx?id=";
    if(getRadioValue("rbtnSurveyItem")!="")
    {
        url+=getRadioValue("rbtnSurveyItem");
        popwin(url,300,235);
    }
    else
    {
        alert("请选择调查选项，谢谢！");
    }
}

function SurveyView()
{
 var url="/product/SurveyView.aspx?sid=";
 if(document.getElementById("hidSurveyid").value!="")
 {
    url+=document.getElementById("hidSurveyid").value;
    popwin(url,300,235);
 }
}

function getRadioValue(radioName){
var reValue="";
 var obj=document.getElementsByName(radioName);
 for(var i=0;i<obj.length;i++){
  if(obj[i].checked){
   reValue = obj[i].value;
   break;
  }
 }
 return reValue;
}

function frmSearch()
{
    var Keyword = document.getElementById("key").value.Trim();
    if(Keyword=='')
    {
        alert('搜索关键字不能为空！');
        document.getElementById("key").focus();
        return;
    }
    else
    {
        Keyword=escape(Keyword);
        var searchUrl=""

        window.location.href="/news/search.aspx?key=" + Keyword;;
    }
}
//页签转换
function TagChange(tagName,tagNum,tagId)
{
	for(i=1;i<=tagNum;i++)
	{
		if(i==tagId)
		{
			document.getElementById("table"+tagName+i).style.display="block";
			document.getElementById("td"+tagName+i).className='tag_on';
		}
		else
		{
		    document.getElementById("table"+tagName+i).style.display="none";
		   document.getElementById("td"+tagName+i).className='tag_off';
		}
		
	}
}


function frmPrice()
{
    var chkprice=document.all.chkprice;
    var areastr="";
    var chknum=0;
    for(i=0;i<chkprice.length;i++)
    {
	    if(chkprice[i].checked)	
	    {
		    chknum++;
		    areastr+=chkprice[i].value+"|";
	    }
    }
    if(chknum==0)
    {
    alert("请选择单位！");
    return false;
    } else if(chknum>6)
    {
    alert("最多只能选择6个单位！");
    return false;
    }
  
   
var startDate,endDate;
startDate=document.getElementById("txtStartDate").value;
endDate=document.getElementById("txtEndDate").value;

if(startDate=="")
{
	alert("开始日期不能为空！");
	return false;
}

if(endDate=="")
{
	alert("结束日期不能为空！");
	return false;
}

popwin("/product/pricechart.aspx?start="+startDate+"&end="+endDate+"&area="+areastr,650,500);
   
}


function frmPrice_newflash()
{
    var chknum=0;
    var areastr="";
    $("input[@name='chkprice']").each(function(){
       if($(this).attr("checked")==true){
        areastr += $(this).attr("value")+"|";
         chknum++;
       }
    })
     
    if(chknum==0)
    {
        alert("请选择单位！");
        return false;
    } else if(chknum>6)
    {
        alert("最多只能选择6个单位！");
        return false;
    }
     
    if(chknum==0)
    {
    alert("请选择单位！");
    return false;
    } else if(chknum>6)
    {
    alert("最多只能选择6个单位！");
    return false;
    }
  
   
var startDate,endDate;
startDate=document.getElementById("txtStartDate").value;
endDate=document.getElementById("txtEndDate").value;

if(startDate=="")
{
	alert("开始日期不能为空！");
	return false;
}

if(endDate=="")
{
	alert("结束日期不能为空！");
	return false;
}

makeNewWindow("/product/priceimg.aspx?start="+startDate+"&end="+endDate+"&area="+areastr,820,500);
   
}

function frmPrice_data()
{
    var chknum=0;
    var areastr="";
    $("input[@name='chkprice']").each(function(){
       if($(this).attr("checked")==true){
        areastr += $(this).attr("value")+"|";
         chknum++;
       }
    })
     
    if(chknum==0)
    {
        alert("请选择单位！");
        return false;
    } else if(chknum>6)
    {
        alert("最多只能选择6个单位！");
        return false;
    }
  
   
var startDate,endDate;
startDate=document.getElementById("txtStartDate").value;
endDate=document.getElementById("txtEndDate").value;

if(startDate=="")
{
	alert("开始日期不能为空！");
	return false;
}

if(endDate=="")
{
	alert("结束日期不能为空！");
	return false;
}
if(compareDate(showdate(),startDate)>180)
{
    alert("你所查看的历史数据超出了规定的时间范围！");
    return false;
}

 window.open("/product/pricelist.aspx?start="+startDate+"&end="+endDate+"&aid="+areastr);
   
}


var newWindow;
function makeNewWindow(url,width,height) {
    var left = parseInt((screen.availWidth/2) - (width/2));//屏幕居中
    var top = parseInt((screen.availHeight/2) - (height/2));
    var windowFeatures = "width=" + width + ",height=" + height + ",status,resizable,scrollbars=1,left=" + left + ",top=" + top + "screenX=" + left + ",screenY=" + top;
    newWindow = window.open(url, "subWind", windowFeatures);
    newWindow.focus();
}

function compareDate(dateOne,dateTwo)
{ 
    var s1 = dateOne.replace(/-/g, "/"); 
    var s2 = dateTwo.replace(/-/g, "/"); 

    s1 = new Date(s1);
    s2 = new Date(s2);

    var days= s1.getTime() - s2.getTime(); 
    var time = parseInt(days / (1000 * 60 * 60 * 24));

    //alert("相差天数: " + time);

    return time;
 }

function showdate(){
  var today=new Date();
  date=today.getDate();
  month=today.getMonth();
  month=month+1;
  if(month<=9)
     month="0"+month;
  year=today.getYear();
  return nowDate=year+'-'+month+'-'+date;
  }

