function ajax_rand(){
	return "&rand="+new Date().getTime()+'&';

}

function json_get(data){
	//alert(data);
	return eval("["+data+"]");
}

function check_pic_type(ext_name){
	var extend = ["jpg", "jpeg", "gif", "png"];
	for (var i = 0; i < extend.length; i++){
		if(ext_name.toLowerCase() == extend[i]){
			return true;
		}
	}
	return false;
}

function check_radio(radioName){
	var radios = document.getElementsByName(radioName);
	for(var i = 0; i < radios.length; i++){
		if(radios[i].checked){
			return true;
		}
	}
	return false;
}
function get_radio(radioName){
	var types = document.getElementsByName(radioName);
	var checkedValue = null;
	for(var i = 0; i < types.length; i++){
		if(types[i].checked){
			checkedValue = types[i].value;
			break;
		}
	}	
	return checkedValue;
}


/*

====================================视频上传部分相关的 js 代码
*/

function video_upload_deal(serverData){
	//alert(serverData);
	if(serverData.indexOf('result') == -1){
		alert('上传失败！请报告管理员！错误信息：'+data);
		return false;
	}
	var ar =json_get(serverData);
	var r = ar[0];

	if(r.result !=='success'){
		alert('上传视频失败,请联系管理员,失败信息:'+r.result+r.msg);
		document.location.reload();
		return false;
	}

	// if r.result ==success

	jQuery("#video_extname").val(r.extname);
	jQuery("#video_file_name").val(r.file_name);
	jQuery("#video_file_path").val(r.file_path);
	jQuery("#video_hash").val(r.hash);
	var i=0;
	for(i=0;i<5;i++){
	  var p = convert_root + '/pic/'+ r.file_name + '_' +i+'.jpg';
	  var html = '<img id = "thumb_pix_8060_'+i+'" class = "img_thumb_pic" src = "'+p+'" onclick="sub_thumb_pic(this, '+i+')" />';
	  //thumb_pic_con
	  jQuery("#thumb_pic_con").append(html);	  			 
	}//end for

	jQuery("#video_info_con").fadeIn('normal');
	jQuery("#upload_con").fadeOut('normal');	

	//默认添加第二张图片为缩略图
	//jQuery("#video_thumb_pic").val(c[0]['pics'][1]);
	sub_thumb_pic(k('thumb_pix_8060_'+1), 1);

}



function getTag(titleid,messageid, targetid){
	var subject = encodeURIComponent($(titleid).value);
	var message = encodeURIComponent($(messageid).value);
	if(message) {
		message = message.substr(0, 500);
		message = message.replace(/&/ig, '', message);
	}
	var x = new Ajax();
	x.get('cp.php?ac=relatekw&subjectenc=' + subject + '&messageenc=' + message, function(s){
		$(targetid).value = s;
	});
}



function sub_thumb_pic(obj, uri){
	//when an thumbpic is clicked by user,after his upload action
	var id = obj.id;
	 jQuery(".img_thumb_pic_click").removeClass("img_thumb_pic_click");
	 jQuery("#"+id).addClass("img_thumb_pic_click");
	 jQuery("#video_thumb_pic").val(uri);
}

function video_album_get_select(args){
	ajaxget('apps.php?do=video&ac=album&op=get-select'+ajax_rand(),'album_select_spn');
}



/* 
*
*   start to define functions in video_view page
*	视频内容页 相关 functions
*
*/

function verifyCode(){
	//output verifycode
	var src= '/apps.php?do=video&ac=comment&op=verifycode&key=video-view-one'+ajax_rand();
	document.writeln('<img id="verifyCode_img" width="70" height="26" src="'+src+'" onclick = "verifyCodeRefresh()" style="cursor:pointer;"" />');

}

function verifyCodeRefresh(){
	//refresh verifycode image
	var src = '/apps.php?do=video&ac=comment&op=verifycode&key=video-view-one'+ajax_rand();
	if($("verifyCode_img")){
		$("verifyCode_img").src = src
	}

}

function video_comment_add(formid, status){
	// if comment added successfully, just load comment by ajax now
	if(1== status){
		$(formid).reset();
		verifyCodeRefresh();
		video_comment_load(video_id);
		
	}
}




function video_comment_load(args){
	//refresh comment list of a video via ajax
	ajaxget('apps.php?do=video&ac=comment&op=get-list&page=1&vid='+video_id+'&ajaxdiv=div_main_content'+ajax_rand(), 'div_main_content');
	return true;

}


function pageReload(arg){	
	//refresh current page
	try{
		document.location.reload();
	}catch(e){
		document.location.href = document.URL;
	}

}