/*	
	Author: hesongling
	Date  : 03-03-2009
	Function : 
*/
//function:禁止js错误提示
function killerror()
{
	return true;	
}
window.onerror = killerror;

//设置url
function site_url(str)
{
	return "http://"+document.domain+"/" + str;	
}

var _selectArr=[];
function hideSelect(N){}

//获得对象函数
function _$(obj)
{
	return document.getElementById(obj);	
}

//类似CI的site_path
function site_path(str)
{
	return "http://"+document.domain+"/" + str;	
}


function controlmenu(obj,n)
{
	var str = '';
	for(var i= 1 ;i<=n;i++)
	{
		str = 'menu' + i.toString();
		_$(str).className = 'menu_hidden';			
	}
	_$(obj).className = '';
}

/*
	msg window
*/
 function sAlert(title,info,url)
 {
	var shield = document.createElement("DIV");
	shield.id = "shield";
	shield.style.position = "absolute";
	shield.style.left = "0px";
	shield.style.top = "0px";
	shield.style.width = "100%";
	shield.style.height = ((document.documentElement.clientHeight>document.documentElement.scrollHeight)?document.documentElement.clientHeight:document.documentElement.scrollHeight)+"px";
	shield.style.background = "#eee";
	shield.style.textAlign = "center";
	shield.style.zIndex = "10000";
	shield.style.filter = "alpha(opacity=0)";
	shield.style.opacity = 0;
	var dAlert = document.createElement("DIV");
	dAlert.id="alertFram";
	dAlert.style.width = '350px';
	dAlert.style.height = 'auto';
	dAlert.style.background = "#eee";
	dAlert.style.border = "1px #cccccc outset";
	dAlert.style.position = "absolute";
	dAlert.style.left = "30%";
	dAlert.style.top = "50%";
	dAlert.style.marginLeft = "0px" ;
	dAlert.style.marginTop = -115+document.documentElement.scrollTop+"px";
	dAlert.style.textAlign = "left";
	dAlert.style.zIndex = "10001";
	strHtml  = "<ul style=\"list-style:none; display:'block';float:none;margin:0px;padding:0px;width:100%;z-index:10000\">\n";
	strHtml += "<li style=\"background:#BD0062;display:'block';float:none;color:#fff;text-align:left;padding-left:10px;font-size:14px;font-weight:bold;height:25px;line-height:25px;border:1px solid #d6d6d6;\">"+ title +"</li>\n";
	strHtml += "<li style=\"background:#fff;display:'block';float:none;text-align:left;font-size:12px;line-height:20px;margin:0px; padding:0px;padding-left:40px;border-left:1px solid #ddd;border-right:1px solid #ddd;\">"+ info +"<br />&nbsp</li>\n";
	strHtml += "<li style=\"background:#fff;display:'block';float:none;text-align:center;font-weight:bold;height:30px;line-height:25px; padding-top:5px; \"><input type=\"button\" value=\"  OK  \" id=\"do_OK\" onclick=\"doOk()\"  style=\"background-color:#BD0062; border: #BD0062 inset 2px; color:#FFF;  width: 82px; height: 26px; margin: 0px 18px; border: none;  color: #FFFFFF; font-weight: bold; letter-spacing: 1px; \"/>";

	strHtml += "</li>\n";
	strHtml += "</ul>";
	dAlert.innerHTML = strHtml;
	//document.write(strHtml);
	document.body.appendChild(dAlert);
	document.body.appendChild(shield);
	this.setOpacity = function(obj,opacity){
		  if(opacity>=1)opacity=opacity/100;
		  try{ obj.style.opacity=opacity; }catch(e){}
		  try{ 
				 if(obj.filters.length>0 && obj.filters("alpha")){
						obj.filters("alpha").opacity=opacity*100;
				 }else{
						obj.style.filter="alpha(opacity=\""+(opacity*100)+"\")";
				 }
		  }catch(e){}
	}
	var c = 0;
	this.doAlpha = function(){
		  if (++c > 20){clearInterval(ad);return 0;}
		  setOpacity(shield,c);
	}
	var ad = setInterval("doAlpha()",1);
	this.doOk = function(){
		  document.body.removeChild(dAlert);
		  document.body.removeChild(shield);
		  //eSrc.focus();
		  	 hideSelect(1);
		  document.body.onselectstart = function(){return true;}
		  document.body.oncontextmenu = function(){return true;}
		  if(url) location.href = url;
	}
	this.doCancel = function(){
		  document.body.removeChild(dAlert);
		  document.body.removeChild(shield);
		  //eSrc.focus();
		  document.body.onselectstart = function(){return true;}
		  document.body.oncontextmenu = function(){return true;}
	}
	document.getElementById("do_OK").focus();
	//eSrc.blur();
	document.body.onselectstart = function(){return false;}
	document.body.oncontextmenu = function(){return false;}
}

//确认删除函数
function okdel()
{
	if(confirm('Are you sure to delete?'))
		return true;
	else
		return false;
}

/*
*	功能：利用ajax删除数据库中的记录
*	参数：id数据库中的id字段 table要删除的记录对应的数据表
*   返回值：无
*/
function ajaxdel(id,table,surl)
{
	if(id && table && okdel())
	{
		$.ajax({
				type: "POST",
				url: surl,
				data: "id="+id+"&table="+table,
				success: function(msg)
				{
					window.location.reload();
		   		}
			}); 
	}
}

  //删除图片函数
function de_image(id,surl,key,obj)
{
	$.ajax({
			type: "POST",
			url: surl,
			data: "id="+id +"&key="+ key,
			success: function(msg)
			{
				obj.parentNode.style.display = 'none';
			}
		}); 
}
 
var count = 1;
function uploadfile(str)
{
	//获得文件名并显	
	var filename = $("#"+str).val();
	_$("filelist").style.display = "";
	if(window.navigator.userAgent.toLowerCase().indexOf('msie') >= 0)
	{
		var arr = filename.split("\\");			
		filename = arr[arr.length-1]		
	}
	var divfile = "filecontent" + count.toString();
	var tmp = "<div style=\"display;''; cursor:pointer;\" id="+divfile+" ><img src='"+site_path('images/jpg.gif')+"' style=\"width:16px;\">&nbsp;"+filename+"&nbsp;&nbsp;<a href='javascript:delfile("+count+");'>Remove</a></div>";					
	$("#filelist").append(tmp);
	//隐藏并重新生成file表单
	count++;	
	var fileid = "myfile" + count.toString();
	$("#"+str).css("display","none");
	tmp = "<input type=\"file\" id='"+fileid+"' class='inputbox' name=\"photos[]\" onchange=\"uploadfile(this.id)\">";
	$("#fileform").append(tmp);
}

//删除文件
function delfile(str)
{
	var divid = "filecontent" + str.toString();
	var filefm = "#myfile" + str.toString();
	$("input").remove(filefm);
	_$("filelist").removeChild(_$(divid));	
}
/*
*	功能：实现弹出框
*/
function showWindow(strhtml,width,height,top,left)
{
	var shield = document.createElement("DIV");
	shield.id = "shield";
	shield.style.position = "absolute";
	shield.style.left = "0px";
	shield.style.top = "0px";
	shield.style.width = "100%";
	shield.style.height = ((document.documentElement.clientHeight>document.documentElement.scrollHeight)?document.documentElement.clientHeight:document.documentElement.scrollHeight)+"px";
	shield.style.background = "#eee";
	shield.style.textAlign = "center";
	shield.style.zIndex = "10000";
	shield.style.filter = "alpha(opacity=0)";
	shield.style.opacity = 0;

	var dAlert = document.createElement("DIV");
	dAlert.id="alertFram";
	dAlert.style.width = width + 'px';
	dAlert.style.height = height + 'px';
	dAlert.style.background = "#eee";
	dAlert.style.border = "1px #cccccc outset";
	dAlert.style.position = "absolute";
	left = (left)?left:"30%";
	top = (top)?top:"50%";
	dAlert.style.left = left;
	dAlert.style.top = top;
	dAlert.style.marginLeft = "0px" ;
	dAlert.style.marginTop = -115+document.documentElement.scrollTop+"px";
	dAlert.style.textAlign = "left";
	dAlert.style.zIndex = "10001";
	dAlert.innerHTML = strhtml;

	document.body.appendChild(dAlert);
	document.body.appendChild(shield);

	this.setOpacity = function(obj,opacity){
		  if(opacity>=1)opacity=opacity/50;
		  try{ obj.style.opacity=opacity; }catch(e){}
		  try{ 
				 if(obj.filters.length>0 && obj.filters("alpha")){
						obj.filters("alpha").opacity=opacity*100;
				 }else{
						obj.style.filter="alpha(opacity=\""+(opacity*100)+"\")";
				 }
		  }catch(e){}
	}

	var c = 0;
	this.doAlpha = function(){
		  if (++c > 20){clearInterval(ad);return 0;}
		  setOpacity(shield,c);
	}
	var ad = setInterval("doAlpha()",1);

	this.Close = function(){
	  document.body.removeChild(dAlert);
	  document.body.removeChild(shield);
	}
}


var popflag = 0 ;
function popWindow(strhtml,width,height,top,left,parentobj,sonobj,title)
{
	_$(parentobj).style.position = "absolute";
	_$(parentobj).style.left = "0px";
	_$(parentobj).style.top = "0px";
	_$(parentobj).style.background = "#eee";
	_$(parentobj).style.width = "100%";
	//_$(parentobj).style.height = ((document.documentElement.clientHeight>document.documentElement.scrollHeight)?document.documentElement.clientHeight:document.documentElement.scrollHeight)+"px";
	_$(parentobj).style.textAlign = "center";
	_$(parentobj).style.zIndex = "10000";
	_$(parentobj).style.filter = "alpha(opacity=0)";
	_$(parentobj).style.opacity = 0;

	_$(sonobj).style.width = width + 'px';
	//_$(sonobj).style.height = height + 'px';
	_$(sonobj).style.background = "#fff";
	_$(sonobj).style.border = "1px #cccccc outset";
	_$(sonobj).style.position = "absolute";
	left = (left)?left:"30%";
	top = (top)?top:"50%";
	_$(sonobj).style.left = left;
	_$(sonobj).style.top = top;
	_$(sonobj).style.marginLeft = "0px" ;
	_$(sonobj).style.marginTop = -115+document.documentElement.scrollTop+"px";
	_$(sonobj).style.textAlign = "left";
	_$(sonobj).style.zIndex = "10001";
	var parenthtml="<div id=\"customer\" style=\"width:"+ width +"px; height: "+ height +"px; margin: 0px auto; border: #000000 solid 1px; background-color:#FFF \">";
	parenthtml +="<div class=\"tt\" style=\"width: 100%; background: #E30011; color: #FFFFFF; font-size: 20px; float: left;\"><b style=\"float: left; margin: 2px 10px;\">"+ title +"</b><a href=\"javascript:void(0);\" style=\"float: right; margin: 6px 5px 0px 0px;\"><img onclick=\"hideSelect(1);_$('"+ parentobj +"').style.display = 'none';_$('"+ sonobj +"').style.display = 'none';\"  src='" + site_path('images/close1.gif') + "' /></a></div>";
    parenthtml +=strhtml;
    parenthtml +="</div>";
	_$(sonobj).innerHTML = parenthtml;
	
	_$(parentobj).style.display = '';
	_$(sonobj).style.display = '';

	this.setOpacity = function(obj,opacity){
		  if(opacity>=1)opacity=opacity/50;
		  try{ obj.style.opacity=opacity; }catch(e){}
		  try{ 
				 if(obj.filters.length>0 && obj.filters("alpha")){
						obj.filters("alpha").opacity=opacity*100;
				 }else{
						obj.style.filter="alpha(opacity=\""+(opacity*100)+"\")";
				 }
		  }catch(e){}
	}

	var c = 0;
	this.doAlpha = function(){
		  if (++c > 20){clearInterval(ad);return 0;}
		  setOpacity(parentobj,c);
	}
	var ad = setInterval("doAlpha()",1);

}

//自定义弹出框
function myPopWindow(strhtml,width,height,top,left,parentobj,sonobj,title)
{
	_$(sonobj).style.width = width + 'px';
	_$(sonobj).style.height = height + 'px';
	_$(sonobj).style.background = "";
	_$(sonobj).style.border = "";
	_$(sonobj).style.position = "absolute";
	left = (left)?left:"30%";
	top = (top)?top:"50%";
	_$(sonobj).style.left = left;
	_$(sonobj).style.top = top;
	_$(sonobj).style.marginLeft = "0px" ;
	_$(sonobj).style.marginTop = -115+document.documentElement.scrollTop+"px";
	_$(sonobj).style.textAlign = "left";
	_$(sonobj).style.zIndex = "10001";
	
	_$(sonobj).innerHTML = strhtml;
	
	_$(parentobj).style.display = '';
	_$(sonobj).style.display = '';

	this.setOpacity = function(obj,opacity){
		  if(opacity>=1)opacity=opacity/50;
		  try{ obj.style.opacity=opacity; }catch(e){}
		  try{ 
				 if(obj.filters.length>0 && obj.filters("alpha")){
						obj.filters("alpha").opacity=opacity*100;
				 }else{
						obj.style.filter="alpha(opacity=\""+(opacity*100)+"\")";
				 }
		  }catch(e){}
	}

	var c = 0;
	this.doAlpha = function(){
		  if (++c > 20){clearInterval(ad);return 0;}
		  setOpacity(parentobj,c);
	}
	var ad = setInterval("doAlpha()",1);

}


function chanel(num)
{
	for(var i=1;i<=3;i++)
	{
		if(i==num)
		{
			_$("chanel"+num.toString()).className = "ahover";
			_$("chanel_content"+num.toString()).style.display = "";
			_$('chanel' + i).style.color='#bd0062';
		}
		else
		{
			_$("chanel"+i.toString()).className = "normala";
			_$("chanel_content"+i.toString()).style.display = "none";
			_$('chanel' + i).style.color='';
		}
	}

}

function ForDight(Dight,How)  
{  
	Dight   = Math.round(Dight*Math.pow(10,How))/Math.pow(10,How);  
	return   Dight;  
}
function searchdroplist(str,category_id)
{
	var keywords = str.replace(/^\s*|\s*$/g,"");
	if(keywords)
	{
		$.ajax({
				   type: "POST",
				   url: site_url('search/searchdroplist'),
				   data: "keywords="+keywords+'&category_id='+category_id,
				   success: function(msg)
				   {
					   	if(msg)
						{
							_$("searchdrop").innerHTML = msg;
							_$("searchdrop").style.display = '';
						}
						else
							_$("searchdrop").style.display = 'none';
				   }
				}); 	
	}
}

function init(obj,str)
{
	var len = _$(obj).length;
	for(var i = 0 ;i<len;i++)
	{
		if(document.getElementById(obj)[i].value==str)
			document.getElementById(obj).selectedIndex = i;
	}
}

function ajaxGetColor(str)
{
	$.ajax({
		   type: "POST",
		   url: site_url('product/getColor'),
		   data: "id="+str,
		   success: function(msg){
			_$("pcolor").innerHTML = msg;
		   }
		}); 
}

function selectColor(str,color)
{
	$.ajax({
		   type: "POST",
		   url: site_url('product/getColorImage'),
		   data: "id="+str+"&color="+color,
		   success: function(msg){
			 var path = site_url('up_files/product/309/thumbnails/')+msg+'_340_400.jpg';
			 showGallery(getIDbyName(path));
			 init("color",color);
		   }
		}); 
}

        
		
		function correctPNG() // correctly handle PNG transparency in Win IE 5.5 & 6. 
		{ 
			var arVersion = navigator.appVersion.split("MSIE") 
			var version = parseFloat(arVersion[1]) 
			if ((version >= 5.5) && (document.body.filters)) 
			{ 
			   for(var j=0; j<document.images.length; j++) 
			   { 
				  var img = document.images[j] 
				  var imgName = img.src.toUpperCase() 
				  if (imgName.substring(imgName.length-3, imgName.length) == "PNG") 
				  { 
					 var imgID = (img.id) ? "id='" + img.id + "' " : "" 
					 var imgClass = (img.className) ? "class='" + img.className + "' " : "" 
					 var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' " 
					 var imgStyle = "display:inline-block;" + img.style.cssText 
					 if (img.align == "left") imgStyle = "float:left;" + imgStyle 
					 if (img.align == "right") imgStyle = "float:right;" + imgStyle 
					 if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle 
					 var strNewHTML = "<span " + imgID + imgClass + imgTitle 
					 + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";" 
					 + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader" 
					 + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" 
					 img.outerHTML = strNewHTML 
					 j = j-1 
				  } 
			   } 
			}    
		} 
		try{ window.attachEvent("onload", correctPNG);}catch(e){}
		
function dispProcessing(str)
{
    var div = document.createElement("div");
    div.innerHTML = str;
	div.id = "mengbandiv";
    div.style.background = "#ccc";
	if(document.all)
   		div.style.filter = "alpha(Opacity=60)";
	else
		div.style.MozOpacity= 0.3;
    div.style.width = "100%";
    div.style.height = "1940px";
    div.style.position = "absolute";
	div.style.top ='0px';
	div.style.left = '0px';
    div.style.zIndex = 10001;
    document.body.appendChild(div);
	document.body.style.cursor='wait';	
}

function hiddProcessing()
{
	document.body.removeChild(_$("mengbandiv"));
	document.body.style.cursor='';	
}

function subscribe(obj)
{
	if(obj)
	{
		 res = /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;
 		 var re = new RegExp(res);
		 if(_$(obj).value.match(re))
		 {
			$.ajax({
					type: "POST",
					url: site_url('home/newsletter'),
					data: "email="+_$(obj).value,
					success: function(msg)
					{
						if(msg == 1)
						{
							_$('send').style.display='';
							_$('send').innerHTML = 'Send Successfully!';
							_$('send').style.color='blue';
						}
						else
						{
							_$('send').style.display='';
							_$('send').innerHTML = 'You have already subscribed!';
							_$('send').style.color='red';
						}
					}
				});
		 }
		else
		 {
		 	 _$("send").style.display = '';
			 _$("send").style.color = "red";
			 _$("send").innerHTML = "Please enter valid email.";
		 }
	}

}
function searchs()
{
	if(_$('searchcategory').value =='all' && !_$('searchkey').value)
	{
		sAlert('Error','Please submit the keyword');
		return false;
	}
}
(function($){
$.fn.bgIframe = $.fn.bgiframe = function(s) {
	// This is only for IE6
	if ( $.browser.msie && /6.0/.test(navigator.userAgent) ) {
		s = $.extend({
			top     : 'auto', // auto == .currentStyle.borderTopWidth
			left    : 'auto', // auto == .currentStyle.borderLeftWidth
			width   : 'auto', // auto == offsetWidth
			height  : 'auto', // auto == offsetHeight
			opacity : true,
			src     : 'javascript:false;'
		}, s || {});
		var prop = function(n){return n&&n.constructor==Number?n+'px':n;},
		    html = '<iframe class="bgiframe"frameborder="0"tabindex="-1"src="'+s.src+'"'+
		               'style="display:block;position:absolute;z-index:-1;'+
			               (s.opacity !== false?'filter:Alpha(Opacity=\'0\');':'')+
					       'top:'+(s.top=='auto'?'expression(((parseInt(this.parentNode.currentStyle.borderTopWidth)||0)*-1)+\'px\')':prop(s.top))+';'+
					       'left:'+(s.left=='auto'?'expression(((parseInt(this.parentNode.currentStyle.borderLeftWidth)||0)*-1)+\'px\')':prop(s.left))+';'+
					       'width:'+(s.width=='auto'?'expression(this.parentNode.offsetWidth+\'px\')':prop(s.width))+';'+
					       'height:'+(s.height=='auto'?'expression(this.parentNode.offsetHeight+\'px\')':prop(s.height))+';'+
					'"/>';
		return this.each(function() {
			if ( $('> iframe.bgiframe', this).length == 0 )
				this.insertBefore( document.createElement(html), this.firstChild );
		});
	}
	return this;
};
})(jQuery);
$(document).ready(function() {  
try{
  $('#attachdiv').bgiframe();  
  }catch(e){}
});


function searchs1()
{
	if((_$('searchcategory1').value =='all' && _$('searchkey1').value =='') || (_$('searchcategory1').value =='item' && _$('searchkey').value ==''))
	{
		sAlert('Error','Please submit the keyword');
		return false;
	}
}
function getItem1(obj)
{

	var searchkey = _$('searchkey1');
	searchkey.onkeyup = function()
	{
		if(_$('searchcategory1').value != 'all')searchdroplist(searchkey.value,_$('searchcategory1').value);
	}
}

function getItem(obj)
{
	var searchkey = _$('searchkey');
	searchkey.onkeyup = function()
	{
		if(_$('searchcategory').value != 'all')searchdroplist(searchkey.value,_$('searchcategory').value);
	}
}

function searchs()
{
	if((_$('searchcategory').value =='all' && _$('searchkey').value =='') || (_$('searchcategory').value =='item' && _$('searchkey').value ==''))
	{
		sAlert('Error','Please submit the keyword');
		return false;
	}
}

$(function(){
	$("#navigation ul li:has(ul)").hover(function(){
		 $(this).children("a").addClass("a1");
		$(this).children("ul").stop(true,true).slideDown("normal");
	},function(){
		 $(this).children("a").removeClass("a1");
		$(this).children("ul").stop(true,true).slideUp("fast");
	});
})

$(function(){
     var len  = $(".num > li").length;
	 var index = 0;
	 var adTimer;
	 $(".num li").mouseover(function(){
		index  =   $(".num li").index(this);
		showImg(index);
	 }).eq(0).mouseover();	 
	 $('.ad').hover(function(){
			 clearInterval(adTimer);
		 },function(){
			 var next=true;
			 adTimer = setInterval(function(){
			    showImg(index);
				if (next){index++;}else{index--;} 
				if(index==len){next=false;index-=2;}else if(index==0){next=true;}
			  } , 5000);
	 }).trigger("mouseleave");
}) 
function showImg(index){
   		var adHeight = $(".banner").width(); 
		$(".slider").stop(true,false).animate({left : -adHeight*index},1000); 
		$(".num li").removeClass("on")
			.eq(index).addClass("on");
}

