var currface = GetCookie('tempequip');
var showArray = currface.split('-');
function onload()
{
	var s="";
	if (showArray[6] != '0')
	{
		showArray[8] = 0;
		showArray[9] = 0;
	}

	for (var i=0; i<26; i++)
	{
		if(showArray[i] != '0')
		{
			s+="<IMG id=s"+i+" src=images/face/"+i+"/"+showArray[i]+".gif style='padding:0;position:absolute;top:0;left:0;width:140;height:226;z-index:"+i+";'>";
		}
	}

	s+="<IMG src=images/face/blank.gif style='padding:0;position:absolute;top:0;left:0;width:140;height:226;z-index:50;'>";
	Show.innerHTML=s;
}

function CHECK(par1,par2,par3,par4)	// 當前層的ID號，商品圖片，適合人群,用戶性別
{
    if (par4 == 'no')
    {
		alert("對不起，您的社區性別為保密，您將無法試穿！請到社區編輯你的個人資料！");
		return;
    }
    if ((par3 != par4) && (par3 != 't'))
    {
		alert("對不起，性別不符，您無法試穿！");
		return;
    }
    
	if(par1==6||par1==7||par1==8||par1==9||par1==11||par1==13||par1==14||par1==18) 
	{
		if(par3=='m')
		{
			init='init';
		}
		else
		{
			init='initf';
		}
	} 
	else 
	{
		init='0';
	}
	if(showArray[par1] != par2) 
	{
		showArray[par1] = par2;
	}
	else 
	{
		showArray[par1] = init;
	}
	if (par1 =='8')
	{
		showArray[6] = 0; 
		if(showArray[9]==0)
		{
			showArray[9] = init;
		}
	} 
	if (par1 =='9') 
	{ 
		showArray[6] = 0; 
		if(showArray[8]==0) 
		{
			showArray[8] = init;
		}
	} 
	if (par1 =='6')
	{ 
		if(showArray[6]==init) 
		{
			showArray[8] = init;
			showArray[9] = init;
			showArray[6]=0;
		}
	} 

	if (showArray[6] != '0') 
	{ 
		showArray[8] = 0; 
		showArray[9] = 0; 
	} 

    var s="";

    for (var i=0; i<26; i++)
    {
		if(showArray[i] != '0')
		{
			s+="<IMG id=s"+i+" src=images/face/"+i+"/"+showArray[i]+".gif style='padding:0;position:absolute;top:0;left:0;width:140;height:226;z-index:"+i+";'>";
		}
    }

    var newequip = "0";
    for (var i=1; i<26; i++)
    {
		if(i != par1)
		{
			temp = showArray[i];
			newequip += "-"+temp+"";
		}
		else
		{
			newequip += "-"+par2+"";
		}
    }
    SetCookie(newequip);
    s+="<IMG src=images/face/blank.gif style='padding:0;position:absolute;top:0;left:0;width:140;height:226;z-index:50;'>";
    Show.innerHTML=s;	
}

function buyface(classid,id,action)
{
	//var action = "buyface";
	var Win=window.open("buyface.php?action="+action+"&classid="+classid+"&id="+id,"BUY",'width=500,height=280,resizable=0,scrollbars=0,menubar=0,status=1');
}
function SetCookie(name)	// 設置 Cookie
{
	document.cookie = "tempequip=" + name + ";";
}

function GetCookie(name)
{	// 讀取 Cookie 裏面的 tempequip 值
	var cname = name + "=";
	var dc = document.cookie;
	if (dc.length > 0)
	{
		begin = dc.indexOf(cname);
		if (begin != -1) 
		{
			begin += cname.length;
			end = dc.indexOf(";", begin);
			if (end == -1) end = dc.length;
			return dc.substring(begin, end);
	    }
    }
    return null;
}

function initshow()
{
	if (sex == 'm') {
	var newequip= '0-0-0-0-0-0-0-0-init-init-0-init-0-init-init-0-0-0-init-0-0-0-0-0-0-0'; 
	SetCookie(newequip); 
    location.reload();
	}
	if (sex == 'f') {
  	var newequip= '0-0-0-0-0-0-0-0-initf-initf-0-initf-0-initf-initf-0-0-0-initf-0-0-0-0-0-0-0';
	               
	SetCookie(newequip); 
    location.reload();
	}  
	if (sex == 'no') {
	alert("對不起，您的社區性別為保密，您將無法使用虛擬形象請先編輯你的個人資料！");
	}
}

function refresh()
{
	if (sex == 'no')
	{
		alert("對不起，您的社區性別為保密，您將無法使用虛擬形象請先編輯你的個人資料！");
	} 
	var newequip= userfacecookie;
    if (sex != sex)
	{
        newequip= "";
    }
    if (newequip=="") 
	{
	    alert("對不起，您還沒有保存的可用形象！");
    } 
	else
	{
		SetCookie(newequip);
		location.reload();
    }
}

	