﻿
function getMinMaxCount(f,gid,sid){
	var pid = parseInt(f.pid.value);
	if(!pid)
		return;

	$.get("/ajax/product.cfm?gid="+gid+"&sid="+sid+"&pid="+pid, function(data){
		var arr = data.split(",");
		f.pMin.value = arr[0];
		f.pMax.value = arr[1];
		f.hidType.value = f.pid.options[f.pid.selectedIndex].text;
	});
}

function cheangelevel(f,type){
	var begin = parseInt(f.beginLevel.value);
	var end = parseInt(f.endLevel.value);
	if(type == 1){
		if(begin>=end)
		{
			alert('Sorry,the price calculation is failed.\nPlease try again!');
			f.beginLevel.value =document.getElementById("hidstart").value;
			return ;
		}else
		{
			f.beginLevel.blur();
			document.getElementById("hidstart").value=begin;
		}
	}else if(type == 2){
		if(end<=begin)
		{
			alert('Sorry,the price calculation is failed.\nPlease try again!');
			f.endLevel.value=document.getElementById("hidend").value
			return ;
		}else{
			f.endLevel.blur();
			document.getElementById("hidend").value=end;
		}
	}
	else{
		if(begin >= end){
		alert("Sorry,the price calculation is failed.\nPlease check your selected level.");
		return;	
		}
	}
	var skillType = 0 ;
	try{
	  skillType = f.skillType.value;
	}catch(ex){}

	
	if( skillType!=0)
	{
		$.get("/ajax/ajaxpowerleveling.cfm",{startLevel:begin,endLevel:end,rate:f.hidrate.value,pid:f.pid.value,skillType:skillType},function(data){
			var	arr=data.split("|");
			$("#pricedataspan").html(arr[0]);
			$("#timedataspan").html(arr[1]);
			$("#hidPowerPrice").val(arr[0]);
			$("#hidPowerTime").val(arr[1]);
		});
	}
	else
	{
		$.get("/ajax/ajaxpowerleveling.cfm",{startLevel:begin,endLevel:end,rate:f.hidrate.value,pid:f.pid.value},function(data){
			var	arr=data.split("|");
			$("#pricedataspan").html(arr[0]);
			$("#timedataspan").html(arr[1]);
			$("#hidPowerPrice").val(arr[0]);
			$("#hidPowerTime").val(arr[1]);
		});
	}
}

/*筛选服务器*/
function searchServer(s){
	var arrServers = $("ul.producttag").nextAll();
	var obj = null;
	if(typeof(s) == "undefined"){
		arrServers.removeClass("jsHide");
	}
	else{
		$.each(arrServers, function(i,o){
			obj = $(o);
			if(obj.text().substring(0,1).toUpperCase() == s)
				obj.removeClass("jsHide");
			else
				obj.addClass("jsHide");
		})
	}
}

/*装备服务器页面*/
global_pro_id = -1;
function switchMenu(i){	
	var sub_li = "#item_"+i;
	var pro = "#pro_"+i;
	var obj = $(sub_li);
	//$("ul.zhan2").hide();//隐藏所有的子类
	if( global_pro_id == i ){
		obj.hide();
		$(pro).removeClass("typeOpen").addClass("typeClose");
		global_pro_id = -1;
	}
	else {
		obj.show();
		$(pro).removeClass("typeClose").addClass("typeOpen");
		global_pro_id = i;
	}
}

var isUpdateLeve = false;

//设置
function setPName(){
    //if($("#product_Name").val().length < 1) return ;
	$("#PNameTxt").val($("#product_Name").val());
	$("#PNameTag").val("true");
//	eval($("#hidAutoonclick").val());
	//var tid = document.getElementById("hidtid").value;
	document.getElementById("hidpid").value = 0;
	document.getElementById("selByPrice").value = 0;
	document.getElementById("selByLevel").value = 0;
	document.getElementById("jumpMenu2").value;
	document.getElementById("pitid").value = 0;
	isUpdateLeve = true;
	ItemToPage(1);
}

function showGameInfo(){
	$("#selectGame").text($("#specialGames>option:selected").text());
	$("#selectServer").text($("#specialServers>option:selected").text());
}

function getData(){
	var gid = parseInt($("#specialGames").val());
	var sid = parseInt($("#specialServers").val());
	var cid = parseInt($("#jumpMenu2").val());
	var obj = $("#loadProduct");
	//alert(gid);alert(sid);alert(cid)
	if(!gid || !sid){
		return;	
	}
	else{
		showGameInfo();		
	}
	
	$.ajax({
		type: "GET",
		url: "/ajax/loadGold.cfm",
		data: "gameid="+gid+"&serverid="+sid+"&curid="+cid,
		beforeSend: function(){
			obj.html("").addClass("ajaxLoader");
		},
		success: function(data){
			obj.removeClass("ajaxLoader").html(data).css("display","none").fadeIn("fast");
			initButtonStyle();
		}
	});
}

function getFastOrderCount(f){
	var pid = parseInt(f.pid.value);
	if(!pid)
		return;
	
	var gid = parseInt($("#specialGames").val());
	var sid = parseInt($("#specialServers").val());

	if(!gid || !sid){
		alert("Please select Game and Server");	
		return;
	}

	$.get("/ajax/product.cfm?gid="+gid+"&sid="+sid+"&pid="+pid, function(data){
		if(!data)
			return;
		var arr = data.split(",");
		f.pMin.value = arr[0];
		f.pMax.value = arr[1];
		f.hidType.value = f.pid.options[f.pid.selectedIndex].text;
		f.GameID.value = gid;
		f.Sid.value = sid;
		f.quantity.value = "";
	});		
}

function showFastOrder(gid,ptype){
	if(!gid || !ptype)
		return;
		
	$.get("/ajax/product.cfm?gid="+gid+"&ptype="+ptype,function(data){
		var dom = document.getElementById("selType");
		while(dom.options.length > 0){
			dom.remove(0);
		}	

		var opt = document.createElement("OPTION");
		var arr = data.split(",");
		opt.text = "--Please Select--";
		opt.value = "0";
		dom.options.add(opt);
		opt.selected = true;
		
		if(data){
			opt = null;
			opt = document.createElement("OPTION");
			opt.value = arr[0];
			opt.text = arr[1];
			dom.options.add(opt);
			
			$("#CustomOrder").css("display","");
		}
		else{
			$("#CustomOrder").css("display","none");	
		}
		
	});
}

function getProductType(gid,tid){
	if(!parseInt(gid) || !parseInt(tid)){
		return;	
	}
	$.get("/ajax/specialProduct.cfm?gameid="+gid+"&tid="+tid, function(data){
		var jStr = eval("("+ data +")");
		var dom = document.getElementById("productType");
		while(dom.options.length > 0){
			dom.remove(0);
		}
		var opt = document.createElement("OPTION");
		opt.text = "--Please Select--";
		opt.value = "0";
		dom.options.add(opt);
		opt.selected = true;
		if(data != null){
			$.each(jStr.DATA, function(i,n){			
				opt = document.createElement("OPTION");
				opt.value = n[1];
				opt.text = n[0];
				dom.options.add(opt);						   
			});

		}
	});
}

function getPLData(curid){
	var gid = parseInt(document.getElementById("specialGames").value);
	var pid = parseInt(document.getElementById("productType").value);
	var cid = 2;
	var obj = $("#loadProduct");
	if(!gid || !pid)
		return;
	if(typeof(curid) != "undefined")
		cid = curid;

		//document.write("gameid="+gid+"&curid="+cid+"&pid="+pid);
		//return ;
	$.ajax({
		type: "GET",
		url: "/ajax/loadPL.cfm",
		data: "gameid="+gid+"&curid="+cid+"&pid="+pid,
		beforeSend: function(){
			obj.html("").addClass("ajaxLoader");
		},
		success: function(data){
			obj.removeClass("ajaxLoader").html(data).css("display","none").fadeIn("fast");
			initButtonStyle();
		}
	});
}

function getItemData(){
	var gid = parseInt(document.getElementById("specialGames").value);
	var sid = -1;//parseInt(document.getElementById("specialServers").value);
	var pid = parseInt(document.getElementById("productType").value);
	var cid = parseInt($("#jumpMenu2").val());
	var obj = $("#loadProduct");

	if(!gid || !sid || !pid){
		return;
	}
	else{
		showGameInfo();	
	}
	//document.write("/ajax/loadItem.cfm?"+"gameid="+gid+"&curid="+cid+"&pid="+pid+"&serverid="+sid)
	$.ajax({
		type: "GET",
		url: "/ajax/loadItem.cfm",
		data: "gameid="+gid+"&curid="+cid+"&pid="+pid+"&serverid="+sid,
		beforeSend: function(){
			obj.html("").addClass("ajaxLoader");
		},
		success: function(data){
			obj.removeClass("ajaxLoader").html(data).css("display","none").fadeIn("fast");
			initButtonStyle();
		}
	});
}

function getCdkeyData(){
	var gid = parseInt(document.getElementById("specialGames").value);
	var cid = parseInt($("#jumpMenu2").val());
	var obj = $("#loadProduct");
	if(!gid){
		return;
	}
	else{
		showGameInfo();	
	}
	$.ajax({
		type: "GET",
		url: "/ajax/loadCdkey.cfm",
		data: "gameid="+gid+"&curid="+cid,
		beforeSend: function(){
			obj.html("").addClass("ajaxLoader");
		},
		success: function(data){
			obj.removeClass("ajaxLoader").html(data);
			$("#page_1").css("display","");
			initButtonStyle();
		}
	});
}

function toPage(iPage){
	var cdk = $("div.cdktext");
	var len = cdk.length;
	iPage = parseInt(iPage) - 1;
	$.each(cdk,function(i,o){
		if(iPage == i)
			$(o).css("display","");
		else
			$(o).css("display","none");
	});
	
}


/*分页*/
function ItemToPage(page)
{
	var serverid= document.getElementById("hidserverid").value;
	var tid = document.getElementById("hidtid").value;
	var pid=document.getElementById("hidpid").value;
	var GameID=document.getElementById("hidGameID").value;
//	var curid=document.getElementById("hidcurid").value;
	var ByPrice=document.getElementById("selByPrice").value;
	var ByLevel=document.getElementById("selByLevel").value;
	var curid=document.getElementById("jumpMenu2").value;
	var pitid=document.getElementById("pitid").value;
	
	var PName = "";
	if($("#PNameTag").val() == "true"){
		PName = $.trim($("#PNameTxt").val());
		$("#product_Name").val(PName);
	}
	
//document.write("/ajax/ItemToPage.cfm?"+"gameid="+GameID+"&curid="+curid+"&serverid="+serverid+"&tid="+tid+"&pid="+pid+"&page="+page+"&priceSort="+ByPrice+"&level="+ByLevel+"&pitid="+pitid);

	var obj = $("#loadProduct");
	$.ajax({
		type: "GET",
		url: "/ajax/ItemToPage.cfm",
		data: "gameid="+GameID+"&curid="+curid+"&serverid="+serverid+"&tid="+tid+"&pid="+pid+"&page="+page+"&priceSort="+ByPrice+"&level="+ByLevel+"&pitid="+pitid+"&PName="+PName,
		beforeSend: function(){
			obj.html("").addClass("ajaxLoader");
		},
		success: function(data){
			obj.removeClass("ajaxLoader").html(data);
			$("#page_1").css("display","");
			initButtonStyle();
			if(isUpdateLeve){
				updateLeve();
		 	}
			isUpdateLeve = false;
			if(GameID == 17 || GameID == 43 && tid == 2){
				jQuery(document).ready(function(){
					jQuery(".enlarge").Zoomer({speedView:200,speedRemove:400,altAnim:true,width:50,height:50,debug:false});	
				});
			}
		}
	});
}

function getItemDataNew(pid,pitid,objID,objtoID){
	var gid = parseInt(document.getElementById("hidGameID").value);
	var sid = parseInt(document.getElementById("hidserverid").value);	
	var tid = parseInt(document.getElementById("hidtid").value);
	var cid = parseInt($("#jumpMenu2").val());
	document.getElementById("hidpid").value = pid;
	document.getElementById("pitid").value = pitid;
	var obj = $("#loadProduct");
	if(!gid || !sid || !pid){
		return;
	}
	else{
		//showGameInfo();	
	}
	$("#selByPrice").val(0);
	$("#selByLevel").val(0);

	var oldKey = $("#hidkeyWord").val();
	var newKey = $("#"+objID).text()  ;
	if(objtoID != "" && objtoID != " "){
		newKey += " - " + $("#"+objtoID).text();
	}

	var oldcp = $("#hidcurrentProductNamed").val();
	var newcp = $("#"+objID).text()  ;
	
	$("#writing").html($("#writing").html().replace( new RegExp(oldKey,"gm") ,newKey));
	$("#navigation").html($("#navigation").html().replace( new RegExp(oldcp,"gm") ,newcp));

	$("#hidkeyWord").val(newKey);
	$("#hidcurrentProductNamed").val(newcp);

	var PName = "";
	if($("#PNameTag").val() == "true"){
		PName = $.trim($("#PNameTxt").val());
		$("#product_Name").val(PName);
	}

//	 alert("gameid="+gid+"&curid="+cid+"&pid="+pid+"&serverid="+sid+"&tid"+tid);
//document.write("/ajax/loadProductItem.cfm?"+"gameid="+gid+"&curid="+cid+"&pid="+pid+"&serverid="+sid+"&tid"+tid+"&pitid="+pitid);
	$.ajax({
		type: "GET",
		url: "/ajax/loadProductItem.cfm",
		data: "gameid="+gid+"&curid="+cid+"&pid="+pid+"&serverid="+sid+"&tid"+tid+"&pitid="+pitid+"&PName="+PName,
		beforeSend: function(){
			obj.html("").addClass("ajaxLoader");
		},
		success: function(data){
			obj.removeClass("ajaxLoader").html(data).css("display","none").fadeIn("fast");
			initButtonStyle();
			// update level
			updateLeve();
					if(gid == 17 || gid == 43 && tid == 2){
								jQuery(document).ready(function(){
	jQuery(".enlarge").Zoomer({speedView:200,speedRemove:400,altAnim:true,width:50,height:50,debug:false});	
});
			}	
		}
	});
}

function updateLeve(){
	// update level
	var dom = document.getElementById("selByLevel");
	while(dom.options.length > 0){
		dom.remove(0);
	}
	var opt = document.createElement("OPTION");
	var arr = $("#hidlevelList").val().split(",");
	opt.text = "--Please Select--";
	opt.value = "0";
	dom.options.add(opt);
	opt.selected = true;
	for(var i = 0 ; i < arr.length ; i++){
		if(parseInt(arr[i])){
			opt = null;
			opt = document.createElement("OPTION");
			opt.value = arr[i];
			opt.text = arr[i];
			dom.options.add(opt);
		}
	}
}

/*show powerleveling promotion products*/
function plPromotion(b){
	if(b)
		document.getElementById("pl_promotion").style.display = "";
	else
		document.getElementById("pl_promotion").style.display = "none";
}

function computePrice(){
	var priceObj = document.getElementsByName("checkpriceid");
	var totalPrice = 0;
	for(var i=0; i<priceObj.length; i++){
		if(priceObj[i].checked)
			totalPrice += parseFloat(document.getElementById("price_"+priceObj[i].value).value);
	}
	document.getElementById("totalPrice").innerHTML = totalPrice.toFixed(2);
}

function expandProductTag(className,obj){
	if($.trim(obj.innerHTML) == "Expand"){
		obj.innerHTML = "Collapse";
		$("."+className).removeClass("jsHide");
	}
	else{
		obj.innerHTML = "Expand";
		$("."+className).addClass("jsHide");
	}
}
function TRequire(start,end,type)
{
	/*var url = "/ajax/getRangeRequie.cfm?start="+start+"&end="+end+"&skillType="+type;
	var result = ReAjax.prototype.LoadUrl2(url); 
	if(result!="")
	{
		var arr = result.split('|||');
		document.getElementById("viewRequire").innerHTML=arr[1];
		document.getElementById("hiddenSkillType").value=arr[0];
	}*/
	$.get("/ajax/getRangeRequie.cfm",{start:start,end:end,skillType:type},function(data){
		if(data!="")
		{
			var result = data.split("|||");
			document.getElementById("viewRequire").innerHTML=result[1];
			document.getElementById("hiddenSkillType").value=result[0];
		}
	});
}

function ockSetsPL(parm,parm1,parm2)
{
	var str_sumname = parm1+"-";
	
	var a = document.getElementsByName("hiSetsSumName");
	var b = document.getElementsByName("hiSetsName");
	for(j=0;j<a.length;j++)
	{
		if(a[j].value!="")
		{
			if(a[j].value.indexOf(str_sumname)>=0)
			{
				for(i=0;i<b.length;i++)
				{
					if(b[i].value!="")
					{
						var c = b[i].value+"-";
						var d = a[j].value.replace(c,"");
						if(d.indexOf("-")<0)
						{
							if(parm2==1)
							{
								
								document.getElementById(parm+"_0").style.display="";
								document.getElementById(parm+"_1").style.display="none";
								document.getElementById("TagPriceRow_"+d).style.display="";
							}
							else
							{
								document.getElementById(parm+"_0").style.display="none";
								document.getElementById(parm+"_1").style.display="";
								document.getElementById("TagPriceRow_"+d).style.display="none";
							}
						}
					}
				}
			}
		}
	}
}

/*FFXI Item*/
function showItemFFXI(d,n)
{
	var obj = jQuery(d);
	var divWOWHead = jQuery("#divFFXIHead"+n);
	var WOWHead = jQuery("#FFXIHead"+n);
	var currrentHtml = jQuery.trim(WOWHead.html());	
	divWOWHead.show();
	if(currrentHtml != "" && currrentHtml != "loading..."){
		return;
	}
	var key = jQuery.trim(obj.text());
	jQuery.ajax({
		cache: true,
		url: "/ajax/ajaxItem.cfm?key="+encodeURI(key),
		beforeSend: function(){
			WOWHead.html("loading...");
		},
		error: function(){
			WOWHead.html("");
		},
		success: function(data){
			data = jQuery.trim(data);
			if(data && data != '0'){
				WOWHead.html(data);
			}
		}
	});
}
function hiddenItemFFXI(d,n){
	var divWOWHead = jQuery("#divFFXIHead"+n);
	divWOWHead.hide();
}
