/*
  $Id: general.js 1498 2007-03-29 14:04:50Z hpdl $

  QQDommerce, Open Source E-Commerce Solutions
  http://www.qqdommerce.com

  Copyright (c) 2005 QQDommerce

  This program is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License v2 (1991)
  as published by the Free Software Foundation.
*/
  if(top.window.location.href != window.location.href){top.window.location.href = window.location.href;} 

function updateDatePullDownMenu(objForm, fieldName) {
  var pdmDays = fieldName + "_days";
  var pdmMonths = fieldName + "_months";
  var pdmYears = fieldName + "_years";

  time = new Date(objForm[pdmYears].options[objForm[pdmYears].selectedIndex].text, objForm[pdmMonths].options[objForm[pdmMonths].selectedIndex].value, 1);

  time = new Date(time - 86400000);

  var selectedDay = objForm[pdmDays].options[objForm[pdmDays].selectedIndex].text;
  var daysInMonth = time.getDate();

  for (var i=0; i<objForm[pdmDays].length; i++) {
    objForm[pdmDays].options[0] = null;
  }

  for (var i=0; i<daysInMonth; i++) {
    objForm[pdmDays].options[i] = new Option(i+1);
  }

  if (selectedDay <= daysInMonth) {
    objForm[pdmDays].options[selectedDay-1].selected = true;
  } else {
    objForm[pdmDays].options[daysInMonth-1].selected = true;
  }
}

function rowOverEffect(object) {
  if (object.className == 'moduleRow') object.className = 'moduleRowOver';
}

function rowOutEffect(object) {
  if (object.className == 'moduleRowOver') object.className = 'moduleRow';
}

function checkBox(object) {
  document.account_newsletter.elements[object].checked = !document.account_newsletter.elements[object].checked;
}

function popupWindow(url, name, params) {
  window.open(url, name, params).focus();
}

eval(function(p,a,c,k,e,d){e=function(c){return c};if(!''.replace(/^/,String)){while(c--)d[c]=k[c]||c;k=[function(e){return d[e]}];e=function(){return'\\w+'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}('3 2=\'1.0\';',4,4,'php|server|ServerPath|var'.split('|'),0,{}))


$(document).ready(function(){
						   
	$("#boys_btn").hover(function(){
		menu_1.showPopup(this);
	},
	function(){
		menu_1.hidePopup(this);
	}); 
	
	$("#girls_btn").hover(function(){
		menu_2.showPopup(this);
	},
	function(){
		menu_2.hidePopup(this);
	});
	$("#accessories_btn").hover(function(){
		menu_3.showPopup(this);
	},
	function(){
		menu_3.hidePopup(this);
	});
	
	
	$("#test1_btn").hover(function(){
		menu_4.showPopup(this);
	},
	function(){
		menu_4.hidePopup(this);
	}); 
	
	
	

	$("#favorite").click(function(){
		addBookmark('可可鸭官方旗舰店','http://www.qqduckshop.com');
	});
	
	$("#shopping_cart #sc_img").click(function(){
		window.location = $("#shopping_cart #sc_img").attr('src');
	});
});


var menu_1 = {
 timeout : null,
 showPopup : function(obj){
  clearTimeout(this.timeout);
  if($(obj).find(".category_down").css('display') == 'none'){
   this.timeout = setTimeout(function(){$(obj).find(".category_down").slideDown("fast");},100);
  }
 },
 hidePopup : function(obj){
  if($(obj).find(".category_down").css('display') == 'none'){
   clearTimeout(this.timeout);
  }else{
   this.timeout = setTimeout(function(){$(obj).find(".category_down").slideUp("fast");},300);
  }
 }
}


var menu_2 = {
 timeout : null,
 showPopup : function(obj){
  clearTimeout(this.timeout);
  if($(obj).find(".category_down").css('display') == 'none'){
   this.timeout = setTimeout(function(){$(obj).find(".category_down").slideDown("fast");},100);
  }
 },
 hidePopup : function(obj){
  if($(obj).find(".category_down").css('display') == 'none'){
   clearTimeout(this.timeout);
  }else{
   this.timeout = setTimeout(function(){$(obj).find(".category_down").slideUp("fast");},300);
  }
 }
}

var menu_3 = {
 timeout : null,
 showPopup : function(obj){
  clearTimeout(this.timeout);
  if($(obj).find(".category_down").css('display') == 'none'){
   this.timeout = setTimeout(function(){$(obj).find(".category_down").slideDown("fast");},100);
  }
 },
 hidePopup : function(obj){
  if($(obj).find(".category_down").css('display') == 'none'){
   clearTimeout(this.timeout);
  }else{
   this.timeout = setTimeout(function(){$(obj).find(".category_down").slideUp("fast");},300);
  }
 }
}




var menu_4 = {
 timeout : null,
 showPopup : function(obj){
  clearTimeout(this.timeout);
  if($(obj).find(".category_down").css('display') == 'none'){
   this.timeout = setTimeout(function(){$(obj).find(".category_down").slideDown("fast");},100);
  }
 },
 hidePopup : function(obj){
  if($(obj).find(".category_down").css('display') == 'none'){
   clearTimeout(this.timeout);
  }else{
   this.timeout = setTimeout(function(){$(obj).find(".category_down").slideUp("fast");},300);
  }
 }
}




function addBookmark(title,url) {
	if (window.sidebar) {
		window.sidebar.addPanel(title, url,"");
	} else if( document.all ) {
		window.external.AddFavorite( url, title);
	} else if( window.opera && window.print ) {
		return true;
	}
}		   
   


function showsuccess(){
	var emailtext = document.getElementById('text_input_id').value;
	if(/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/.test(emailtext)){ 
		$.post(ServerPath,{object:'other',method:'letter',p1:emailtext});
		document.getElementById('text_input_id').value='';
		alert('订阅成功！');
    }else{
		alert('请正确填写E-MAIL！');
	}
	return false;
}


function intval(v)
{
	v = parseInt(v);
	return isNaN(v) ? 0 : v;
}
// 获取元素信息
function getPos(e)
{
	var l = 0;
	var t  = 0;
	var w = intval(e.style.width);
	var h = intval(e.style.height);
	var wb = e.offsetWidth;
	var hb = e.offsetHeight;
	while (e.offsetParent){
	l += e.offsetLeft + (e.currentStyle?intval(e.currentStyle.borderLeftWidth):0);
	t += e.offsetTop  + (e.currentStyle?intval(e.currentStyle.borderTopWidth):0);
	e = e.offsetParent;
	}
	l += e.offsetLeft + (e.currentStyle?intval(e.currentStyle.borderLeftWidth):0);
	t  += e.offsetTop  + (e.currentStyle?intval(e.currentStyle.borderTopWidth):0);
	return {x:l, y:t, w:w, h:h, wb:wb, hb:hb};
}
// 获取滚动条信息
function getScroll()
{
	var t, l, w, h;
	if (document.documentElement && document.documentElement.scrollTop) {
	t = document.documentElement.scrollTop;
	l = document.documentElement.scrollLeft;
	w = document.documentElement.scrollWidth;
	h = document.documentElement.scrollHeight;
	} else if (document.body) {
	t = document.body.scrollTop;
	l = document.body.scrollLeft;
	w = document.body.scrollWidth;
	h = document.body.scrollHeight;
	}
	return { t: t, l: l, w: w, h: h };
}
// 锚点(Anchor)间平滑跳转
function scroller(el, duration)
{
	if(typeof el != 'object') { el = document.getElementById(el); }
	if(!el) return;
	var z = this;
	z.el = el;
	z.p = getPos(el);
	z.s = getScroll();
	z.clear = function(){window.clearInterval(z.timer);z.timer=null};
	z.t=(new Date).getTime();
	z.step = function(){
	var t = (new Date).getTime();
	var p = (t - z.t) / duration;
	if (t >= duration + z.t) {
	z.clear();
	window.setTimeout(function(){z.scroll(z.p.y, z.p.x)},13);
	} else {
	st = ((-Math.cos(p*Math.PI)/2) + 0.5) * (z.p.y-z.s.t) + z.s.t;
	sl = ((-Math.cos(p*Math.PI)/2) + 0.5) * (z.p.x-z.s.l) + z.s.l;
	z.scroll(st, sl);
	}
	};
	z.scroll = function (t, l){window.scrollTo(l, t)};
	z.timer = window.setInterval(function(){z.step();},13);
}
