// JavaScript Document
//更新多条数据的一个属性  name checkbox名称
CMS.UpdMess=function(action,ps,name,callback){
	var ids;
	ids=CMS.getCheckBoxs(name);
	alert('更新'+ids);
}

//打开窗口
CMS.openWin=function(name,url){
	var ids=CMS.getCheckBoxs(name);
	if(ids.split(',').length!=1 || ids.length==0){alert('请选择一条数据后点击!');return;}
	var win=$L.ui.getWindow(url+ids+'.htm',true);
}

CMS.getValueSetToForm=function(key,form,action){
	CMS.getInfo(key,action,function(store){$L.setValues(form,store);});
}

//点击量自增
CMS.doCountIc=function(action,keys,handle){
	 $L.Ajax.getResult("com.ogw.cms.core.Execute",{'action':action,'keys':keys},function(msg){});
};

//搜索
CMS.searchkey=function(key){
	if(key.length==0){alert('请输入关键字后点击搜索!');return;}
	var url='/searlist_key-'+key+'.htm';
	//$L.sendRedirect(url);
	window.open(url);
}

//通过控件搜索
CMS.search=function(el){
	var key=$L.ID(el).value;
	CMS.searchkey(key);
}

//发布留言
CMS.sendLiuyan=function(form){
	var ps=$L.getForm(form);
	ps.cid=CMS.getRequest().cid;
	if(!ps.title){alert('对不起,留言标题必须填写!');return;}
	if(!ps.content){alert('对不起,留言内容必须填写!');return;}
	CMS.saveInfo("添加留言",ps,function(msg){if(msg){alert('留言发送成功!');}else{alert('留言发送失败!');return;}})
}
//上传
CMS.upload=function(el,imgel){
	new $L.ui.FileUpload(function(src){$L.ID(el).value=src;if(imgel)$L.ID(imgel).src=src;});
}

CMS.videoUpload=function(targetHandle,action){
   var _L=parent.$L;
   if(!_L.ui.FileUploadWin){
       _L.ui.FileUploadWin=new _L.ui.Window();
	   _L.ui.FileUploadWin.setTitle("文件上传窗口");
   }
   var win=_L.ui.FileUploadWin;
   win.setModle(true);
   win.show();
   win.setSize(420,358);
   win.setCenter(); 
   if(!action){action="fileUploadSave.jcms";}
   var frame=win.getContent(true);
   win.addButton("上传视频","icon_save",function(){
		_L.fileUploadCallBack=function(src){
	       if(targetHandle)targetHandle(src);
		   _L.ui.FileUploadWin.close();
        };
	    _L.ID("uploadForm").submit();
   });
   win.addButton("取消上传","icon_del",function(){
	    win.close();
   });
   var main=_L.create("DIV",{},frame);
   var hiddenFrame="uploadHiddenFrame";
   var content="<IFRAME name='"+hiddenFrame+"' style='display:none;'></IFRAME>";
   content+="<FORM id='uploadForm' method=post enctype=multipart/form-data  action='"+action+"' target='"+hiddenFrame+"'>";
   content+='<div style="width:418px; height:300px; overflow:hidden; border:1px solid #CCC;">';
   content+='<div style="width:370px; height:55px; overflow:hidden; float:left; padding-top:35px; padding-left:25px;">';
   content+='<div style="font-size:12px; color:#666;">点击浏览从电脑选择一个FLV格式视频</div>';
   content+='<div style="padding-top:10px;">';
   content+='<input type="file" name="file1" id=""file21 style="width:350px; height:22px; border:1px solid #CCCCCC;" />';
   content+='</div></div>';
   content+='<div style="width:100%; height:70px; overflow:hidden; float:left;"></div>';
   content+='<div style="width:360px; overflow:hidden; float:left; padding-left:25px;">';
   content+='<h4 style="font-size:12px;color:#656563; float:left;">提示：</h4>  ';
   content+='<div style="clear:both; height:0px; width:100%; font-size:1px; line-height:0px; visibility:hidden; overflow:hidden;"></div>';
   content+='<ul style="width:355px; overflow:hidden; float:left; padding-left:5px; font-size:12px; color:#626260;">';
   content+='<li style=" width:355px; line-height:20px;font-family:Verdana, Geneva, sans-serif;">●&nbsp;&nbsp;仅支持FLV 格式视频文件文件。</li>';
   content+=' </ul></div></div></FORM>';
   main.innerHTML+=content;
   setTimeout(function(){win.onTop();},100);  
}
//上传视频
CMS.uploads=function(el,imgel){
	new CMS.videoUpload(function(src){$L.ID(el).value=src;if(imgel)$L.ID(imgel).src=src;});
}

//上传文件
CMS.uploadFile=function(el,imgel){
	new CMS.fileUpload(function(src){$L.ID(el).value=src;if(imgel)$L.ID(imgel).src=src;});
}
CMS.fileUpload=function(targetHandle,action){
   var _L=parent.$L;
   if(!_L.ui.FileUploadWin){
       _L.ui.FileUploadWin=new _L.ui.Window();
	   _L.ui.FileUploadWin.setTitle("文件上传窗口");
   }
   var win=_L.ui.FileUploadWin;
   win.setModle(true);
   win.show();
   win.setSize(420,358);
   win.setCenter(); 
   if(!action){action="fileUploadSave.jcms";}
   var frame=win.getContent(true);
   win.addButton("上传文件","icon_save",function(){
		_L.fileUploadCallBack=function(src){
			if(!src.endWith('.doc') & !src.endWith('.doc') & !src.endWith('.xls')& !src.endWith('.xlsx')&!src.endWith('.txt')&!src.endWith('.ppt')&!src.endWith('.pptx')){
				alert('对不起,文件上传现在只支持doc,docx,xls,xlsx,ppt,pptx,txt格式文档 \n您上传的文档不是以上格式,请检查文件后再次上传!');return;
			}
	       if(targetHandle)targetHandle(src);
		   _L.ui.FileUploadWin.close();
        };
	    _L.ID("uploadForm").submit();
   });
   win.addButton("取消上传","icon_del",function(){
	    win.close();
   });
   
   var main=_L.create("DIV",{},frame);
   var hiddenFrame="uploadHiddenFrame";
   var content="<IFRAME name='"+hiddenFrame+"' style='display:none;'></IFRAME>";
   content+="<FORM id='uploadForm' method=post enctype=multipart/form-data  action='"+action+"' target='"+hiddenFrame+"'>";
   content+='<div style="width:418px; height:300px; overflow:hidden; border:1px solid #CCC;">';
   content+='<div style="width:370px; height:55px; overflow:hidden; float:left; padding-top:35px; padding-left:25px;">';
   content+='<div style="font-size:12px; color:#666;">点击浏览从电脑选择一个文件</div>';
   content+='<div style="padding-top:10px;">';
   content+='<input type="file" name="file1" id="file21" style="width:350px; height:22px; border:1px solid #CCCCCC;" />';
   content+='</div></div>';
   content+='<div style="width:100%; height:70px; overflow:hidden; float:left;"></div>';
   content+='<div style="width:360px; overflow:hidden; float:left; padding-left:25px;">';
   content+='<h4 style="font-size:12px;color:#656563; float:left;">提示：</h4>  ';
   content+='<div style="clear:both; height:0px; width:100%; font-size:1px; line-height:0px; visibility:hidden; overflow:hidden;"></div>';
   content+='<ul style="width:355px; overflow:hidden; float:left; padding-left:5px; font-size:12px; color:#626260;">';
   content+='<li style=" width:355px; line-height:20px;font-family:Verdana, Geneva, sans-serif;">●&nbsp;&nbsp;仅支持doc,docx,ppt,pptx,xls,xlsx 格式。</li>';
   content+=' </ul></div></div></FORM>';
   main.innerHTML+=content;
   setTimeout(function(){win.onTop();},100);  
}


CMS.showPhoto=function(src,isMask,host){
	if(!host)host="";

	if(!$L._vsel){
       $L._vsel=$L.create("DIV",{},document.body);
	   $L._vsel.setStyles("width:100px;height:100px;border:10px solid #999999;position:absolute;display:none;text-align:center;z-index:100000;");
	   $L._vsel.setStyles("background-color:#FFFFFF;overflow:hidden;");
	   $L._vsel.content=$L.create("DIV",{},$L._vsel);
	   $L._vsel.content.setStyles("width:100%;height:100%;position:relative;");
	   $L._vsel.closeBtn=$L.create("IMG",{src:host+'/testIcons/closelabel.gif'},$L._vsel.content);
	   $L._vsel.closeBtn.setStyles("position:absolute;right:10px;top:10px;");
	   $L._vsel.closeBtn.style.width='21px';
	    $L._vsel.closeBtn.style.height='20px';
	   $L._vsel.closeBtn.onclick=function(){$L.hide($L._vsel);if(isMask)$L.Mask.hide();}
   }
   $L._vsel.setStyles("width:100px;height:100px;");
   var lightBox=new $L.PhotoLightBox(src,isMask);
};

CMS.loginWithoutYZM=function(formId){
    var form=$L.getForm(formId);
    if(!/^[a-zA-Z0-9_]{5,16}/.test(form.account)){alert("请正确输入登录帐号!");return;}
	if(!form.psw){alert("请输入登录密码!");return;}
	$L.Ajax.getResult("com.ogw.cms.ajax.user.LoginOutCodeAjax",form,function(msg){
		if(msg=='error.out'){alert("外部访问，参数缺少!");return;}
		if(msg=='error.login'){alert("请不要重复登陆!");return;}
		if(msg=='error.404'){alert("登录帐号不存在!");return;}
		if(msg=='error.fb'){alert("对不起该帐号被禁止!");return;}
		if(msg=='error.psw'){alert("对不起，您的密码不对!");return;}
		if(msg=='ok'){$L.sendRedirect('/downloadList_cid-51.htm');}
	});
};

//收藏产品
CMS.saveFav=function(pid){
	$L.Ajax.getResult("com.ogw.cms.ajax.SaveFavProduct",{'pid':pid},function(msg){
		if(msg=='ok'){alert('商品收藏成功');return;}
		if(msg=='exist'){alert('对不起,该商品您已经收藏不能重复收藏!');return;}
		else{alert('收藏失败,请重试')}
	});
}
//加入购物车
CMS.saveCar=function(pid){
	$L.Ajax.getResult("com.ogw.cms.ajax.SaveCar",{'pid':pid},function(msg){
		if(msg=='ok'){alert('商品加入购物成功');$L.refresh();return;}
		if(msg=='exist'){alert('商品不存在!');$L.refresh();return;}
		if(msg=='error'){alert('商品加入购物失败');$L.refresh();return;}
	});
}

//支付订单
CMS.payOrder=function(ps){
	$L.Ajax.getResult("cms.ogw.pay.PayOrder",ps,function(msg){
		if(msg=='nologin'){alert('您没有登录,不能进行操作!');return;}
		if(msg=='noid'){alert('订单编号为空,请重试');return;}
		if(msg=='notexist'){alert('订单不存在');return;}
		if(msg=='orderError'){alert('订单出错,请重试!');return;}
		if(msg=='error'){alert('订单出错,请重试!');return;}
		window.location.href=msg;
	});
}

CMS.payCar=function(carid){
	$L.Ajax.getResult("cms.ogw.pay.PayCar",{'carid':carid},function(msg){
		if(msg=='null'){alert('没有传入关键值!请重试!');return;}
		if(msg=='toolow'){alert('产品价值为0不需支付!');return;}
		if(msg=='error'){alert('支付出错!');return;}
		window.location.href=msg;
	});
	
}

//支付
CMS.pay=function(ids){
	$L.Ajax.getResult("cms.ogw.pay.PayCar",{'ids':ids},function(msg){
		if(msg=='null'){alert('没有传入关键值!请重试!');return;}
		if(msg=='toolow'){alert('产品价值为0不需支付!');return;}
		if(msg=='error'){alert('支付出错!');return;}
		window.location.href=msg;
	});
}

CMS.payCar=function(formid){
	var check=document.getElementsByName("ids");
	var ps={};ps.ids='';
	for(var i=0;i<check.length;i++){
		if(check[i].checked)
			if(ps.ids)ps.ids+=','+check[i].value;
			else ps.ids+=check[i].value;
	}
	if(ps.ids)CMS.pay(ps.ids);
}

CMS.logOut=function(page){
	$L.Ajax.getResult("com.ogw.cms.ajax.user.OutAjax",{},function(msg){
		 if(msg=='ok'){if(page)$L.sendRedirect(page);else $L.sendRedirect('/index.htm'); return;}
	});
}

CMS.sex=[{'label':'男','value':'m'},{'label':'女','value':'l'}];



