﻿if (!('trim' in String.prototype)) {
    String.prototype.trim = function() {
        return this.replace(/(^\s*)|(\s*$)/g, "");
    }
};
if (!('SubString' in String.prototype)) {
	String.prototype.SubString=function(size)
	{
		var totalCount = 0;  
		var newStr = ""; 
		for (var i=0; i<this.length; i++) {  
         var c = this.charCodeAt(i);  
         if ((c >= 0x0001 && c <= 0x007e) || (0xff60<=c && c<=0xff9f)) {  
             totalCount++;  
         }else {     
             totalCount+=2;  
         }  
         if(totalCount<size){ 
             newStr = this.substring(0,i+1); 
         }
     } 
     return newStr; 
	}
};
function LoginStatus()
{
	var userid = cookie("Users", "UserID");
	var username = cookie("Users", "UserName");
	var nickname = cookie("Users", "NickName");
	var groupid = cookie("Users", "GroupID");
	var grouptitle = cookie("Users", "GroupTitle");
	var usertype = cookie("Users", "UserType");
	var gender = cookie("Users", "Gender");
	var html="<div>";
	if (!userid || !username || !groupid || !usertype)
	{
		html+="您好，欢迎"+SiteName+"。<a href=\""+SitePath
			+"Login.aspx\" target=\"_blank\">登录</a>&nbsp;&nbsp;|&nbsp;&nbsp;<a href=\""+SitePath
			+"Login.aspx\" target=\"_blank\">注册</a>";
	}
	else
	{
		html+=username+",您好，欢迎您回来.<a href=\"javascript:\" onclick=\"Loginout(LoginStatus)\">退出登陆</a>";
	}
	html+="</div>";
	$("#LoginStatus").html(html);
};

function ShoppingCart()
{
	$.get(AjaxUrl+"ShoppingCart.aspx", { Action: "init"},
		        function(data, textStatus) {
		        	
		        }, "text");
	
	//var html="<a href=\""+SitePath+"ShoppingCart.aspx\" target=\"_blank\">购物车中有<span id=\"spcr1\">{0}</span>件商品 合计<span id=\"spct1\">{1}</span>元</a>";
	var html="<a href=\""+SitePath+"ShoppingCart.aspx\" target=\"_blank\">购物车中有<span id=\"spcr1\">{0}</span>件商品</a>";
	var r=cookie("ShoppingCart","RecordCount");
	//var p=cookie("ShoppingCart","TotalPrice");
	if(!r)r=0;
	//if(!p)p=0;
	html=html.replace(/\{0\}/g,r);
	//html=html.replace(/\{1\}/g,p);
	$("#ShoppingCartInfo").html(html);
};
function Buy(itemid,count)
{
	count=parseInt(count);
	if(isNaN(count) || count<1)
	{
		alert('请输入要购买的数量');
		return;
}
var stocks = parseInt($("#stocks").html().replace(/[^(\d+)]/gi, ""));
if (isNaN(stocks) || count > stocks) {
    alert("库存不足无法购买");
    return;
}
var _size = $(".size").html();
//if (_size == "") {
//    alert("请选择尺码");
//    return;
//}
//_size = "尺码：" + _size;
	$.post(AjaxUrl+"ShoppingCart.aspx", { Action: "add", CommodityID: itemid, Quantity: count,
	Spec: _size
},
		        function(data, textStatus) {
		            if (data == "Success") {
		            	document.location.href=SitePath+"ShoppingCart.aspx";
		            }else
		            	alert(data);
		        }, "text");
};
function AddShoppingCart(itemid,count)
{
	count=parseInt(count);
	if(isNaN(count) || count<1)
	{
		alert('请输入要购买的数量');
		return;
}
var stocks = parseInt($("#stocks").html().replace(/[^(\d+)]/gi, ""));
if (isNaN(stocks) || count > stocks) {
    alert("库存不足无法购买");
    return;
}
var _size = $(".size").html();
//if (_size == "") {
//    alert("请选择尺码");
//    return;
//}
//_size = "尺码：" + _size;
$.post(AjaxUrl + "ShoppingCart.aspx", { Action: "add", CommodityID: itemid, Quantity: count,
Spec: _size
},
		        function(data, textStatus) {
		            if (data == "Success") {
		            	alert('添加成功');
		            	ShoppingCart();
		            }else
		            	alert(data);
		        }, "text");
};
function AddFavorite(cid,itemid,title,url,t)
{
	if(itemid<1 || title.trim()=='' || url.trim()=='')
	{
		return;
	}
	$.post(AjaxUrl+"Favorite.aspx", { Action: "add", ChannelID: cid, ItemID: itemid,
			Title:title,Url:url},
		        function(data, textStatus) {
		            if (data == "Success") {
		            	alert('添加成功');
		            }
		            else if(data=="201")
		            {
		            	if(!t)
		            	{
		            		ShowLogin('',function(data)
		            		{
		            			AddFavorite(data.ChannelID,data.ItemID,data.Title,data.Url,1);
		            		},{ChannelID: cid, ItemID: itemid,Title:title,Url:url});
		            	}
		            }
		            else if(data=="0")
		            {
		            	alert("添加失败，可能该页已经在您的收藏夹中");
		            }
		            else
		            {
		            	alert(data);
		            }
		        }, "text");
};
function HideLogin()
{
	var body=$("#loginframe");
	if(body.attr('id'))
	{
		body.hide();
	}	
};
var callbackdata;
function ShowLogin(obj,callback,data)
{
	callbackdata=data;
	var body=$("#loginframe");
	if(!body.attr('id'))
	{
		$('body').prepend('<div id="loginframe" class=\"loginframe\">&nbsp;</div>');
		body=$("#loginframe");
		var html="<form onsubmit=\"return CheckLogin(this,"+callback+");\">";
		html+="<div class=\"h\"><label><a href=\"javascript:\" onclick=\"HideLogin();\"></a></label></div>";
		html+="<div class=\"m\"><div class=\"i\">";
		html+="<ul><li class=\"l\">用户名：</li><li class=\"r\"><input type=\"text\" name=\"UserName\" /></li></ul>";
		html+="<ul><li class=\"l\">密&nbsp;&nbsp; 码：</li><li class=\"r\"><input type=\"password\" name=\"UserPassword\" /></li></ul>";
		html+="<ul><li class=\"l\">验证码：</li><li class=\"r v\"><input type=\"text\" name=\"VerifyCode\" id=\"VerifyCode\" style=\"width:40px\" maxlength=\"4\" onfocus=\"ShowVerifyimg('login','vi1','VerifyCode')\" onclick=\"ShowVerifyimg('login','vi1','VerifyCode')\"/><span id=\"vi1\" onclick=\"ShowVerifyimg('login',this.id,'VerifyCode')\">点击显示</span></li></ul>";
		html+="</div><div class=\"b\"><input class=\"b1\" type=\"submit\" value=\" \" /></div>";
		html+="<div class=\"bottom\"><ul><li><a href=\""+SitePath+"Register.aspx\" target=\"_blank\">免费注册</a></li>";
		html+="<li><a href=\""+PassportPath+"GetPassword.aspx\" target=\"_blank\">忘记密码</a></li></ul></div>";
		html+="</div></form>";
		body.html(html);
	}
	var wi=GetWindowInfo();
	var top=(wi.Height/2)-(parseInt(body.height())/2)+wi.ScrollY+"px";
	body.css({"left":(($(document).width())/2-(parseInt(body.width())/2))+"px",
		"top":top,
		"position":"absolute"
	}).show();	
};
function Loginout(callback)
{
	 $.post(AjaxUrl+"Login.aspx",  { Action: "ajax_loginout"},
	 	function(data,textstatus)
	 	{
	 		if(callback)callback();
		});
};
function CheckLogin(form,callback)
{
	if(form.UserName.value.trim()=='')
	{
		alert('请输入用户名');
		form.UserName.focus();
		return false;
	}
	if(form.UserPassword.value.trim()=='')
	{
		alert('请输入密码');
		form.UserPassword.focus();
		return false;
	}
	if(form.VerifyCode.value.trim()=='')
	{
		alert('请输入验证码');
		form.VerifyCode.focus();
		return false;
	}
	 $.post(AjaxUrl+"Login.aspx",  { Action: "ajax_login", UserName: form.UserName.value, UserPassword: form.UserPassword.value,LoginType:0},function(data,textstatus)
	 {
	 		switch(parseInt(data))
		        	{
		        		case 0:callback(callbackdata);break;
		        		case -1:alert("用户不存在");break;
		        		case 1:alert("用户名或密码错误");break;
		        		default:alert("您的账号异常，请联系管理员");break;		        		
		        	}	
		});
	return false;
};
function ShowVerifyimg(sn,img,input,form) {
	if(typeof(form)=="string")form=document.getElementById(form);
	if(typeof(img)=="string")
	{
		if(form)
		{
			var tmp=form.getElementsByTagName("SPAN");			
			for(var i=0;i<tmp.length;i++)
			{
				if(tmp[i].id==img)img=tmp[i];
			}
		}
		else
		{
			img=document.getElementById(img);
		}
	}
	img.innerHTML = "<img src=\""+AjaxUrl+"VerifyImage.aspx?sb=1&st=1&w=55&h=20&fs=12&key="+sn+"&"+Math.random()+"\" alt=\"\" width=\"55\" height=\"20\" align=\"absMiddle\" style=\"cursor: pointer;\" />";
	
	if(typeof(input)=="string")
	{
		if(form)
		{
			var tmp=form.getElementsByTagName("INPUT");			
			for(var i=0;i<tmp.length;i++)
			{
				if(tmp[i].name==input)input=tmp[i];
			}
		}
		else
		{
			input=document.getElementById(input);
		}	
	}
	input.onclick = null;
	input.onfocus = null;
};
        
function cookie(root, name, value, options) {
    root = CookiePrefix + root;
    root = root.toLowerCase();
    if (typeof value != 'undefined') {
        options = options || {};
        if (value === null) {
            value = '';
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString();
        }
        var path = options.path ? '; path=' + (options.path) : '';
        var domain = options.domain ? '; domain=' + (options.domain) : '';
        var secure = options.secure ? '; secure' : '';
        
        document.cookie = [root, '=', name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else {
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = cookies[i].trim();

                if (cookie.toLowerCase().substring(0, root.length + 1) == (root + '=')) {
                    var nodes = decodeURIComponent(cookie.substring(root.length + 1)).split('&');
                    for (var j = 0; j < nodes.length; j++) {
                        if (nodes[j].substring(0, name.length + 1) == (name + '=')) {
                            cookieValue = nodes[j].substring(name.length + 1);
                            break;
                        }
                    }
                    break;
                }
            }
        }
        return cookieValue;
    }
};


function ShowPic(ImgD, maxwidth, maxheight) {
    var image = new Image();
    image.src = ImgD.src;
    if (image.width > 0 && image.height > 0) {
        if (image.width / image.height >= maxwidth / maxheight) {
            if (image.width > maxwidth) {
                ImgD.width = maxwidth;
                ImgD.height = (image.height * maxwidth) / image.width;
            } else {
                ImgD.width = image.width;
                ImgD.height = image.height;
            }
        }
        else {
            if (image.height > maxheight) {
                ImgD.height = maxheight;
                ImgD.width = (image.width * maxheight) / image.height;
            } else {
                ImgD.width = image.width;
                ImgD.height = image.height;
            }
        }
    }
};

function vFlash(URL,width,height)
{
	this.swf=URL;
	this.width=width;
	this.height=height;
	this.Params=new Array();
	this.FlashVars=new Array();
	this.addParam=function(ParamName,ParamValue)
	{
		var obj=new Object();
		obj.name=ParamName;
		obj.value=ParamValue;
		this.Params[this.Params.length]=obj;
	};
	this.AddVars=function(ParamName,ParamValue)
	{
		var obj=new Object();
		obj.name=ParamName;
		obj.value=ParamValue;
		this.FlashVars[this.FlashVars.length]=obj;
	};
	this.write=function(obj)
	{
		var html="<object type=\"application/x-shockwave-flash\" data=\""+this.swf+"\"";
		html+=" width=\""+this.width+"\" height=\""+this.height+"\">\n";
		html+="<param name=\"movie\" value=\""+this.swf+"\" />";
		for(var i=0;i<this.Params.length-1;i++)
		{
			html+="<param name=\""+this.Params[i].name+"\" value=\""+this.Params[i].value+"\" />\n";
		}
		if(this.FlashVars.length>0)
		{
			html+="<param name=\"FlashVars\" value=\"";
			for(var i=0;i<this.FlashVars.length;i++)
			{
				html+=this.FlashVars[i].name+"="+this.FlashVars[i].value;
				if(i<this.FlashVars.length-1)html+="&";
			}
			html+="\">\n";
		}
		html+="</object>";
		if(typeof(obj)=="undefined")
		{
			document.write(html);	
		}
		else
		{
			obj.innerHTML=html;
		}
	};	
};
var tabs=new vTabs();
function vTabs(divid)
{
	this.links=new Object();
	this.Show=function(index,divid)
	{
		var li=this.links[divid].parents("li");
		for(var i=0;i<li.length;i++)
		{
			if(index==i)
			{
				$(li[i]).addClass("current");
			}
			else
			{
				$(li[i]).removeClass("current");
			}
		}
		for(var i=0;i<this.links[divid].length;i++)
		{
			var id=this.links[divid][i].href.replace(/\S+#/g, "");
			if(i==index)
				$("#"+id).css({ display: '' });
			else
				$("#"+id).css({ display: 'none' });
		}
		return false;
	};
	this.init=function(divid)
	{
		if(!divid)return;
		var menu=$("#"+divid);
		var a=menu.find("A");
		this.links[divid]=a;
		for(var i=0;i<a.length;i++)
		{			
			a[i].onclick=new Function("return tabs.Show("+i+",'"+divid+"');");
		}
	};
};


function GetWindowInfo()
{
	var scrollX = 0, scrollY = 0, width = 0, height = 0, contentWidth = 0, contentHeight = 0;
		if (typeof(window.pageXOffset) == 'number')
		{
			scrollX = window.pageXOffset;
			scrollY = window.pageYOffset;
		}
		else if (document.body && (document.body.scrollLeft || document.body.scrollTop))
		{
			scrollX = document.body.scrollLeft;
			scrollY = document.body.scrollTop;
		}
		else if (document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop))
		{
			scrollX = document.documentElement.scrollLeft;
			scrollY = document.documentElement.scrollTop;
		}

		if (typeof(window.innerWidth) == 'number')
		{
			width = window.innerWidth;
			height = window.innerHeight;
		}
		else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight))
		{
			width = document.documentElement.clientWidth;
			height = document.documentElement.clientHeight;
		}
		else if (document.body && (document.body.clientWidth || document.body.clientHeight))
		{
			width = document.body.clientWidth;
			height = document.body.clientHeight;
		}
		if (document.documentElement && (document.documentElement.scrollHeight || document.documentElement.offsetHeight))
		{
			if (document.documentElement.scrollHeight > document.documentElement.offsetHeight)
			{
				contentWidth = document.documentElement.scrollWidth;
				contentHeight = document.documentElement.scrollHeight;
			}
			else
			{
				contentWidth = document.documentElement.offsetWidth;
				contentHeight = document.documentElement.offsetHeight;
			}
		}
		else if (document.body && (document.body.scrollHeight || document.body.offsetHeight))
		{
			if (document.body.scrollHeight > document.body.offsetHeight)
			{
				contentWidth = document.body.scrollWidth;
				contentHeight = document.body.scrollHeight;
			}
			else
			{
				contentWidth = document.body.offsetWidth;
				contentHeight = document.body.offsetHeight;
			}
		}
		else
		{
			contentWidth = width;
			contentHeight = height;
		}

		if (height > contentHeight)
			height = contentHeight;

		if (width > contentWidth)
			width = contentWidth;

		var rect = new Object();
		rect.ScrollX = scrollX;
		rect.ScrollY = scrollY;
		rect.Width = width;
		rect.Height = height;
		rect.ContentWidth = contentWidth;
		rect.ContentHeight = contentHeight;
		return rect;
};

function KeypressNumber(obj)
{
	var key=obj.keyCode || obj.charCode; 
	if (key < 48 || key > 57) 
	{	          
		return false; 
	}
	else
	{
		return true;
	}
};

function loadxml(isfile,data)
{
	var xmldoc;
	if(window.ActiveXObject)
	{
		xmldoc	= new ActiveXObject('Microsoft.XMLDOM');
		xmldoc.async	= false;
		xmldoc.setProperty('SelectionLanguage','XPath');
	}
	else if (document.implementation&&document.implementation.createDocument)
	{
		xmldoc	= document.implementation.createDocument('', '', null);
		xmldoc.async = false;
	}
	else
	{
		return null;
	}
	if(isfile)xmldoc.load(data);
	else
	{
		if(window.ActiveXObject)
		{
			xmldoc.loadXML(data);
		}
		else
		{
			var oParser = new DOMParser();
			xmldoc = oParser.parseFromString(data,"text/xml");
		}
	}
	return xmldoc;
};

function ShowMask()
{
	var DivMask=$("#DivMask");
	if(!DivMask.attr('id'))
	{
		$('body').prepend('<div id="DivMask"><IFRAME style=\"width:1px;height:1px\"></IFRAME></div>');
		DivMask=$("#DivMask");
		DivMask.css({position:"absolute",
			background:"#ccc",
			top:"0px",
			left:"0px",
			filter:"alpha(Opacity=50)",
			width:"100%",
			zIndex:"10",
			height:$('body').height(),
			MozOpacity:"0.5"
			});
		
	}
	DivMask.show();
};
function HideMask()
{
	var DivMask=$("#DivMask");
	if(DivMask.attr("id"))DivMask.hide();
};


function LoadJS(jsfile,_id)
{
	try{
		if(_id && $(_id)) return;
		var js=document.createElement('script');
	  	js.setAttribute("type","text/javascript");
	  	js.setAttribute("src", jsfile);
	  	document.getElementsByTagName("head")[0].appendChild(js);
	}catch(ex){}
};
function LoadCSS(cssfile)
{
	try{
		var css=document.createElement("link");
	  css.setAttribute("type","text/css");
	  css.setAttribute("href", cssfile);
		css.setAttribute("rel", "stylesheet")
	  document.getElementsByTagName("head")[0].appendChild(css);
	}catch(ex){}
};
function RunScript(URL,CallBack)
{
	var script = document.createElement('script');
	script.type = "text/javascript";
	if (CallBack)
		script.onload = script.onreadystatechange = function() {
      if (script.readyState && script.readyState != 'loaded' && script.readyState != 'complete')
        return;
      script.onreadystatechange = script.onload = null;
      CallBack();
    };
	script.src=URL;
	document.getElementsByTagName('head')[0].appendChild (script);
};

function GetPicUrl(url)
{
	return url.replace(/(_+?.*(\.[^\.]*)$)/i, "$2");
};
function GetThumbnailUrl(url)
{
	url=GetPicUrl(url);
	return url.replace(/(.*)(.*(\.[^\.]*)$)/g,"$1_Thumbnail$2");
};
function GetSquareUrl(url)
{
	url=GetPicUrl(url);
	return url.replace(/(.*)(.*(\.[^\.]*)$)/g,"$1_Square$2");
};
var topmenus=new Object();	
function InitMenu()
{
    jQuery('.topmenu').vmenus();
};
(function($) {
    $.fn.vmenus = function(options) {
        var opt = $.extend({}, $.fn.vmenus.defaults, options);
        var items = new Object();
        return this.each(function() {
            var lis = $(this).find("UL > li");
            var links = lis.find("a");
            lis.each(function(i) {
                var pid = $(lis[i]).attr("id").replace(/m1_/g, "");
                if (typeof (items[pid]) == "undefined") items[pid] = new Array();
                items[pid][items[pid].length] = [$(links[i]).attr("id").replace(/(m\d+_\d+_(\d+))$/g, "$2"), $(links[i]).text(), $(links[i]).attr("href"), $(links[i]).attr("target")];
            });
            $(this).html("");
            $(this).prepend('<ul class=\"fmenu\"></ul>');
            var uls = $(this).find("ul.fmenu");
            for (var i = 0; i < items[0].length; i++) {
                var item = items[0][i];
                if (typeof (item[1]) == "undefined") continue;
                var li = $("<li class=\"fmenu\" onmouseover=\"$.fn.vmenus.over(this)\" onmouseout=\"$.fn.vmenus.out(this)\"></li>").appendTo(uls);
                var a = $("<a></a>").appendTo(li);
                a.html(item[1]);
                a.attr("href", item[2]);
                a.attr("class", "r0");
                a.attr("target", item[3]);
                $.fn.vmenus.additem(items, li, item[0]);
            };
            $(this).show();
        });
    };
    $.fn.vmenus.over = function(obj) {
        $(obj).find("ul").css({ visibility: "visible" });
        if ($.browser.msie && $.browser.version < 7) { $("#SearchType").css("visibility", "hidden"); }
    };
    $.fn.vmenus.out = function(obj) {
        $(obj).find("ul").css("visibility", "hidden");
        if ($.browser.msie && $.browser.version < 7) { $("#SearchType").css("visibility", "visible"); }
    };
    $.fn.vmenus.additem = function(items, par, id) {
        if (typeof (items[id]) == "undefined") return "";
        var uls = par;
        if (items[id].length > 0) {
            uls = $("<ul></ul>").appendTo(par).css("visibility", "hidden");
        };
        for (var i = 0; i < items[id].length; i++) {
            var item = items[id][i];
            if (typeof (item[1]) == "undefined") continue;
            var li = $("<li onmouseover=\"$.fn.vmenus.over(this)\" onmouseout=\"$.fn.vmenus.out(this)\"></li>").appendTo(uls);
            var a = $("<a></a>").appendTo(li);
            a.html(item[1]);
            a.attr("href", item[2]);
            a.attr("target", item[3]);
            $.fn.vmenus.additem(items, li, item[0]);
        };
    };
    $.fn.vmenus.defaults = {
        minWidth: 9, 	// requires em unit.
        maxWidth: 25, 	// requires em unit.
        extraWidth: 0			// extra width can ensure lines don't sometimes turn over due to slight browser differences in how they round-off values
    };
})(jQuery);



function AddSubMenu(id)
{
	if(!topmenus[id] || topmenus[id].length<1)return "";
	for(var i=0;i<topmenus[id].length;i++)
	{
		var item=topmenus[id][i];
		html+="<li><a href=\""+item[2]+"\" target=\""+item[3]+"\">"+item[1]+"</a>";
		html+=AddSubMenu(item[0]);
		html+="</li>";
	};
	return html;
};
function ShowSubmenu(obj,id)
{
	var menubox=$("#menubox");
	if(!menubox.attr("id"))
	{
		$('body').prepend('<div id="menubox"><IFRAME style=\"width:1px;height:1px\"></IFRAME></div>');
		menubox=$("#menubox");
		menubox.css({position:"absolute",
			background:"#ccc",
			top:"0px",
			left:"0px",
			filter:"alpha(Opacity=50)",
			zIndex:"10",
			MozOpacity:"0.5"
			});
	};
	
};

function CheckSearch(form)
{
	var keywords = form.Keywords.value;
	if (keywords == "" || keywords == "请输入关键字")
	{
			keywords = "";
			alert("请输入关键字");
			form.Keywords.focus();
			return false;
	}
	keywords = escape(keywords);
	switch (parseInt(form.SearchType.value))
	{
		case 2:
			document.location.href = SitePath + "NewsList.aspx?Keywords=" + keywords;
			break;
		default:
			document.location.href = SitePath + "CommodityList.aspx?SearchType=1&Keywords=" + keywords;
			break;
	}
	return false;
};

function UPTop(id)
{
	var s=id.split(',');
	for(var i=0;i<s.length;i++)
	{
		if(s[i].trim()=="")continue;
		$.get(AjaxUrl+"Commodity.aspx",{Action:"upjs",
				t:"top",
				ChannelID:2,
				CategoryID:s[i],
				PageSize:10},
			function(t,s)
			{});
	}
};


function ShowDialog(t,s,m,w)
{
	ShowMask();
	var box=$("#DialogBox");
	if(!box.attr('id'))
	{
		$('body').prepend('<div id="DialogBox">&nbsp;</div>');
		box=$("#DialogBox");
	}
	var html="<div class=\"h\"><div class=\"t\">"+t+"</div>";
	if(m)html+="<div class=\"m1\">"+m+"</div>";
	html+="<div class=\"r\"><a href=\"javascript:HideDialog();\"></a></div>";
	html+="</div><div class=\"m\">"+s+"</div>";
	box.html(html);
	if(w)
	{
			box.css({width:w+"px"});
	}
	var wi=GetWindowInfo();	
	var top=(wi.Height/2)-(parseInt(box.height())/2)+wi.ScrollY+"px";
	box.css({"left":(($(document).width())/2-(parseInt(box.width())/2))+"px",
		"top":top,
		"position":"absolute"
	}).show();	
};
function HideDialog()
{
	var box=$("#DialogBox");
	if(box.attr('id'))
	{
		box.hide();
	}
	HideMask();
};

function IsEmail(s) {
    var re = /^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
    return re.test(s);
};


(function($) {                                          // Compliant with jquery.noConflict()
$.fn.jCarouselLite = function(o) {
    o = $.extend({
        btnPrev: null,
        btnNext: null,
        btnGo: null,
        mouseWheel: false,
        auto: null,

        speed: 200,
        easing: null,

        vertical: false,
        circular: true,
        visible: 3,
        start: 0,
        scroll: 1,

        beforeStart: null,
        afterEnd: null
    }, o || {});

    return this.each(function() {                           // Returns the element collection. Chainable.

        var running = false, animCss=o.vertical?"top":"left", sizeCss=o.vertical?"height":"width";
        var div = $(this), ul = $("ul", div), tLi = $("li", ul), tl = tLi.size(), v = o.visible;

        if(o.circular) {
            ul.prepend(tLi.slice(tl-v-1+1).clone())
              .append(tLi.slice(0,v).clone());
            o.start += v;
        }

        var li = $("li", ul), itemLength = li.size(), curr = o.start;
        div.css("visibility", "visible");

        li.css({overflow: "hidden", float: o.vertical ? "none" : "left"});
        ul.css({margin: "0", padding: "0", position: "relative", "list-style-type": "none", "z-index": "1"});
        div.css({overflow: "hidden", position: "relative", "z-index": "2", left: "0px"});

        var liSize = o.vertical ? height(li) : width(li);   // Full li size(incl margin)-Used for animation
        var ulSize = liSize * itemLength;                   // size of full ul(total length, not just for the visible items)
        var divSize = liSize * v;                           // size of entire div(total length for just the visible items)

        li.css({width: li.width(), height: li.height()});
        ul.css(sizeCss, ulSize+"px").css(animCss, -(curr*liSize));

        div.css(sizeCss, divSize+"px");                     // Width of the DIV. length of visible images

        if(o.btnPrev)
            $(o.btnPrev).click(function() {
                return go(curr-o.scroll);
            });

        if(o.btnNext)
            $(o.btnNext).click(function() {
                return go(curr+o.scroll);
            });

        if(o.btnGo)
            $.each(o.btnGo, function(i, val) {
                $(val).click(function() {
                    return go(o.circular ? o.visible+i : i);
                });
            });

        if(o.mouseWheel && div.mousewheel)
            div.mousewheel(function(e, d) {
                return d>0 ? go(curr-o.scroll) : go(curr+o.scroll);
            });

        if(o.auto)
            setInterval(function() {
                go(curr+o.scroll);
            }, o.auto+o.speed);

        function vis() {
            return li.slice(curr).slice(0,v);
        };

        function go(to) {
            if(!running) {

                if(o.beforeStart)
                    o.beforeStart.call(this, vis());

                if(o.circular) {            // If circular we are in first or last, then goto the other end
                    if(to<=o.start-v-1) {           // If first, then goto last
                        ul.css(animCss, -((itemLength-(v*2))*liSize)+"px");
                        // If "scroll" > 1, then the "to" might not be equal to the condition; it can be lesser depending on the number of elements.
                        curr = to==o.start-v-1 ? itemLength-(v*2)-1 : itemLength-(v*2)-o.scroll;
                    } else if(to>=itemLength-v+1) { // If last, then goto first
                        ul.css(animCss, -( (v) * liSize ) + "px" );
                        // If "scroll" > 1, then the "to" might not be equal to the condition; it can be greater depending on the number of elements.
                        curr = to==itemLength-v+1 ? v+1 : v+o.scroll;
                    } else curr = to;
                } else {                    // If non-circular and to points to first or last, we just return.
                    if(to<0 || to>itemLength-v) return;
                    else curr = to;
                }                           // If neither overrides it, the curr will still be "to" and we can proceed.

                running = true;

                ul.animate(
                    animCss == "left" ? { left: -(curr*liSize) } : { top: -(curr*liSize) } , o.speed, o.easing,
                    function() {
                        if(o.afterEnd)
                            o.afterEnd.call(this, vis());
                        running = false;
                    }
                );
                // Disable buttons when the carousel reaches the last/first, and enable when not
                if(!o.circular) {
                    $(o.btnPrev + "," + o.btnNext).removeClass("disabled");
                    $( (curr-o.scroll<0 && o.btnPrev)
                        ||
                       (curr+o.scroll > itemLength-v && o.btnNext)
                        ||
                       []
                     ).addClass("disabled");
                }

            }
            return false;
        };
    });
};

function css(el, prop) {
    return parseInt($.css(el[0], prop)) || 0;
};
function width(el) {
    return  el[0].offsetWidth + css(el, 'marginLeft') + css(el, 'marginRight');
};
function height(el) {
    return el[0].offsetHeight + css(el, 'marginTop') + css(el, 'marginBottom');
};

})(jQuery);