/****
 * 功能描述 : 商城JS FUNCTION
 * 作	者 : qingkuangs
 * 日   期 : 2007-11-01
 *
****/

var xmlhttp = new HTTPRequest();
function check_wish_gift(id, name, type) 
{
	 if(confirm("您确认许愿 "+name+"？")){
		xmlhttp.open("/wish/wish_thing.php");
		xmlhttp.send("itemid=" + id + "&itemname=" + encodeURIComponent(name) + "&itemtype=" + type + "&act=add");
		//alert(xmlhttp.response);
		if(xmlhttp.response == -999){
           alert("您尚未登入，请先登入！  ");
           location.href = '/signup.php?f=/shop/furniture/giftshop.php';
        }else if(xmlhttp.response == "wish_ok") 
	       alert("许愿成功！！！");
        else if(xmlhttp.response == "wish_having")
	      alert("此物品已经在您的许愿盒中了！");
	    else if(xmlhttp.response == "wish_fail")
	       alert("许愿失败，请重试！");
	    else
	       alert("无效操作"); 
	 }
}


function try_audio(item_id)
{
	var audio = document.getElementById("audioDiv");
	while(audio.lastChild) {
		audio.removeChild(audio.lastChild);
	}
	var music = document.createElement("embed");
	music.id = "MUSIC_" + item_id;
	music.name = "MUSIC_" + item_id;
	music.src = "/music/" + item_id + ".mid";
	music.hidden = "true";
	music.autostart = "true";
	music.loop = "true";
	audio.appendChild(music);
}

//--[ 白金VIP领取 ]--//
function fnGetGift(gift_name, gift_id)
{
   if(confirm("您确认领取 "+ gift_name + "吗?")) {
      xmlhttp.open("/shop/furniture/giftshop_vip_monthly_gift_get.php");
      xmlhttp.send("sp_gift_id=" + gift_id);
      if(xmlhttp.response == 1){
        alert("领取成功");
      } else if(xmlhttp.response == -1) {
	alert("您尚未登入,请先登入!");
	window.location  = "/signup.php?f=/shop/furniture/giftshop_vip.php";
      } else if(xmlhttp.response == -2) {
	alert("当月您已经领取了5样礼物了!");
      } else if(xmlhttp.response == -3) {
	alert("您还不是白金VIP!");
      } else {
	alert("领取失败");
      }
   }
}

function check_recommendation(id,g_type) {
  document.getElementById("g").value = g_type;
  document.getElementById("d").value = id;
  document.avatar_form.action = "/shop/room_recommendation.php";
  document.avatar_form.target = "_top";
  document.avatar_form.submit();
}

function check_present(id,type,g_type,u) {
	if(u > 0)
		var newW = window.open("/shop/present/present.php?g=" + g_type + "&t=" + type + "&d=" + id + "&u=" + u,'present',"");
	else
		var newW = window.open("/shop/present/present.php?g=" + g_type + "&t=" + type + "&d=" + id,'present',"");
	newW.focus();
}

function check_transfer(id,type,g_type,u) {
	if(u > 0)
		var newW = window.open("/shop/present/transfer.php?g=" + g_type + "&t=" + type + "&gid=" + id + "&u=" + u,'transfer',"");
	else
		var newW = window.open("/shop/present/transfer.php?g=" + g_type + "&t=" + type + "&gid=" + id,'transfer',"");
	newW.focus();
}

function check_otherbuy(id,type,g_type) {
  document.getElementById("g").value = g_type;
  document.getElementById("t").value = type;
  document.getElementById("d").value = id;
  document.avatar_form.action = "/shop/room_otherbuy.php";
  document.avatar_form.target = "_top";
  document.avatar_form.submit();
}
function check_wish_avatar(id, name, type) 
{
	 if(confirm("您确认许愿 "+name+"？")){
		xmlhttp.open("/wish/wish_thing.php");
		 xmlhttp.send("g=a&t=" + type + "&d=" + id + "&act=add");
		//alert(xmlhttp.response);
		if(xmlhttp.response == -999){
           alert("您尚未登入，请先登入！  ");
           document.getElementById("f").value = "/shop/avatar/avatar.php";
           document.sign_form.action = "/signup.php";
           document.sign_form.target = "_top";
           document.sign_form.submit();
           //location.href = '/signup.php?f=/avatar/avatar.php';
        }else if(xmlhttp.response == "wish_ok") 
	       alert("许愿成功！！！");
        else if(xmlhttp.response == "wish_having")
	      alert("此物品已经在您的许愿盒中了！");
	    else if(xmlhttp.response == "wish_fail")
	       alert("许愿失败，请重试！");
	    else
	       alert("无效操作"); 
	 }
}
//--[ 购买礼物 ]--//
function fnBuy_gift(id) {
	var newW = window.open("/shop/buy/giftshop_buyGift.php?item_id=" + id + "",'buyGift',"height=207,width=450,status=yes,toolbar=no,menubar=no,location=no");
	newW.focus();
}

function fnBuy_avatar(id) {
	var newW = window.open("/shop/buy/giftshop_buyAvatar.php?item_id=" + id + "",'buyAvatar',"height=207,width=450,status=yes,toolbar=no,menubar=no,location=no");
	newW.focus();
}

function fnBuy_Pick(id) {
	window.location.href= "/shop/pick/pick_buy_check.php?item_id=" + id;
	//newW.focus();
}
function fnBuy_model(id) {
	var newW = window.open("/shop/buy/giftshop_buyModel.php?item_id=" + id + "",'buyModel',"height=211,width=450,status=yes,toolbar=no,menubar=no,location=no");
	newW.focus();
}
function fnBuy_pet(type,id) {
	var newW = window.open("/shop/buy/giftshop_buyPetAcc.php?item_type=" + type + "&item_id=" + id + "",'buyPet',"height=207,width=450,status=yes,toolbar=no,menubar=no,location=no");
	newW.focus();
}
function fnRelet_pet(id) {
	var newW = window.open("/shop/buy/giftshop_reletPetAcc.php?data_id=" + id + "",'reletPet',"height=238,width=385,status=yes,toolbar=no,menubar=no,location=no");
	newW.focus();
}
function fnRelet_avatar(item_id,id) {
	var newW = window.open("/shop/buy/giftshop_reletAvatar.php?item_id=" + item_id + "&id=" + id + "",'reletAvatar',"height=238,width=385,status=yes,toolbar=no,menubar=no,location=no");
	newW.focus();
}
function getNeedPoint(lifedays,price) {
	if(lifedays != 30) {
		month = lifedays / 30;
		price = month * (1 - month/15) * price;
		return Math.floor(price);
	} else {
		return price;
	}
}

function fnBuy_room(id, name) {
  if(confirm("您确认购买 "+name+"？")){
    xmlhttp.open("/room/room_buyRoom.php");

    xmlhttp.send("item_id=" + id);
	//alert(xmlhttp.response);
	if(xmlhttp.response == -999){
    alert("您尚未登入，请先登入！  ");
	  location.href = '/signup.php?f=/room/room_select.php';
	}else if(xmlhttp.response == 1) 
    alert("购买成功！！！");
	else if(xmlhttp.response == 0)
	  alert("购买失败，请重试！");
	else if(xmlhttp.response == -1)
	  alert("对不起，您的I币不足，无法使用！");
  else if(xmlhttp.response == -2)
    alert("无此房型！");
  else if(xmlhttp.response == -3)
    alert("您已经拥有此房型！");
	else
	  alert("无效操作"); 
  }
}


function collect_superboy(id) {
	var newW = window.open("/html/action/070827/superboy_collectDeal.php?id=" + id + "",'superboy',"height=192,width=330,status=yes,toolbar=no,menubar=no,location=no");
	newW.focus();
}
function pick_preview(id) {
	var newW = window.open("/shop/pick/preview/" + id + ".html",'pick_preview',"height=500,width=568,status=yes,toolbar=no,menubar=no,location=no");
	newW.focus();
}

function pick_vip_preview(id) {
	var newW = window.open("/shop/pick/preview/vip_" + id + ".html",'pick_preview',"height=500,width=568,status=yes,toolbar=no,menubar=no,location=no");
	newW.focus();
}

function exchange_gift_step(type,item_id) {
	top.window.location = "/html/action/071127/exchange_gift_step2.php?item_type=" + type + "&item_id=" + item_id + "&life_days=30";
}

String.prototype.trim = function() {
    // 用正则表达式将前后空格
    // 用空字符串替代。
    return this.replace(/(^\s*)|(\s*$)/g, "");
}

