﻿// JavaScript Document
//头部自动加载鼠标hover切换图片
function topHover()
{
	if($(".menu ul li img").attr("mycom"))
	{
		var tmpimg=""
		$(".menu ul li img").each(function(){
			$(this).data('src', $(this).attr('src'));
		});
		$(".menu ul li img").hover(function(){
											$(this).attr("src",function(){
																		return $(this).attr("mycom");
																		});
											},
											function(){
														$(this).attr("src",$(this).data('src'));									
												})
	}
}

//隐藏显示首页tab
function indexTAB(group,id)
{
	$(".cp").each(
				   function(){
					   if($(this).attr("mygroup")==group && $(this).attr("id")== id){
							$("#"+id).addClass("cphover");
							$("#"+id+"_c").show();
					   }else if($(this).attr("mygroup")==group && $(this).attr("id")!= id){
						   //$("#"+$(this).attr("id")).removeClass("cphover");
						   $(this).removeClass("cphover");
						   $("#"+$(this).attr("id")+"_c").hide();
					   }
					   });
}
//鼠标hover展示大图
function showBigPic(src,id)
{
	$("#maximg").attr("src", src);
	$("#"+id).addClass("imghover");
}
function rmcss(id)
{
	$("#"+id).removeClass("imghover");
}
//在线订购js
var d_lx="0";
var d_bz="0";
var d_yq="0";
function selectme(id,kind)
{
	switch(kind)
	{
		case "lx":
			if(d_lx != id)
			{
				$("#"+kind+"_"+id).attr("src","price/"+kind+"_"+id+"_selected.jpg");
				$("#"+kind+"_"+d_lx).attr("src","price/"+kind+"_"+d_lx+".jpg");
				$("#gplx").val($("#"+kind+"_"+id).attr("alt"));
				$("#plx").val($("#"+kind+"_"+id).attr("id"));
				d_lx=id;
				goOK();
			}
			break;
		case "yq":
			if(d_yq != id)
			{
				$("#"+kind+"_"+id).attr("src","price/"+kind+"_"+id+"_selected.jpg");
				$("#"+kind+"_"+d_yq).attr("src","price/"+kind+"_"+d_yq+".jpg");
				$("#zzyq").val($("#"+kind+"_"+id).attr("alt"));
				$("#pyq").val($("#"+kind+"_"+id).attr("id"));
				d_yq=id;
				goOK();
			}
			break;
		case "bz":
			if(d_bz != id)
			{
				$("#"+kind+"_"+id).attr("src","price/"+kind+"_"+id+"_selected.jpg");
				$("#"+kind+"_"+d_bz).attr("src","price/"+kind+"_"+d_bz+".jpg");
				$("#xzbz").val($("#"+kind+"_"+id).attr("alt"));
				$("#pbz").val($("#"+kind+"_"+id).attr("id"));
				d_bz=id;
				goOK();
			}
			break;
	}
}
function goOK()
{
	if($("#gplx").val()!="")
	{
		$('#lx_ok').addClass("narrow_ok");
	}
	if($("#gplx").val()!="" && $("#zzyq").val()!="")
	{
		$('#yq_ok').addClass("narrow_ok");
	}
	if($("#gplx").val()!="" && $("#zzyq").val()!="" && $("#xzbz").val()!="")
	{
		$('#bz_ok').addClass("narrow_ok");
	}
}
function onloadOrderImg(id)
{
	new Image().src="price/"+id+"_selected.jpg";
}
function showmsg(id)
{
	alert($('#'+id).val());
}
function postOrder()
{
	if($('#gplx').val()=="")
	{
		alert("请选择『光盘类型』!");
		return false;
	}
	if($('#zzyq').val()=="")
	{
		alert("请选择『制作要求』!");
		return false;
	}
	if($('#xzbz').val()=="")
	{
		alert("请选择『选择包装』!");
		return false;
	}
	if($('#Num').val()=="")
	{
		alert("请填写『光盘数量』!");
		return false;
	}else if($('#Num').val() <100)
	{
		alert("『光盘数量』不能小于100!");
		return false;
	}else if($('#Num').val() >10000)
	{
		$.blockUI({ message: $('#question'), css: { width: '275px' } }); 
		return false;
	}
	if($('#gplx').val()!="" && $('#zzyq').val()!="" && $('#xzbz').val()!="" && $('#Num').val()!="")
	{
		$("#order_form").submit();
	}
	
}

//提交订单
function saveOrder()
{
	var reemail=/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/
	if($("#company").val()=="")
	{
		alert("公司名称不能为空！");
		return false;
	}
	if($("#username").val()=="")
	{
		alert("联系人不能为空！");
		return false;
	}
	if($("#cpmtel").val()=="")
	{
		alert("公司电话不能为空！");
		return false;
	}
	if($("#tel").val()=="")
	{
		alert("联系电话不能为空！");
		return false;
	}
/*	if($("#Email").val()=="" )
	{
		alert("Email不能为空或者不是正确的Email地址！");
		return false;
	}
	else if(!reemail.test($("#Email").val()))
	{
		alert("不是正确的Email地址！");
		return false;
	}*/
	if($("#company").val()!="" && $("#username").val()!="" && $("#cpmtel").val()!="" && $("#tel").val()!="")
	{
		$("#order_form").submit();
	}
	
}

//提交订单
function savemsg()
{
	if($("#company").val()=="")
	{
		alert("公司名称不能为空！");
		return false;
	}
	if($("#username").val()=="")
	{
		alert("联系人不能为空！");
		return false;
	}
	if($("#cpmtel").val()=="")
	{
		alert("公司电话不能为空！");
		return false;
	}
	if($("#tel").val()=="")
	{
		alert("联系电话不能为空！");
		return false;
	}
	if($("#msg").val()=="")
	{
		alert("内容不能为空！");
		return false;	
	}
	if($("#company").val()!="" && $("#username").val()!="" && $("#cpmtel").val()!="" && $("#tel").val()!="" && $("#msg").val()!="")
	{
		$("#msgform").submit();
	}
	
}
// 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 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;
									   }
									   
									}
								   );
}


//获取随机数
function GetRandomNum(minNum,maxNum)
{       
        var Rand = Math.random();
		return Rand*(maxNum-minNum)+minNum       
}

//添加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=4000; //图片停留时间(1000为1秒钟)//this param
                    var show_text=0; //是否显示文字标签 1显示 0不显示//this param
                    var txtcolor="000000"; //文字色

                    var bgcolor="DDDDDD"; //背景色


                    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);
}
function createFlash(ur,w,h){
document.write('<object classid="clsid:D27CDB6E-AE6D-11CF-96B8-444553540000" id="obj1" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,40,0" border="0" width="'+w+'" height="'+h+'">');
document.write('<param name="movie" value="'+ur+'">');
document.write('<param name="quality" value="high"> ');
document.write('<param name="wmode" value="transparent"> ');
document.write('<param name="menu" value="false"> ');
document.write('<embed src="'+ur+'" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" name="obj1" width="'+w+'" height="'+h+'" quality="High" wmode="transparent">');
document.write('</embed>');
document.write('</object>');
}
document.oncontextmenu=function(e){return false;}
