/*
'=====================================================================
' Module Name:
' File name: video.js
' Author: william.lu
' Project : my_bebo
' Copyright (c) all rights reserved by juuyou.com Co., LTD.
' Create on 2009/02/17
' Version: 1.0
'
'=====================================================================
'*********************************************************************
' Usage: Video页JS函数集
'
'*********************************************************************
*/

/**  定义juuyou.video命名空间  **/
juuyou.video = {};

								
/**  验证上传视频文件格式  **/
juuyou.video.CheckVideoFileType = function(fileId){
	var FileName = new String($obj(fileId).value);//文件名
	var fileType = new String(FileName.substring(FileName.lastIndexOf(".")+1,FileName.length));//文件扩展名

	var suppotFile = new Array();
    suppotFile[0] = "wmv";
    suppotFile[1] = "asf";
    suppotFile[2] = "asx";
    suppotFile[3] = "rm";
    suppotFile[4] = "rmvb";
    suppotFile[5] = "mpg";
    suppotFile[6] = "mpeg";
    suppotFile[7] = "mpe";
    suppotFile[8] = "3gp";
    suppotFile[9] = "mov";
    suppotFile[10] = "mp4";
    suppotFile[11] = "m4v";
    suppotFile[12] = "avi";
    suppotFile[13] = "dat";
    suppotFile[14] = "mkv";
    suppotFile[15] = "flv";
    suppotFile[16] = "vob";
    suppotFile[17] = "mp3";
    suppotFile[18] = "wma";

	fileType = fileType.toLowerCase();
	
    for(var i =0;i<suppotFile.length;i++){
		if(suppotFile[i]==fileType){
     		$obj("hid_fileType_flag").value = 1;
     		break;
    	}else{
    		$obj("hid_fileType_flag").value = 0;
			continue;
		}
	}
	//juuyou.common.switchDisplayShow(errDivId);
	
}

/**  验证上传并提交 **/
juuyou.video.CheckVideoAdd = function(){
	juuyou.video.CheckVideoFileType("upload_file");
	if($obj("hid_fileType_flag").value == "0"){
		//alert("请选择正确的视频文件");
		juuyou.common.switchDisplayShow("div_file_error");
		return false;
	}else{
		juuyou.common.switchDisplayNone("div_file_error");
	}
	
	if(juuyou.common.trim($obj("txt_title").value) == ""){
		alert("标题不能为空");
		return false;
	}
	
	if(juuyou.common.getSelectVal("sel_category") == ""){
		alert("请选择分类");
		return false;
	}
	
	if(juuyou.common.trim($obj("txt_description").value) == ""){
		alert("描述不能为空");
		return false;
	}
	
	if(juuyou.common.validWordLength('txt_description', 'txt_word_cnt', 1000)){
		juuyou.common.switchDisplayShow("div_doing");
		juuyou.common.switchDisplayNone("div_upload");
		return true;
	}else{
		return false;
	}

}

/**  验证并提交视频留言 **/
juuyou.video.checkCommentSubmit = function(){
	var intCnt = 0;
	var strVal = juuyou.common.trim($obj("txtAreaComment").value);
	var strIdVal = juuyou.common.trim($obj("hid_videoId").value);
	var strActiveId = juuyou.common.trim($obj("hid_active_id").value);
	
	intCnt = strVal.length;

	if(intCnt == 0){
		alert("评论不能为空");
		return;
	}

	if(!juuyou.common.validWordLength('txtAreaComment', 'txt_word_cnt', 250)){
		alert("字符数最大不得超过250");
		return;
	}
	

	$.ajax({
 		type:"POST",
		url:"../json/videoCommentAdd.php",
		async:true,
		data: {
			txtAreaComment: strVal,
			videoId: strIdVal,
			activeId: strActiveId
		},
		success:function(data){
			if(juuyou.common.trim(data) == juuyou.common.json.failure){
				alert("提交失败");
			}else{
				$obj("div_video_comments").innerHTML = data;
				juuyou.video.initComment();
			}
		}
	});
}

juuyou.video.initComment = function(){
	$obj("txtAreaComment").value = "";
	$obj("txt_word_cnt").value = "250";
}

