﻿var system_http = "http://www.bygamer.com";

function transUrl(gameshortname){
	var reg1 = / - /g;
	var reg2 = /-/g;
	var reg3 = / /g;
	var shortname = gameshortname.replace(reg1,",").replace(reg2,"_").replace(reg3,"-");
	return shortname;
}

function createUrl(gameshortname,ptype,serverid,curid,productid,page){
	var lens = arguments.length;
	if(lens < 2)
		return "argument is error";
		
	if(ptype == 0)
	{
		location = system_http;	
	}
	else
	{
		var shortname = transUrl(gameshortname);
		var listtype = ["Gold","Item","PL","CDkey","CPL"];
		var url = system_http + "/buy-" + shortname;
		if(ptype != 1)
		{
			if(ptype == 12){
				url = url + "-" + "CPL";
			}else{
				url = url + "-" + listtype[ptype-1];
			}
		}
		if(lens == 5||(productid != 0&&productid!=undefined))
			url = url + "-" + productid;
		
		if(lens == 3||(serverid != 0&&serverid!=undefined)||(serverid==0&&(ptype==3 ||ptype==4)))
			url = url + "/" + serverid;
			
		if(lens == 4||(curid != 0&&curid!=undefined))
			url = url + "-" + curid;
			
		if(lens == 6||(page != 0&&page != undefined))
			url = url + "_" + page;
		location = url;
	}
}

function jumpToCheckout(gameid,serverid,curid,pid,tid){
	var url = system_http + "/product/checkout.cfm?gameid="+gameid+"&serverid="+serverid+"&curid="+curid+"&pid="+pid+"&tid="+tid;	
	window.location = url;
}

function checkProductType(carttype,curtype){
	if(carttype != 0 && carttype != curtype)
	{
		return confirm("Different type of products cannot be purchased together, or your product in shopping cart will be replaced. Are you sure you want to do this?");
	}
	
	return true;
		
}
