
var dialogStyle = "border:#ffffff 1px solid;position:absolute;background-color:White; z-index:999;";
var titleStyle = "height:23px;padding:7px 10px 0;background:#333;color:#fff;";
var hStyle = "float:left;padding:0;margin:0;font-size:14px;line-height:16px;";
var closeStyle = "float:right;cursor:pointer;";
var contentStyle = "padding:20px 15px;background:#fff;";

var dialogExist = false;
//显示一个弹出层
//title:标题
//content:内容
// width, height:宽，高
var title="询价";
var content = "<table style='text-align:left;' width='100%' height='150px' border=1><tr><th>&nbsp;</th><td>&nbsp;</td></tr><tr>"+
"<th>*标题：</th><td style='text-align:left;'><input style='text-align:left;' type='text' style='width:200px' onblur='if(this.value==\"\"){$(\"#spMsg\").html(\"不能为空\")}else{$(\"#spMsg\").html(\"\")}' id='txtTitle' /><span id='spMsg'></span></td>"+
"</tr><tr><th>内容：</th><td style='text-align:left;'><textarea style='text-align:left;' id='txtContect' style='width:250px; height:100px;'></textarea><br><span id='contentTip'></span></td></tr>"+
"<tr><th>&nbsp;</th><td><input type='button' onclick='saveMsg()' id='btnSave' value='发送'>&nbsp;&nbsp;&nbsp;<input type='button' onclick='hideDiv()' value='关闭'></a></td></tr></table>";
var width = 380;
var height= 200;
var _siteID =0;
var _productID=0;
var _language=0;
function showDialog(siteID,productID,language) {
	_siteID = siteID;
	_productID = productID;
	_language = language;
	css="background-color:#FFE3B3;border:1px solid #FFB64B;width:"+width+"px;height:"+height+"px;";
    if (!dialogExist) {
        var divHtml = "";

        divHtml += "<div id='divBig'><iframe style='background:#000;color:white;width:" + (document.body.clientWidth-20) + "px; height:" + (document.body.clientHeight-20) + "px; position:absolute;left:0px;top:0px;filter: Alpha(opacity=0);-moz-opacity:0;opacity:0;'></iframe></div>";
        divHtml += "<div id='divDialog' style='" + dialogStyle + "'>";
        divHtml += "<dl id='hCss' style=\"" + css + "\">";
        divHtml += "<dt><span><div id=\"hTitle\">" + title + "</div></span><a href=\"javascript:hideDiv()\" id=\"close\"  class=\"close\" alt=\"关闭\" title=\"关闭\"></a></dt>";
        divHtml += "<dd><div id=\"divContent\">" + content + "</div><dd></dl>";
        divHtml += "</div>";

        var div = document.createElement("div");
        div.innerHTML = divHtml;
        document.body.appendChild(div);

    }

    dialogExist = true;
    var top = $(document).scrollTop() + (window.screen.availHeight - height) / 2 - 100;
    var left = (window.screen.availWidth - width) / 2;
    $("#divContent").html(content);
    $("#hTitle").html(title);
    $("#divDialog").css("top", top + "px");
    $("#divDialog").css("left", left + "px");
    document.getElementById("hCss").className = css;

    $("#close").show();
    $("#divBig").show();
    $("#divDialog").show();
}

//隐藏弹出层
function hideDiv() {
    $("#divBig").hide();
    $("#divDialog").hide();
}

function saveMsg() {

    var title = '';
    var content = '';
    var siteID = '';
    var productID = '';
    var language ='';

    title = $("#txtTitle").val();
    siteID = _siteID;
    productID = _productID;
    content = $("#txtContect").val();
    language = _language;
    

    if (title == "") {
        $("#spMsg").html("标题不能为空");
        return;
    }
    if (content == "") {
    	$("#contentTip").html("询价内容不能为空"); 
    	return; 
    }
    
    $("#spMsg").html("");
    $("#contentTip").html("");
    $("#btnSave").val("正在发送...");
    $("#btnSave").attr("disabled", "disabled");

    $.ajax({
    	type:"GET",
    	url:"/asyn/inquiry.php",
    	cache:false,
    	dataType:"jsonp",
    	data:"siteID="+_siteID+"&language="+_language+"&productID="+_productID+"&title="+encodeURIComponent(title)+"&content="+encodeURIComponent(content),
    	success:function(data){
			alert(data.result);
			hideDiv();
		},
		error:function()
		{
			alert('询价失败，请重试');
		}
    });
   // });
}
