﻿// JavaScript Document


// Description: sInputString 为输入字符串，iType为类型，分别为  
// 0 - 去除前后空格; 1 - 去前导空格; 2 - 去尾部空格
function trim(sInputString)
{   
	iType=0;
	var sTmpStr = ' ' 
     var i = -1  
	 if(iType == 0 || iType == 1) 
	 { 
		 while(sTmpStr == ' ') 
		 {   
		 	  ++i  
			 sTmpStr = sInputString.substr(i,1) 
		 }  
		 sInputString = sInputString.substring(i) 
	}  
	if(iType == 0 || iType == 2) 
	{  
		sTmpStr = ' '
		i = sInputString.length  
		while(sTmpStr == ' ')  
		{  
			--i 
			sTmpStr = sInputString.substr(i,1)  
		} 
		sInputString = sInputString.substring(0,i+1)  
	} 
	return sInputString 
}

//格式化价钱
function formatPrice(price)
{
//debugger;
    price=price+"";
    var l=price.indexOf(".");
	if(l>=0)
	{
		  if (price.substring(l + 1, 1) == "0")
            {
                return price.substring(0, l);
            }
            else
            {
                return Math.round(price*10)/10;
            }
	}
	return price;
}

function setMarginTop(){
	
	mainID="div.MainPanel"
	
	var h=$(window).height();
	var ph=$(mainID).height()/2;
	var pt=h/2 - ph;
	if(pt >=0)
	{
		$(mainID).css("margin-top",pt);
	}
	else
	{
		$(mainID).css("margin-top","0px");
	}
}


function $get(id)
{
	return	document.getElementById(id);
}


//自动根据指定比例到指定容器控制图片的显示
function resetImgSize(divClass,wth,hgh)
{
	var divColection=document.getElementsByTagName("div");//获取div数组	
	//var divs=$get(divid);
	//debugger;
	for(j=0;j<divColection.length;j++)
	{
		var cssList=divColection[j].className.split(" ");
		var findFlag=false;
		for(k=0;k<cssList.length;k++)
		{
			if(cssList[k]==divClass)
			{
				findFlag=true;
				break;
			}
		}
		
		if(findFlag)  //检查是否是有divClass这个类名
		{
			var imgs=divColection[j].getElementsByTagName("img");	
			setHeight=hgh;
			setWidth=wth;
			//document.getElementById("sdf").style.paddingRight.paddingLeft.paddingBottom.paddingTop
			for(i=0;i<imgs.length;i++)
			{
				height=imgs[i].height;
				width=imgs[i].width;
				//alert(height+","+width+","+width/height+","+setWidth/setHeight)
				if(height>setHeight||width>setWidth)
				{
					if(width/height>setWidth/setHeight)
					{
						height=setWidth*height/width				
						width=setWidth;
					}
					else
					{	
						width=setHeight*width/height				
						height=setHeight;
					}
				}
	
				imgs[i].height=height;
				if(height<setHeight)
				{
					
					//imgs[i].style.marginTop=(setHeight-height)/2;
					imgs[i].style.paddingBottom=(setHeight-height);
					//alert(width+","+height)
				}
				imgs[i].width=width;
				if(width<setWidth)
				{
					imgs[i].style.paddingLeft=(setWidth-width)/2;
					imgs[i].style.paddingRight=(setWidth-width)/2;
					//alert(width+","+height)
				}
			}
		}
	}
}

	//全部选择
function doSelectAll()
{
    var i=0;
    var idstr="";
    var obj=document.getElementById("selectAll");
    
    for(i=0;i<document.getElementsByName("selectone").length;i++)
    {
        if(obj.checked)
        {
            document.getElementsByName("selectone")[i].checked=true;
		    idstr+=document.getElementsByName("selectone")[i].value + ",";
		}
		else
		{
		    document.getElementsByName("selectone")[i].checked=false;
		    idstr="";
		}
	}
	if(idstr!="")
	{//去掉后面一个","
  	  document.getElementById("hidSelect").value=idstr.substring(0,idstr.length-1);
	}
	else
	{
		document.getElementById("hidSelect").value=idstr;	
	}
}
function doSelect()
{
	 var i=0;
    var idstr="";
 
    for(i=0;i<document.getElementsByName("selectone").length;i++)
    {
        if(document.getElementsByName("selectone")[i].checked)
        {           
		    idstr+=document.getElementsByName("selectone")[i].value + ",";
		}		
	}
  if(idstr!="")
	{//去掉后面一个","
  	  document.getElementById("hidSelect").value=idstr.substring(0,idstr.length-1);
	}
	else
	{
		document.getElementById("hidSelect").value=idstr;	
	}
}
//自动调整指定区域的图片大小
//id,图片ID
//size,尺寸
//type,类型,1为调整宽,2为调整高
function autoResizeImg(id,size,type)
{
	
	$("#"+id+" img").each(function()
								   {
									   switch(type)
									   {
										   case 1:
										   if($(this).width()>size)
										   {
											   $(this).width(size);
											   //alert($(this))
											   $(this).attr("rel","lytebox");
												$(this).removeAttr("height");
												
											}
											break;
											case 2:
											if($(this).height()>size)
										   {
											   $(this).height(size);
											   //alert($(this))
											   $(this).attr("rel","lytebox");
												$(this).removeAttr("width");
												
											}
											
											break;
									   }
									   
									}
								   );
}



//添加Flash轮播广告 width长,height高,pics图片,links链接,texts文字
function addFlash1(width,height,pics,links,texts)
{

                    var pic_width=width; //图片宽度//this param387
                    var pic_height=height; //图片高度//this param244

                    var button_pos=4; //按扭位置 1左 2右 3上 4下//this param
                    var stop_time=10000; //图片停留时间(1000为1秒钟)//this param
                    var show_text=1; //是否显示文字标签 1显示 0不显示//this param
                    var txtcolor="ffffff"; //文字色

                    var bgcolor="000000"; //背景色


                    var imag=new Array();
                    var link=new Array();//this param
                    var text=new Array();//this param

                    //可编辑内容结束
                    var swf_height=show_text==0?pic_height:pic_height;//this param

                    var pics=pics;
                    var links=links;
                    var texts=texts;

                    var wmode = 'movie';
                    var flashurl = 'focus.swf';
                    var htmlstr = '<embed wmode="transparent" style="position:relative;top:0px;" src="' + flashurl + '" wmode=' + wmode +
                    ' quality="high" FlashVars="pics='+pics
	                    +'&links='+links
	                    +'&texts='+texts+
	                    '&pic_width='+pic_width+
	                    '&pic_height='+pic_height+
	                    '&show_text='+show_text+
	                    '&txtcolor='+txtcolor+
	                    '&bgcolor='+bgcolor+
	                    '&button_pos='+button_pos+
	                    '&stop_time='+stop_time+
	                    '" quality="high" width="'+ pic_width +
	                    '" height="'+ swf_height +'" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"></embed>';
                    document.write(htmlstr);
                
  }
function addFlash2(width,height,pics,links,texts)
{
								var focus_width=width;
						var focus_height=height;
						var text_height=0;
						var swf_height = focus_height+text_height;
						var src="playswfnew.swf";
						  
						document.write('<object ID="focus_flash" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="'+ focus_width +'" height="'+ swf_height +'">');
						document.write('<param name="allowScriptAccess" value="sameDomain"><param name="movie" value="'+src+'"><param name="quality" value="high"><param name="bgcolor" value="#ffffff">');
						document.write('<param name="menu" value="false"><param name=wmode value="opaque">');
						document.write('<param name="FlashVars" value="pics='+pics+'&links='+links+'&texts='+texts+'&borderwidth='+focus_width+'&borderheight='+focus_height+'&textheight='+text_height+'">');
						document.write('<embed ID="focus_flash" src="'+src+'" wmode="opaque" FlashVars="pics='+pics+'&links='+links+'&texts='+texts+'&borderwidth='+focus_width+'&borderheight='+focus_height+'&textheight='+text_height+'" menu="false" bgcolor="#fff" quality="high" width="'+ focus_width +'" height="'+ swf_height +'" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />');		document.write('</object>');
}
//添加普通FLASH
function addFlash(width,height,src)
{
  var htmlstr = '<embed wmode="transparent" style="position:relative;top:0px;" src="' + src + '"' +
                    ' quality="high" width="'+ width +'" height="'+ height 
                    +'" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"></embed>';
                              
                       document.write(htmlstr);
}// JavaScript Document

function addFlashAd(widht,count) {
var $ = function (id) {
	return "string" == typeof id ? document.getElementById(id) : id;
};

var Class = {
  create: function() {
	return function() {
	  this.initialize.apply(this, arguments);
	}
  }
}

Object.extend = function(destination, source) {
	for (var property in source) {
		destination[property] = source[property];
	}
	return destination;
}

var TransformView = Class.create();
TransformView.prototype = {
  //容器对象,滑动对象,切换参数,切换数量
  initialize: function(container, slider, parameter, count, options) {
	if(parameter <= 0 || count <= 0) return;
	var oContainer = $(container), oSlider = $(slider), oThis = this;

	this.Index = 0;//当前索引
	
	this._timer = null;//定时器
	this._slider = oSlider;//滑动对象
	this._parameter = parameter;//切换参数
	this._count = count || 0;//切换数量
	this._target = 0;//目标参数
	
	this.SetOptions(options);
	
	this.Up = !!this.options.Up;
	this.Step = Math.abs(this.options.Step);
	this.Time = Math.abs(this.options.Time);
	this.Auto = !!this.options.Auto;
	this.Pause = Math.abs(this.options.Pause);
	this.onStart = this.options.onStart;
	this.onFinish = this.options.onFinish;
	
	oContainer.style.overflow = "hidden";
	oContainer.style.position = "relative";
	
	oSlider.style.position = "absolute";
	oSlider.style.top = oSlider.style.left = 0;
  },
  //设置默认属性
  SetOptions: function(options) {
	this.options = {//默认值
		Up:			true,//是否向上(否则向左)
		Step:		5,//滑动变化率
		Time:		10,//滑动延时
		Auto:		true,//是否自动转换
		Pause:		2000,//停顿时间(Auto为true时有效)
		onStart:	function(){},//开始转换时执行
		onFinish:	function(){}//完成转换时执行
	};
	Object.extend(this.options, options || {});
  },
  //开始切换设置
  Start: function() {
	if(this.Index < 0){
		this.Index = this._count - 1;
	} else if (this.Index >= this._count){ this.Index = 0; }
	
	this._target = -1 * this._parameter * this.Index;
	this.onStart();
	this.Move();
  },
  //移动
  Move: function() {
	clearTimeout(this._timer);
	var oThis = this, style = this.Up ? "top" : "left", iNow = parseInt(this._slider.style[style]) || 0, iStep = this.GetStep(this._target, iNow);
	
	if (iStep != 0) {
		this._slider.style[style] = (iNow + iStep) + "px";
		this._timer = setTimeout(function(){ oThis.Move(); }, this.Time);
	} else {
		this._slider.style[style] = this._target + "px";
		this.onFinish();
		if (this.Auto) { this._timer = setTimeout(function(){ oThis.Index++; oThis.Start(); }, this.Pause); }
	}
  },
  //获取步长
  GetStep: function(iTarget, iNow) {
	var iStep = (iTarget - iNow) / this.Step;
	if (iStep == 0) return 0;
	if (Math.abs(iStep) < 1) return (iStep > 0 ? 1 : -1);
	return iStep;
  },
  //停止
  Stop: function(iTarget, iNow) {
	clearTimeout(this._timer);
	this._slider.style[this.Up ? "top" : "left"] = this._target + "px";
  }
};

window.onload=function(){
	function Each(list, fun){
		for (var i = 0, len = list.length; i < len; i++) { fun(list[i], i); }
	};
	
	var objs2 = $("idNum2").getElementsByTagName("li");
	
	var tv2 = new TransformView("idTransformView2", "idSlider2", widht, count, {
		onStart: function(){ Each(objs2, function(o, i){ o.className = tv2.Index == i ? "on" : ""; }) },//按钮样式
		Up: false
	});
	
	tv2.Start();
	
	Each(objs2, function(o, i){
		o.onmouseover = function(){
			o.className = "on";
			tv2.Auto = false;
			tv2.Index = i;
			tv2.Start();
		}
		o.onmouseout = function(){
			o.className = "";
			tv2.Auto = true;
			tv2.Start();
		}
	})
}
}


function doSelectAll()
{
    var i=0;
    var idstr="";
    var obj=document.getElementById("selectAll");
    
    for(i=0;i<document.getElementsByName("selectone").length;i++)
    {
        if(obj.checked)
        {
            document.getElementsByName("selectone")[i].checked=true;
		    idstr+=document.getElementsByName("selectone")[i].value + ",";
		}
		else
		{
		    document.getElementsByName("selectone")[i].checked=false;
		    idstr="";
		}
	}
	if(idstr!="")
	{
  	  document.getElementById("hidSelect").value=idstr.substring(0,idstr.length-1);
	}
	else
	{
		document.getElementById("hidSelect").value=idstr;	
	}
}
function doSelect()
{
	 var i=0;
    var idstr="";
 
    for(i=0;i<document.getElementsByName("selectone").length;i++)
    {
        if(document.getElementsByName("selectone")[i].checked)
        {           
		    idstr+=document.getElementsByName("selectone")[i].value + ",";
		}		
	}
  if(idstr!="")
	{
  	  document.getElementById("hidSelect").value=idstr.substring(0,idstr.length-1);
	}
	else
	{
		document.getElementById("hidSelect").value=idstr;	
	}
}
//设为首页
function setHomePage(obj){
    var aUrls=document.URL.split("/");
    var vDomainName="http://"+aUrls[2]+"/";
    try{//IE
        obj.style.behavior="url(#default#homepage)";
        obj.setHomePage(vDomainName);
    }catch(e){//other
        if(window.netscape) {//ff
            try {
                    netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
            }
            catch (e) {
                    alert(" 此操作被浏览器拒绝！\n请在浏览器地址栏输入“about:config”并回车\n然后将 [signed.applets.codebase_principal_support]设置为'true'");
            }
            var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);
            prefs.setCharPref('browser.startup.homepage',vDomainName);
         }
    }
}

//添加到收藏夹  <a onclick="javascript:AddToFavorite();"  style="cursor:pointer">
function AddToFavorite()   
{   
    if (document.all){   
       window.external.addFavorite(document.URL,document.title);   
    }else if (window.sidebar){   
       window.sidebar.addPanel(document.title, document.URL, "");   
    }   
}   

//取当前时间，格式为,yyyy-mm-dd hh:mm:ss
function getNowFormatDate()
{
   var day = new Date();

   var Year = 0;
   var Month = 0;
   var Day = 0;
var CurrentDate = "";
   //初始化时间
   //Year= day.getYear();//有火狐下2008年显示108的bug
   Year= day.getFullYear();//ie火狐下都可以
   Month= day.getMonth()+1;
   Day = day.getDate();
   Hour = day.getHours();
   Minute = day.getMinutes();
   Second = day.getSeconds();
   CurrentDate += Year + "-";
   if (Month >= 10 )
   {
    CurrentDate += Month + "-";
   }
   else
   {
    CurrentDate += "0" + Month + "-";
   }
   if (Day >= 10 )
   {
    CurrentDate += Day ;
   }
   else
   {
    CurrentDate += "0" + Day ;
   }
   if(Hour>=10)
   {
    CurrentDate+=" "+Hour;
   }else
   {
    CurrentDate+=" 0"+Hour;
   }
   if(Minute>=10)
   {
    CurrentDate+=":"+Minute;
   }else
   {
    CurrentDate+=":0"+Minute;
   }
   if(Second>=10)
   {
    CurrentDate+=":"+Second;
   }
   else
   {
    CurrentDate+=":0"+Second;
   }
   return CurrentDate;
}

//播放视频
function writeVideo(src,w,h)
{
	var vtype= src.split(".");
	videotype=vtype[1];
	var videcode='';
	switch(videotype)
	{
		case "flv":
	
	videcode+='<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="'+w+'" height="'+h+'">';
	videcode+='<param name="movie" value="vcastr.swf">';
	videcode+='<param name="quality" value="high">';
	videcode+='<param name="allowFullScreen" value="true" />';
	videcode+='<param name="FlashVars" value="vcastr_file='+src+'&LogoUrl=&LogoText=" />';
	videcode+='<embed src="vcastr.swf" allowFullScreen="true" FlashVars="vcastr_file='+src+'" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="'+w+'" height="'+w+'" ></embed>';
	videcode+='</object>';
		break;
	}
	document.writeln(videcode);
}


//获取随机数
function GetRandomNum(minNum,maxNum)
{       
        var Rand = Math.random();
		return Rand*(maxNum-minNum)+minNum;       
}
function GetNowTime(){
var week;
if(new Date().getDay()==0)          week="星期日"
if(new Date().getDay()==1)          week="星期一"
if(new Date().getDay()==2)          week="星期二"
if(new Date().getDay()==3)          week="星期三"
if(new Date().getDay()==4)          week="星期四"
if(new Date().getDay()==5)          week="星期五"
if(new Date().getDay()==6)          week="星期六"
document.write("今日是"+new Date().getFullYear()+"年"+(new Date().getMonth()+1)+"月"+new Date().getDate()+"日 "+week);
}

