﻿	var divTop,divLeft,divWidth,divHeight,docHeight,docWidth,objTimer,i = 0;
	var win = 'MYM_win';
	var min_win = 'MYM_win_min';
	var win_style = 'z-index:99999; left: 0px; visibility: hidden;width: 200px; position: absolute; top: 0px; height: 258px;border:#88ADBB 1px solid;background:url(http://www.heg.bj.cn/Popgb.gif);';
	var title_style = 'color: #333333; font-size:12px; height:25px;line-height:25px; padding:0,5,0,5;';
	var win_content_style = 'font-size:12px;over-flow:hidden;text-align:middle;';
	
	var win_content_html = '<iframe src="' + iframe_url + '" width="200" height="221" scrolling="no" frameborder="no" style="border:1px #ccc solid;margin:0 auto;"></iframe>';
	var form_item_style = 'margin-bottom:0px;margin:0;padding:0;';
	var form_ul = 'margin:0;padding:0;list-style-type:none;';
	
	var iframe_url = 'http://www.heg.bj.cn/MYM_POP_Server/form.html';
	var win_content_html = '<iframe src="' + iframe_url + '" width="196" height="245" scrolling="no" frameborder="no" style="margin:0 auto;"></iframe>';
	var min_win_style = 'z-index:99999; left: 0px; visibility: hidden;width: 200px; position: absolute; top: 0px;background:url(http://www.heg.bj.cn/Popgb.gif);';
	var left_btn_style = 'cursor:pointer;display:block;float:right;width:10px;margin-left:4px;';
	var right_btn_style = 'float:left;display:block;';
	
	//var form_action = 'form.html';
	
	/*

	win_content_html = '<div style=\'margin:10px;\'>';
	win_content_html += '<form style="margin:0;padding:0;" action="' + form_action + '" method="post" id="sendOrder">';
	win_content_html += '<textarea name="content" id="content" style="width:190px;height:120px;border:#88ADBB 1px solid;margin-bottom:5px;font-size:12px;color:#666666;"></textarea><br/>';
	win_content_html += '<input type="text" id="contact" name="contact" style="width:190px;border:#CDDCDE 1px solid;margin-bottom:5px;font-size:12px;color:#666666;" /><br/>';
	win_content_html += '<input type="text" id="phone" name="phone" style="width:190px;border:#CDDCDE 1px solid;margin-bottom:5px;font-size:12px;color:#666666;" /><br/>';
	win_content_html += '<input type="text" id="address" name="address" style="width:190px;border:#CDDCDE 1px solid;margin-bottom:5px;font-size:12px;color:#666666;" /><br/>';
	win_content_html += '<input type="button" style="border:#88ADBB 1px solid;width:60px;height:23px;line-height:23px;background:#D0E6E8;color:#6B9AAB;" value="发送" onclick="sendMessage()" />';
	win_content_html += '</form></div>';
	
	var content_msg = '请您在这里写入您需要订购的产品及联系方式，我们会及时与您联系！';
	var contact_msg = '请输入联系人';
	var phone_msg = '请输入电话';
	var address_msg = '请输入地址';
	*/
	

	function buildView()
	{
		var view = "<div id='MYM_win' style='" + win_style + "'>";
		view += "<div style='" + title_style + "'><span style='" + right_btn_style + "'>在线下订单</span>"
		view += "<span style='" + left_btn_style + "' onclick='minDiv()'>×</span></div>";
		view += "<iframe id='targetUrl' name='targetUrl' frameborder='0' border='0' scrolling='no' width='220' height='150' style='display:none' src='about:blank'></iframe>";
		view += "<div id='contentDiv' style='" + win_content_style + "'>" + win_content_html;
		view += "</div>";
		view += "</div>";

		var mview = "<div id='MYM_win_min' style='" + min_win_style + "'>";
		mview += "<div style='" + title_style + "'><span style='" + right_btn_style + "'>在线下订单</span>";
		mview += "</span><span style='" + left_btn_style + "' onclick='maxDiv()'>□</span></div>";
		mview += "</div>";
		
		var popContainer = document.createElement("div");
		popContainer.innerHTML = view + mview;
		document.body.appendChild(popContainer);
		
	}

	function getMsg()
	{
		buildView();
		try
		{
			//alert(document.getElementById("MYM_win").style.visibility);
			divTop = parseInt(document.getElementById("MYM_win").style.top,10);
			divLeft = parseInt(document.getElementById("MYM_win").style.left,10);
			divHeight = parseInt(document.getElementById("MYM_win").offsetHeight,10);
			divWidth = parseInt(document.getElementById("MYM_win").offsetWidth,10);
			docWidth = document.documentElement.clientWidth==0?document.body.clientWidth:document.documentElement.clientWidth;
			docHeight = document.documentElement.clientHeight==0?document.body.clientHeight:document.documentElement.clientHeight;
			document.getElementById("MYM_win").style.top = parseInt(document.documentElement.scrollTop==0?document.body.scrollTop:document.documentElement.scrollTop,10) + docHeight + 10;// divHeight
			document.getElementById("MYM_win").style.left = parseInt(document.documentElement.scrollLeft==0?document.body.scrollLeft:document.documentElement.scrollLeft,10) + docWidth - divWidth;
			document.getElementById("MYM_win").style.visibility="visible";
			objTimer = window.setInterval("moveDiv()",10);
		}
		catch(e){
			alert('error');
		}
	}
	
	//初始化位置
	function resizeDiv()
	{
		i+=1;
		//if(i>300) closeDiv() //想不用自动消失由用户来自己关闭所以屏蔽这句
		try
		{
			divHeight = parseInt(document.getElementById("MYM_win").offsetHeight,10);
			divWidth = parseInt(document.getElementById("MYM_win").offsetWidth,10);
			//docWidth = document.documentElement.clientWidth;
			//docHeight = document.documentElement.clientHeight;
			docWidth = document.documentElement.clientWidth==0?document.body.clientWidth:document.documentElement.clientWidth;
			docHeight = document.documentElement.clientHeight==0?document.body.clientHeight:document.documentElement.clientHeight;
			//document.getElementById("MYM_win").style.top = docHeight - divHeight + parseInt(document.documentElement.scrollTop,10);
			//document.getElementById("MYM_win").style.left = docWidth - divWidth + parseInt(document.documentElement.scrollLeft,10);
			document.getElementById("MYM_win").style.top = docHeight - divHeight + parseInt(document.documentElement.scrollTop==0?document.body.scrollTop:document.documentElement.scrollTop,10);
			document.getElementById("MYM_win").style.left = docWidth - divWidth + parseInt(document.documentElement.scrollLeft==0?document.body.scrollLeft:document.documentElement.scrollLeft,10);
		}
		catch(e){}
	}
	
	//最小化
	function minsizeDiv()
	{
		i+=1
		//if(i>300) closeDiv() //想不用自动消失由用户来自己关闭所以屏蔽这句
		try
		{
			divHeight = parseInt(document.getElementById("MYM_win_min").offsetHeight,10);
			divWidth = parseInt(document.getElementById("MYM_win_min").offsetWidth,10);
			docWidth = document.documentElement.clientWidth;
			docHeight = document.documentElement.clientHeight;
			document.getElementById("MYM_win_min").style.top = docHeight - divHeight + parseInt(document.documentElement.scrollTop,10);
			document.getElementById("MYM_win_min").style.left = docWidth - divWidth + parseInt(document.documentElement.scrollLeft,10);
		}
		catch(e){}
	}
	
	//移动
	function moveDiv()
	{
	try
	{
		if(parseInt(document.getElementById("MYM_win").style.top,10) <= (docHeight - divHeight + parseInt(document.documentElement.scrollTop==0?document.body.scrollTop:document.documentElement.scrollTop,10)))
		{
			window.clearInterval(objTimer);
			objTimer = window.setInterval("resizeDiv()",1);
		}
		divTop = parseInt(document.getElementById("MYM_win").style.top,10);
		document.getElementById("MYM_win").style.top = divTop -1;
	}
		catch(e){}
	}
	
	function minDiv()
	{
		closeDiv();
		document.getElementById('MYM_win_min').style.visibility='visible';
		objTimer = window.setInterval("minsizeDiv()",1);
	}
	
	function maxDiv()
	{
		document.getElementById('MYM_win_min').style.visibility='hidden';
		document.getElementById('MYM_win').style.visibility='visible';
		objTimer = window.setInterval("resizeDiv()",1);
		//resizeDiv()
		getMsg();
	}
	
	function closeDiv()
	{
		document.getElementById('MYM_win').style.visibility='hidden';
		document.getElementById('MYM_win_min').style.visibility='hidden';
		if(objTimer) window.clearInterval(objTimer);
	}
	
	//getMsg();
	//window.onload = function()
	//{
		
		window.setTimeout('getMsg()',5000);
	//}
	
	window.onresize = function(){
		resizeDiv();
	}
	window.onerror = function(){}