﻿//提交一个表单
function formSubmit(form)
{
	form.submit();
}

//跳转
function jumpUrl(url)
{
	window.location = url;
}

var inputIn = true;
//创建一个编辑框
function createEditInput(table, filed, infoId, changeFiled, val, size)
{
	if(inputIn == true)
	{
		size = size == "" ? 20 : size;
		$('#'+changeFiled + 'Msg_' + infoId).html('<input type="text" name="editValue" id="edit'+ changeFiled +'_'+ infoId +'" value=\''+ val +'\' size="'+ size +'" onblur="changeInputBool(\''+ table +'\', \''+ filed +'\', '+ infoId +', \''+ changeFiled +'\', this.value)"/>');
		$('#edit'+ changeFiled + '_' + infoId).focus();
		inputIn = false;
	}
}

var textareaIn = true;
//创建一个文本域编辑框
function createEditTextarea(changeFiled, infoId, ajax)
{
	if(textareaIn == true)
	{
		var value= $('#'+changeFiled + 'Msg_' + infoId).html();
		value = value.replace(/&lt;br&gt;/g,   "");
		value = value.replace(/<br>/g,   "");
		$('#'+changeFiled + 'Msg_' + infoId).html('<textarea name="editValue" id="edit'+ changeFiled +'_'+ infoId +'" cols="60" rows="6" onblur="changeInputBool(\''+ changeFiled +'\', '+ infoId +', this.value, '+ ajax +')">'+ value +'</textarea>');
		if(ajax == "xajax_editAnswer")
		{
			$("#replyid_" + infoId).html('');
		}
		$('#edit'+ changeFiled + '_' + infoId).focus();
		textareaIn = false;
	}
}

var selectIn = true;
//创建一个下拉选择框
function createEditSelect(table, filed, infoId, changeFiled, value, paramsValue, paramsKey)
{
	if(selectIn == true)
	{
		var text = '<select name="editValue" id="edit'+ changeFiled +'_'+ infoId +'" onblur="changeInputBool(\''+ table +'\', \''+ filed +'\', '+ infoId +', \''+ changeFiled +'\', this.value)">';
		
		var _default = "";
		var arr = new Array();
		var arr_val = new Array();
		var arr = paramsValue.split(",");
		var arr_val = paramsKey.split(",");
		for(var i = 0; i< arr.length; i++)
		{
			if(arr[i] == value)
			{
				_default = 'selected';
			}
			text += '<option value="'+ arr_val[i] +'" '+ _default +'>'+ arr[i] +'</option>';
			_default = "";
		}
		text += '</select>';
		$('#'+changeFiled + 'Msg_' + infoId).html(text);
		selectIn = false;
	}
}

//检查正确后执行修改
function changeInputBool(changeFiled, infoId, value, ajax)
{
	inputIn = true;
	textareaIn = true;
	selectIn = true;
	ajax(changeFiled + 'Msg_' + infoId, infoId, value);
}

function changeImg(mypic,id){ 
	var xw = 640; 
	var xl = 160; 
	
	var width = mypic.width;
	var height = mypic.height; 
	var bili = width/height; 
	
	var A=xw/width; 
	var B=xl/height; 

	if(A>=1||B>1){ 
		if(A<B){ 
			mypic.width=xw; 
			mypic.height=xw/bili; 
		} 
		if(A>B){ 
			mypic.width=xl*bili; 
			mypic.height=xl; 
		} 
	}
	$('#' + id).attr('style', 'cursor: pointer;').attr('title', '点击放大').unbind('click').removeAttr('onclick').bind("click", function(){bigImg(id);});
}

function bigImg(id){
	$('#' + id).removeAttr('onload').removeAttr('width').removeAttr('height').attr('style', 'cursor:pointer;').attr('title', '点击缩小').unbind('click').removeAttr('onclick').bind("click", function(){changeImg(this,id);});
	if($('#' + id).attr('width') > 500){
		$('#' + id).attr('width', 500);
	}
}