﻿// JavaScript Document

$(window).load(function () {
	iHeight = $("#intromain").height()-100;
	iHeight = iHeight<180?180:iHeight;

	if(iHeight > $("#inleftmenu").height())
		$("#inleftmenu").height(iHeight);
});

$(document).ready(function () {
	iHeight = $("#intromain").height()-100;
	iHeight = iHeight<180?180:iHeight;

	if(iHeight > $("#inleftmenu").height())
		$("#inleftmenu").height(iHeight);

	//如果需要初始化地区，则在此初始化
	if(typeof(initDrops) != "undefined")
	{
		initDrops(document.getElementById("AreaDrop"), document.getElementById("CityDrop"));
	}

	//如果需要初始化选择的地区，则在这里初始化

	if(document.getElementById("AreaDrop") != null)
	{
		setSort(document.getElementById('AreaDrop'), document.getElementById('CityDrop'));
	}

	if(document.getElementById("IndDrop") != null)
	{
		document.getElementById("IndDrop").value = document.getElementById("CompInd").value;
	}

	if(document.getElementById("UpdateButton") != null)
	{
		$("#UpdateButton").click(OnStartUpdate);
	}

	$("#AccountName").keyup(function () {
		$("#DefaultUser").val($("#AccountName").val());
	});
	$("#AccountName").change(function () {
		$("#DefaultUser").val($("#AccountName").val());
	});

	$("#LoginBt").click(function () {
		$.cookie("AccountName", $("#AccountName").attr("value"), {path: "/", domain: "itlanhai.com"});
		$.cookie("UserName", $("#UserName").attr("value"), {path: "/", domain: "itlanhai.com"});
		$.cookie("UserPass", $("#UserPass").attr("value"), {path: "/", domain: "itlanhai.com"});

		window.open("http://crm.itlanhai.com/chat/index.html", "_blank", "height=600,width=800,toolbar=no,menubar=no,scrollbar=no,status=no,resizable=yes");
	});

	$("#AccountName").bind("keypress", OnLoginKeyPress);
	$("#UserName").bind("keypress", OnLoginKeyPress);
	$("#UserPass").bind("keypress", OnLoginKeyPress);

	$("#GotoRegBt").click(function () {
		document.location="uregister.aspx";
	});
});

function OnLoginKeyPress(evt)
{
	if(evt.keyCode == 13)
	{
		$.cookie("AccountName", $("#AccountName").attr("value"), {path: "/", domain: "itlanhai.com"});
		$.cookie("UserName", $("#UserName").attr("value"), {path: "/", domain: "itlanhai.com"});
		$.cookie("UserPass", $("#UserPass").attr("value"), {path: "/", domain: "itlanhai.com"});

		window.open("http://crm.itlanhai.com/chat/index.html", "_blank", "height=600,width=800,toolbar=no,menubar=no,scrollbar=no,status=no,resizable=yes");
	}
}

function OnStartUpdate()
{
	scrollTop = 0;

	if(document.documentElement && document.documentElement.scrollTop)
		scrollTop = document.documentElement.scrollTop;
	else
		scrollTop = document.body.scrollTop;

	//如果含有地区控件，则将地区控件的值更新到隐藏框
	if(document.getElementById("AreaDrop") != null)
	{
		if($("#AreaDrop").val() == "0" || ($("#CityDrop").css("display") != "none" && $("#CityDrop").val() == "0"))
		{
			alert("请选择地区！");
			return false;
		}
		document.getElementById("ProvinceID").value = document.getElementById("AreaDrop").value;
		document.getElementById("CityID").value = document.getElementById("CityDrop").value;
	}

	//如果含有行业控件，则将行业控件的值更新到隐藏框
	if(document.getElementById("IndDrop") != null)
	{
		document.getElementById("CompInd").value = document.getElementById("IndDrop").value;
	}
	return true;
}
