var A = {};

var onloadObj = new Array;
function onloadFunc()
{
	for(i=0;i<onloadObj.length;i++)
	{
		var x = onloadObj[i];
		try
		{
			x();
		}
		catch(ex)
		{
			//none;
		}
	}
}
window.onload = onloadFunc;
var arrIndex = 0;
function AddOnloadFunc(o)
{
		onloadObj[arrIndex++] = o;
}

var onResizeObj = new Array;
function onResizeFunc()
{
	for(i=0;i<onResizeObj.length;i++)
	{
		var x = onResizeObj[i];
		x();
	}
}
window.onresize = onResizeFunc;
var arrResizeIndex = 0;
function AddResizeFunc(o)
{
		onResizeObj[arrResizeIndex++] = o;
}

function CheckNumber()
{
	var key = event.keyCode;	
	
	if(key == 8 || key == 9 || key == 13 || key == 37 || key == 39)
	{
		event.returnValue=true;
		return true;		
	}
	

	if((key>=48 && key<=57) || (key>=96 && key<=105))
	{
		event.returnValue=true;
		return true;
	}

	event.returnValue=false;
	return false;
}

function ReplaceParam(ostr, fstr, tstr)
{		
		ostr = ToLower(ostr);
		np = xurl.indexOf(fstr);
		if(np < 0)
			return ostr;
		ep = np + fstr.length;

		// sum string
		s1 = ostr.substring(0,np);
		s2 = ostr.substring(ep);
		
		outs = s1;
		outs += tstr;
		outs += s2;
		
		return outs;
}

  function alterString(str,before,after) {
   var returnStr = "";
   for(i = 0; i < str.length; i++) {
    value = str.charAt(i);
    index = before.indexOf(value);
    if(index >= 0) value = after.charAt(index);
    returnStr += value;
   }
   return returnStr;
  }

  function ToUpper(arg) {
   var str1 = "abcdefghijklmnopqrstuvwxyz";
   var str2 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
   return alterString(arg,str1,str2);
  }

  function ToLower(arg){
   var str1 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
   var str2 = "abcdefghijklmnopqrstuvwxyz";
   return alterString(arg,str1,str2);
  }

function ChangeParam(param, val, fullurl)
{
	var ret = "";
	
	var xparam;
	
	var adds;
	
	if(fullurl == null)	
		adds = location.href;
	else
		adds = fullurl;
		
	var n;
	
	var flag = false;
	
	xparam = "&" + param + "=";	
	n = adds.indexOf(xparam);
		
	if(n >= 0)
				flag = true;

	if(!flag)
	{
		xparam = "?" + param + "=";	
		n = adds.indexOf(xparam);
			
		if(n >= 0)
					flag = true;
	}
	
	// url doesn't have specific parameter;
	if(!flag)
	{
		if(0 <= adds.indexOf("?"))
			ret = adds + "&" + param + "=" + val;
		else
			ret = adds + "?" + param + "=" + val;			
			
		return ret;
	}

	// get its end point
	var len = xparam.length;	
	var endpt = adds.indexOf("&",len+n)
	var makeurl = adds.substring(0,n);

	if(endpt < 0)
	{
		if(makeurl.indexOf("?") < 0)
			makeurl += "?";
		else
			makeurl += "&";
			
		makeurl += param;
		makeurl += "=";
		makeurl += val;
		ret = makeurl;
		return ret;
	}

	if(makeurl.indexOf("?") < 0)
		makeurl += "?";
	
	// attach tail url
	var tail = adds.substring(endpt,adds.length);
	makeurl += tail;
	makeurl += "&";
	makeurl += param;
	makeurl += "=";
	makeurl += val;
	ret = makeurl;
	return ret;
}

function addPost()
{
	a_win = window.open("/user/post.aspx","addpop", "width=460,height=500,resizable=no,scrollbars=yes");
	a_win.focus();
}
function GiveFeedback(uid,subuid)
{
	a_win = window.open("/mine/give_feedback.aspx?uid="+uid+"&subuid="+subuid,"gfeddback", "width=458,height=340,resizable=no,scrollbars=yes");
	a_win.focus();
}
function DelFeedback(uid,subuid)
{
	a_win = window.open("/mine/del_feedback.aspx?uid="+uid+"&subuid="+subuid,"gfeddback", "width=458,height=340,resizable=no,scrollbars=yes");
	a_win.focus();
}
function GivePenalty(uid,subuid)
{
	a_win = window.open("/mine/give_penalty.aspx?uid="+uid+"&subuid="+subuid,"gfeddback", "width=458,height=340,resizable=no,scrollbars=yes");
	a_win.focus();
}
function inviteFriend()
{
	a_win = window.open("/oboard/inviteFriend.aspx","inviteFriend", "width=562,height=280,resizable=no,scrollbars=no");
	a_win.focus();
}
function SendMemo(tg)
{
	if(tg == null || tg == "")
		tg = "";
	
	a_win = window.open("/mine/pop_memo.aspx?target="+tg,"memo", "width=562,height=280,resizable=no,scrollbars=no");
	a_win.focus();
}
function SendMemoItem(tg,item)
{
	a_win = window.open("/mine/pop_memo_item.aspx?target="+tg+"&item="+item,"memo", "width=562,height=280,resizable=no,scrollbars=no");
	a_win.focus();
}
function RecommendGoods(item)
{
	a_win = window.open("/mine/pop_memo_recom_goods.aspx?item="+item,"memo", "width=562,height=280,resizable=no,scrollbars=no");
	a_win.focus();
}

var bgLayerShown = false;
var bgLayer = top.document.getElementById('BGLayer');
var sLayer = top.document.getElementById('sLayer');
var hIframe = top.document.getElementById('hIframe');

function showProgress()
{	
	showBGLayer();
	
	var vc = top.document.getElementById('bgContents');
	if(!bgLayerShown)
	{
		vc.innerHTML = "";		
	}
	else
	{
		vc.innerHTML = "<img src='/images/prog_ing.gif'>";	
	}
}

function showBGLayer()
{
	if(!bgLayer)
	{
		hIframe = top.document.createElement('iframe');
		hIframe.id = 'hIframe';		
		hIframe.style.display = "none";
		hIframe.style.position = "absolute";
		top.document.body.appendChild(hIframe);
		
		bgLayer = top.document.createElement('DIV');
		bgLayer.id = 'BGLayer';
		top.document.body.appendChild(bgLayer);
		bgLayer.style.display = "none";
		bgLayer.style.zIndex = 40;

		sLayer = top.document.createElement('DIV');
		sLayer.id = 'sLayer';
		top.document.body.appendChild(sLayer);
		sLayer.style.display = "none";
		sLayer.style.zIndex = 999;

		sLayer.innerHTML += "<table width=100% height=100%><tr><td align=center valign=middle><span id='bgContents'></span></td></tr></table>";
	}

	bgLayer.style.position = 'absolute';
	bgLayer.style.background = '#181818';
	bgLayer.style.filter = 'alpha(opacity:50)';	
	bgLayer.style.MozOpacity = '0.5';
	hIframe.style.filter = 'alpha(opacity:50)';	
	hIframe.style.MozOpacity = '0.5';
	
	sLayer.style.position = 'absolute';
	
	scrollLayer();

	if(hIframe.style.display == "")
	{
		hIframe.style.display = "none";
		bgLayer.style.display = "none";
		sLayer.style.display = "none";
		bgLayerShown = false;
	}
	else
	{
		hIframe.style.display = "";
		bgLayer.style.display = "";
		sLayer.style.display = "";
		bgLayerShown = true;		
	}	
}

function scrollLayer()
{
	if(!bgLayer)
		return;

	hIframe.style.left = top.document.body.scrollLeft;
	hIframe.style.top = top.document.body.scrollTop;
	hIframe.style.width = top.document.body.clientWidth;
	hIframe.style.height = top.document.body.clientHeight;		
	bgLayer.style.left = top.document.body.scrollLeft;
	bgLayer.style.top = top.document.body.scrollTop;
	bgLayer.style.width = top.document.body.clientWidth;
	bgLayer.style.height = top.document.body.clientHeight;		
	sLayer.style.left = top.document.body.scrollLeft;
	sLayer.style.top = top.document.body.scrollTop;
	sLayer.style.width = top.document.body.clientWidth;
	sLayer.style.height = top.document.body.clientHeight;
}

function resizeLayer()
{
	if(!bgLayer)
		return;

	hIframe.style.left = top.document.body.scrollLeft;
	hIframe.style.top = top.document.body.scrollTop;
	hIframe.style.width = top.document.body.clientWidth;
	hIframe.style.height = top.document.body.clientHeight;
	bgLayer.style.left = top.document.body.scrollLeft;
	bgLayer.style.top = top.document.body.scrollTop;
	bgLayer.style.width = top.document.body.clientWidth;
	bgLayer.style.height = top.document.body.clientHeight;		
	sLayer.style.left = top.document.body.scrollLeft;
	sLayer.style.top = top.document.body.scrollTop;
	sLayer.style.width = top.document.body.clientWidth;
	sLayer.style.height = top.document.body.clientHeight;	
}

window.onscroll = scrollLayer;
AddResizeFunc(resizeLayer);

	var r1 = '<div style="width:100%;height:1px"><div style="float:left;height:1px;width:5px;background-color:#FFFFFF;overflow:hidden;"></div>	<div style="float:right;height:1px;width:5px;background-color:#FFFFFF;overflow:hidden;"></div></div>';
	var r2 = '<div style="width:100%;height:1px"><div style="float:left;height:1px;width:3px;background-color:#FFFFFF;overflow:hidden;"></div>	<div style="float:right;height:1px;width:3px;background-color:#FFFFFF;overflow:hidden;"></div></div>';
	var r3 = '<div style="width:100%;height:1px"><div style="float:left;height:1px;width:2px;background-color:#FFFFFF;overflow:hidden;"></div>	<div style="float:right;height:1px;width:2px;background-color:#FFFFFF;overflow:hidden;"></div></div>';
	var r4 = '<div style="width:100%;height:2px"><div style="float:left;height:2px;width:1px;background-color:#FFFFFF;overflow:hidden;"></div>	<div style="float:right;height:2px;width:1px;background-color:#FFFFFF;overflow:hidden;"></div></div>';	

	function DrawRoundTable(w,h)
	{				
		var rimg = '<div style="background-color:#CCCCCC;width:'+w+';height:'+h+';">';
		document.write(rimg);
		
		document.write(r1);
		document.write(r2);
		document.write(r3);
		document.write(r4);

		var bdimg = '<div style="width:100%;height:'+(h-10)+'px"></div>';
		
		document.write(bdimg);
		
		document.write(r4);
		document.write(r3);
		document.write(r2);
		document.write(r1);		
		document.write('</div>');
	}

	function DrawRoundingImg(w,h,url,linkurl)
	{
		var rimg = '<div style="background-image:url('+url+');width:'+w+';height:'+h+';">';
		document.write(rimg);
		
		document.write(r1);
		document.write(r2);
		document.write(r3);
		document.write(r4);

		var bdimg = '<div style="width:100%;height:'+(h-10)+'px"></div>';
		if(linkurl != null)
		{
			bdimg = '<div style="width:100%;height:'+(h-10)+'px;cursor:pointer;" onclick="goThumbLink(\''+linkurl+'\')"></div>';
		}
		
		document.write(bdimg);
		
		document.write(r4);
		document.write(r3);
		document.write(r2);
		document.write(r1);		
		document.write('</div>');
	}
	
	function goThumbLink(url,newwindow)
	{
		var keyjs = "javascript:";
		var nj = url.indexOf(keyjs);
		if(nj == 0)
		{
			var funcname = url.substring(keyjs.length);
			eval(funcname);
		}
		else
		{
		    if(newwindow==null)
			    top.document.location.href=url;
			else
			    window.open(url);
		}
	}
	
	function DrawTR1(w,clr,bgclr)
	{
		var tr1 = '<div style="width:100%;height:1px"><div style="float:left;height:1px;width:5px;background-color:'+bgclr+';overflow:hidden;"></div><div style="float:left;width:'+(w-10)+'px;height:1px;background-color:'+clr+';overflow:hidden;"></div><div style="float:right;height:1px;width:5px;background-color:'+bgclr+';overflow:hidden;"></div></div>';
		document.write(tr1);		
	}	
	function DrawTR2(w,clr,bgclr)
	{
		var tr2 = '<div style="width:100%;height:1px"><div style="float:left;height:1px;width:3px;background-color:'+bgclr+';overflow:hidden;"></div><div style="float:left;height:1px;width:2px;background-color:'+clr+';overflow:hidden;"></div><div style="float:left;width:'+(w-10)+'px;height:1px;overflow:hidden;"></div><div style="float:left;height:1px;width:2px;background-color:'+clr+';overflow:hidden;"></div><div style="float:right;height:1px;width:3px;background-color:'+bgclr+';overflow:hidden;"></div></div>';
		document.write(tr2);		
	}	
	function DrawTR3(w,clr,bgclr)
	{
		var tr3 = '<div style="width:100%;height:1px"><div style="float:left;height:1px;width:2px;background-color:'+bgclr+';overflow:hidden;"></div><div style="float:left;height:1px;width:1px;background-color:'+clr+';overflow:hidden;"></div><div style="float:left;width:'+(w-6)+'px;height:1px;overflow:hidden;"></div><div style="float:left;height:1px;width:1px;background-color:'+clr+';overflow:hidden;"></div><div style="float:right;height:1px;width:2px;background-color:'+bgclr+';overflow:hidden;"></div></div>';
		document.write(tr3);		
	}	
	function DrawTR4(w,clr,bgclr)
	{
		var tr4 = '<div style="width:100%;height:2px"><div style="float:left;height:2px;width:1px;background-color:'+bgclr+';overflow:hidden;"></div><div style="float:left;height:2px;width:1px;background-color:'+clr+';overflow:hidden;"></div><div style="float:left;width:'+(w-4)+'px;height:2px;overflow:hidden;"></div><div style="float:left;height:2px;width:1px;background-color:'+clr+';overflow:hidden;"></div><div style="float:right;height:2px;width:1px;background-color:'+bgclr+';overflow:hidden;"></div></div>';
		document.write(tr4);
	}	

	function DrawBorderedRoundingImg(w,h,url,clr,linkurl,newwindow)
	{
		var rimg = '<div style="background-image:url('+url+');width:'+w+';height:'+h+';background-repeat:no-repeat;background-position:center center;">';
		document.write(rimg);
		
		var bgclr = '#FFFFFF';
		
		DrawTR1(w,clr,bgclr);
		DrawTR2(w,clr,bgclr);
		DrawTR3(w,clr,bgclr);
		DrawTR4(w,clr,bgclr);

		var bdimg = '<div style="width:100%;height:'+(w-10)+'px">';
		bdimg += '<div style="float:left;height:100%;width:1px;background-color:'+clr+';overflow:hidden;"></div>';		
		
		if(linkurl == null)
		{
			bdimg += '<div style="width:'+(w-2)+'px;height:'+(w-10)+'px;float:left;"></div>';
		}
		else
		{
		    if(newwindow)
		    	bdimg += '<div style="width:'+(w-2)+'px;height:'+(w-10)+'px;float:left;cursor:pointer;" onclick="goThumbLink(\''+linkurl+'\',true)"></div>';
		   	else
			    bdimg += '<div style="width:'+(w-2)+'px;height:'+(w-10)+'px;float:left;cursor:pointer;" onclick="goThumbLink(\''+linkurl+'\')"></div>';
		}
		bdimg += '<div style="float:left;height:100%;width:1px;background-color:'+clr+';overflow:hidden;"></div></div>';

		document.write(bdimg);
		
		DrawTR4(w,clr,bgclr);
		DrawTR3(w,clr,bgclr);
		DrawTR2(w,clr,bgclr);
		DrawTR1(w,clr,bgclr);
		document.write('</div>');	
	}
	
	function DrawBorderedRoundingImg2(w,h,url,clr,bgclr,linkurl,newwindow)
	{
		var rimg = '<div style="background-image:url('+url+');width:'+w+';height:'+h+';">';
		document.write(rimg);
		
		DrawTR1(w,clr,bgclr);
		DrawTR2(w,clr,bgclr);
		DrawTR3(w,clr,bgclr);
		DrawTR4(w,clr,bgclr);

		var bdimg = '<div style="width:100%;height:'+(w-10)+'px">';
		bdimg += '<div style="float:left;height:100%;width:1px;background-color:'+clr+';overflow:hidden;"></div>';		
		
		if(linkurl == null)
		{
			bdimg += '<div style="width:'+(w-2)+'px;height:'+(w-10)+'px;float:left;"></div>';
		}
		else
		{
		    if(newwindow == null)
			    bdimg += '<div style="width:'+(w-2)+'px;height:'+(w-10)+'px;float:left;cursor:pointer;" onclick="goThumbLink(\''+linkurl+'\')"></div>';
			else
			    bdimg += '<div style="width:'+(w-2)+'px;height:'+(w-10)+'px;float:left;cursor:pointer;" onclick="goThumbLink(\''+linkurl+'\',true)"></div>';
		}
		bdimg += '<div style="float:left;height:100%;width:1px;background-color:'+clr+';overflow:hidden;"></div></div>';

		document.write(bdimg);
		
		DrawTR4(w,clr,bgclr);
		DrawTR3(w,clr,bgclr);
		DrawTR2(w,clr,bgclr);
		DrawTR1(w,clr,bgclr);
		document.write('</div>');	
	}	
	
	function CopyToBlog(item)
	{
		showBGLayer();
		var vc = $('bgContents');	
		vc.innerHTML = "<iframe frameborder='0' marginwidth='0' marginheight='0' scrolling='no' width=680 height=583 src='/ajax/GetItemPostingManagement.aspx?item="+item+"'></iframe>";
	}
	
	function ShowPriceComparingList()
	{
		showBGLayer();
		var vc = $('bgContents');	
		vc.innerHTML = "<iframe frameborder='0' marginwidth='0' marginheight='0' scrolling='no' width=780 height=623 src='/ajax/GetAjaxComparePrice.aspx'></iframe>";
	}
	
	function ShowSellItem(cate)
	{
		showBGLayer();
		var vc = $('bgContents');	
		vc.innerHTML = "<iframe frameborder='0' marginwidth='0' marginheight='0' scrolling='no' width=780 height=623 src='/ajax/GetAjaxSellItem.aspx?category=' + cate></iframe>";
	}

	function ShowBlogReviewList()
	{
		showBGLayer();
		var vc = $('bgContents');	
		vc.innerHTML = "<iframe frameborder='0' marginwidth='0' marginheight='0' scrolling='no' width=780 height=623 src='/ajax/GetAjaxBlogReview.aspx?mode=0'></iframe>";
	}
	
	function ShowHelpSMS()
	{
		showBGLayer();
		var vc = $('bgContents');	
		vc.innerHTML = "<iframe frameborder='0' marginwidth='0' marginheight='0' scrolling='no' width=780 height=623 src='/help/SMS.aspx'></iframe>";
	}	

	function ShowMaps(seller,mapx,mapy,item)
	{
		showBGLayer();
		var vc = $('bgContents');	
		vc.innerHTML = "<iframe frameborder='0' marginwidth='0' marginheight='0' scrolling='no' width=780 height=623 src='/ajax/map.aspx?id=" + seller + "&mapx=" + mapx + "&mapy=" + mapy + "&item=" + item + "'></iframe>";
	}		

	function GetMoneyType(x)
	{
		var flag = 0;
		var ret = "";
		var i = 0;

		for(i=x.length-1;i >= 0;i--)
		{
			if(flag++ == 2 && i != 0)
			{
				flag = 0;
				ret = "," + x.substring(i,i+1) + ret;
			}
			else
				ret = x.substring(i,i+1) + ret;
		}

		return ret;
	}

function HelpGuide()
{
	a_win = window.open("/help/help1.aspx","help1", "width=620,height=670,resizable=yes,scrollbars=yes");
	a_win.focus();
}