var Pubhome = new Object();
var Ajax = new Object();
var Flash = new Object();
var Images=new Object();
var Images1=new Object();
Pubhome.Local = "http://www.jiaomai.com/";
Pubhome.Remote_DS = "http://www.discoversources.com/";
Pubhome.CreateObject = function(tagName)
{
	return document.createElement(tagName);
};
Pubhome.CreateText = function(s)
{
	return document.createTextNode(s);
};
String.prototype.trim = function()
{
	return this.replace(/^\s*|\s*$/g,"");
};
String.prototype.realLength = function()
{
    return this.replace(/[^\x00-\xff]/g,"**").length;
};
String.prototype.left = function(n)
{
	if (this.length > n)
	{
		return this.substr(0, n) + '...';
	}
	else
	{
		return this;
	}
};
Array.prototype.remove = function(n)
{
	if (n < 0)
	{
		return this;
	}
	else
	{
		return this.slice(0, n).concat(this.slice(n + 1, this.length));
	}
};
/*
Pubhome.findPosX = function(obj) 
{
	var curleft = 0;
	if (obj && obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft;
			obj = obj.offsetParent;
		}
	}
	else if (obj && obj.x) curleft += obj.x;
	return curleft;
};

Pubhome.findPosY = function(obj)
{
	var curtop = 0;
	if (obj && obj.offsetParent) 
	{
		while (obj.offsetParent) 
		{
			curtop += obj.offsetTop;
			obj = obj.offsetParent;
		}
	} 
	else if (obj && obj.y) curtop += obj.y;
	return curtop;
};
*/
Pubhome.getOs = function()
{
	if(navigator.userAgent.indexOf("MSIE")>0)return 1;
	if(isFirefox=navigator.userAgent.indexOf("Firefox")>0)return 2;
};

Pubhome.addFavorite = function(href, title)
{
	switch(Pubhome.getOs())
	{
		case 1:
			window.external.AddFavorite(href, title);
			break;
		case 2:
			window.sidebar.addPanel(title, href, '');
			break;
		default:
			break;
	}
};
Pubhome.setHomePage = function(t,href)
{
	t.style.behavior="url(#default#homepage)";
	t.setHomePage(href);
};
Pubhome.Count = function(a,b,c)
{
	// 1 : retun text
	// 2 : return xml
	Ajax.ajax(Pubhome.Local + "Count/?ShopName=" + a.toString() + "&Flag=" + b.toString() + "&Type=" + c.toString(),1);
};
Pubhome.CountWeb = function(a,b)
{
	// 1 : retun text
	// 2 : return xml
	Ajax.ajax(Pubhome.Remote_DS + "Count/WebLinkCount.aspx?LinkID=" + a.toString() + "&Type=" + b.toString(),1);
};
Ajax.xmlhttp = null;
Ajax.ajax = function(http,tag)
{
	if(!Ajax.xmlhttp)
	{
		Ajax.xmlhttp = zXmlHttp.createRequest();
	}
	else if(Ajax.xmlhttp.readyState!=0)
	{
		Ajax.xmlhttp.abort();
	}
	Ajax.xmlhttp.open("GET",http + ((http.indexOf("?") != -1)?"&T=":"?T=") + new Date().getTime(),true);	
	Ajax.xmlhttp.onreadystatechange = function()
	{
		if(Ajax.xmlhttp.readyState == 4)
		{
			if(Ajax.xmlhttp.status == 200)
			{	
				var returnValue = "";
				returnValue = (tag==1)?Ajax.xmlhttp.responseText:Ajax.xmlhttp.responseXML;
				return returnValue;
			}
		}
	};	
	Ajax.xmlhttp.send(null);
};
//D = id B = filename A = width F = flashvars
Flash.createFlash = function(D,B,A,F)
{
	var E="<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0\" width=\""+A+"\" height=\""+A+"\" id=\""+D+"\" align=\"middle\">";
	E+="<param name=\"quality\" value=\"high\">";
	E+="<param name=\"movie\" value=\""+B+"\">";
	E+="<param name=\"flashvars\" value=\""+F+"\">";
	E+="<embed src=\""+B+"\" flashvars=\""+F+"\" quality=\"high\" width=\""+A+"\" height=\""+A+"\" name=\""+D+"\" align=\"middle\" type=\"application/x-shockwave-flash\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\">";
	E+="</object>";
	document.write(E);
};

Images.MakeThumbnail = function(D,A)
{
	var a = Dom.$id(D).getElementsByTagName("IMG");
	var w,h;
	for(var i=0;i<a.length;i++)
	{
		w = a[i].width ;
		h = a[i].height;
		if(w>h)
		{
			
			if(parseInt(w)>parseInt(A))
			{
			a[i].width = A;
			a[i].height = h * (A/w);			
			}
		}
		else
		{
			if(parseInt(h)>parseInt(A))
			{
				
			a[i].height = A;
			a[i].width =(w*A)/h ;
			}
		}
	}
};
Images1.MakeThumbnail1 = function(D,A)
{
	var a = Dom.$id(D).getElementsByTagName("IMG");
	var w,h;
	for(var i=0;i<a.length;i++)
	{
		w = a[i].width ;
		h = a[i].height;
		if(w>h)
		{
			
			if(parseInt(w)>parseInt(A))
			{
			a[i].width = A;
			a[i].height = h * (A/w);			
			}
		}
		else
		{
			if(parseInt(h)>parseInt(A))
			{
				
			a[i].height = A;
			a[i].width =(w*A)/h ;
			}
		}
	}
};