﻿(function(){

//声bcgogo命名空间
window.bcgogo = {version:1.0};

//常量
bcgogo.GUIDREG = /[a-f\d]{8}(-[a-f\d]{4}){3}-[a-f\d]{12}/i;
bcgogo.EMAIL = /^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;

bcgogo.PageSize = [10, 20, 50, 100];
bcgogo.SystemItemNo = {SystemItemNo:1, DataType:11, EditorType:21, RenderType:22, DataTable:101, ProductTemplateType:1001};
bcgogo.UserState = {Unused:null, Disabled:0, Normal:1};//状态
bcgogo.Platform = {System:1, Supplier:2, Buyer:3};

//常量
bcgogo.URL =
{
	SortXMLPath:"/supplier/sort.xml",//产品种类XML
	ModelXMLPath:"/Product/model.xml",//车型XML

	SettingSelect:"/Handle/S.ashx?method=select",
	FavorateProduct:"/Buyer2/FavorateProduct.xml",//收藏夹的XML

//	ProductGet:"/Handle/Product.ashx?method=get",
//	ProductInsert:"/Handle/Product.ashx?method=insert",
	ProductUpdate:"/Admin/Product.ashx?method=update",	
//	ProductCategorySelect:"/Handle/ProductCategory.ashx?method=select",//分类

//	ProductListHandle:"/Handle/ProductList.ashx",

	UserGet:"/Handle/User.ashx?method=get",
	UserLogin:"/Handle/User.ashx?method=login",
	UserModify:"/Handle/User.ashx?method=modify",
	UserModifyUsername:"/Handle/User.ashx?method=modifyusername",
	UserModifyPassword:"/Handle/User.ashx?method=modifypassword",
	UserUpdate:"/Handle/User.ashx?method=update",

	//待处理的订单列表
//	OrderListPendingSelect:"/BIZ/b.ashx?method=select",//订单查询接口
//	OrderListPendingGet:"/BIZ/b.ashx?method=get",//查询某个具体的订单
//	OrderListPendingProductGet:"/BIZ/p.ashx?method=get",//查询某个订单的具体产品列表
//	OrderListPendingDelivery:"/BIZ/b.ashx?method=210005",//发货
//	OrderListPendingReturns:"/BIZ/b.ashx?method=210004",//退单
//	OrderProducts:"",//订单产品查询

	//获取用户信息，及用户所属单位的信息
	UserInfoGet:"/Handle/UserInfo.ashx",
	UserExit:"/Handle/User.ashx?method=exit",
	SystemTime:"/Public/SystemTime.ashx",
	
	//采购单
	BillProduct:"/Handle/p.ashx?method=billproduct",
	
	//首页统计注册，采购商，产品的信息
	Statistics:"/Public/Statistics.ashx",
	//公司动态
	companyNews:"CompanyNews.xml",
	Register:"/Handle/user.ashx?method=register",//快速注册
	SynchroUpadate:"/Handle/user.ashx?method=synchroupadate",//用户资料与企业信息同步更新
	RetrievePassword:"/Handle/user.ashx?method=retrievepassword",
	//S0
	S0Select:"/Handle/S0.ashx?method=select",
	S0Delete:"/Handle/S0.ashx?method=delete",

	HtmlEditorPage:"/Product/HtmlEditor/0.htm",//富文本框编辑页面
	DefaultPage:"/0.htm"//默认网页	
};

bcgogo["get"] = function(url){try{return eval(js.http["get"](url));}catch(e){return null;}}
bcgogo.post = function(url, data){try{return eval(js.http.post(url, data));}catch(e){return null;}}



bcgogo.Text = 
{
	NetworkError:"网络访问失败！",
	ConfirmDelete:"确定要删除吗？",
	ConfirmStopProduct:"确定要停用该产品吗？",
	ConfirmCancel:"确定取消吗？"
}


//bcgogo.SystemTime = function(callback)
//{
//	this.bTimeAlert = true;
//	
//	var r = bcgogo.get("/Handle/SystemTime.ashx");
//	
//	window.setTimeout(bcgogo.getSystemTime, 60 * 1000);
//	
//	if (r === null)
//	{
//		if (bTimeAlert)
//		{
//			bTimeAlert = false;
//			alert(bcgogo.Text.NetworkError);
//		}
//	}
//	else if (r instanceof Date)
//	{
//		bTimeAlert = true;
//		callback(r);
//	}
//	else
//	{
//		if (bTimeAlert)
//		{
//			bTimeAlert = false;
//			alert(r);
//		}
//	}
//}

function HTMLElement(para){this.para(para);}
HTMLElement.prototype.para = function(para){}

bcgogo.A = function(para)
{
	this.htmle = js.html.$("A", para.htmld);
	
	HTMLElement.apply(this, arguments);
}
bcgogo.A.prototype.para = function(para)
{
	if ("text" in para)
	{
		this.htmle.innerHTML = para.text;
		if (!("title" in para))
		{
			this.htmle.title = para.text;
			this.htmle.href = "info:"+para.text;
		}
	}
	
	if ("class" in para)
	{
		this.htmle.className = para["class"];
	}
	
	if ("title" in para)
	{
		this.htmle.title = para.title;
		this.htmle.href = "info:"+para.title;
	}
	
	if ("target" in para)
	{
		this.htmle.target = para["target"];
	}
	
	if ("href" in para)
	{
		if (para.href == null) {this.htmle.removeAttribute("HREF");}
		else {this.htmle.href = para.href;}
	}
	
	if ("onclick" in para)
	{
		if (para.onclick == null)
		{
			this.htmle.onclick = null;
		}
		else
		{
			var me = this;
			this.htmle.onclick = function(evt){try{para.onclick(evt||event, me);}catch(e){}finally{return false;}}
		}
	}
}

bcgogo.UserInfo = bcgogo.get(bcgogo.URL.UserInfoGet);

bcgogo.SystemTime = function(callback)
{
	var r = bcgogo.get(bcgogo.URL.SystemTime);
	
	if (r === null)
	{
		alert(bcgogo.Text.NetworkError);
	}
	else if (r instanceof Date)
	{
		callback(r);
		window.setTimeout("bcgogo.SystemTime(callback);", 60000);
	}
	else
	{
		alert(r);
	}
}

//给select赋值
bcgogo.setValue = function (sel,data)
{
	for (var i =0, l = sel.options.length; i < l; i++)
	{
		if (sel.options[i].value == data || (data == null && sel.options[i].value == ""))
		{
			//sel.options[i].selected = "selected";
			setTimeout(function(){sel.options[i].selected = "selected"}, 1); 
			//sel.selectedIndex = i;
			break;
		}
	}
}

//把时间以特定的格式yyyy-MM-dd hh:mm输出
bcgogo.cast = function(date)
{
	date = new Date(date);
	var year = date.getFullYear();
	var month = date.getMonth()+1; //js从0开始取 
	var day = date.getDate(); 
	var hour = date.getHours(); 
	var minutes = date.getMinutes(); 
	return year + "-" + month + "-" + day + " " + hour + ":" + minutes;
}

//没有框架的页面加载53客服
if (!self.frameElement && (window.location.pathname == "/Supplier/" ||  window.location.pathname == "/"))
{
//	if(document.getElementsByTagName("head") && document.getElementsByTagName("head")[0])
//	{
//		var script = document.getElementsByTagName("head")[0].appendChild(document.createElement("script"));
//		script.type = "text/javascript";
//		script.src = "http://chat.53kf.com/kf.php?arg=tonggou&style=1";
//	}
}

})();
