﻿var dataChangNotification = "你输入的影讯数据尚未保存。";
var hasCleared = false;

function clientValidate(source, clientside_arguments)
{
	if (clientside_arguments.Value.length <= 2000)
	{
		clientside_arguments.IsValid = true;
	}
	else
	{
		clientside_arguments.IsValid = false;
	}
}

function setNotification()
{
	window.onbeforeunload = function(){ return dataChangNotification; };
}

function clearNotification()
{
	window.onbeforeunload = null;
}
//function pricesel()
//{
//        alert($("ctl00_ContentPlaceHolderMain_PanelcopyPrice").style.display);
//	$("ctl00_ContentPlaceHolderMain_PanelcopyPrice").style.display="block";
//	 alert($("ctl00_ContentPlaceHolderMain_PanelcopyPrice").style.display);
//}


function updateValues(slt)
{
	var textboxId = slt.id.replace("DropDownListMovie", "TextBoxLength");
	$(textboxId).value = slt.options[slt.selectedIndex].attributes["runtime"].value;
	
	var languageSelectedId = slt.id.replace("DropDownListMovie", "DropDownListLanguage");
	setSelected($(languageSelectedId), slt.options[slt.selectedIndex].attributes["language"].value);

	var versionSelectedId = slt.id.replace("DropDownListMovie", "DropDownListVersion");
	setSelected($(versionSelectedId), slt.options[slt.selectedIndex].attributes["version"].value);
}

function setSelected(slt, value)
{
	for (i = 0; i < slt.options.length; i++)
	{
		if (slt.options[i].value == value)
		{
			slt.options[i].selected = true;
			
			break;
		}
	}
}

function toggleHelpLayer()
{
	var obj = $("helplayer");
	
	obj.style.display = (obj.style.display == "none" ? "block" : "none");
}

function setShowHelpStatus(obj)
{
	var status = !obj.checked;

	setPersistentCookie("HelpStatus", status);

	Mtime.ManageShowtime.Web.AjaxService.SetShowHelpStatus(status);
}

function simulateClick(obj)
{
	if(document.all)
	{
		obj.click();
	}
	else
	{
		var e = document.createEvent("MouseEvent");
		e.initEvent("click", true, false);
		obj.dispatchEvent(e);
	}
}

function searchMovie(text)
{
	text = text.replace(" ", "");
	
	if(text != "")
	{
		Mtime.ManageShowtime.Web.AjaxService.SearchMovie(text, cb_searchMovie);
	}
}

function cb_searchMovie(result)
{
	$("divSearchResult").innerHTML = result;
}

function setSelectedMovieId(id)
{
	$("ctl00_ContentPlaceHolderMain_HiddenFieldSelectedMovieId").value = id;
}

function checkSelectedMovieId()
{
	if($("ctl00_ContentPlaceHolderMain_HiddenFieldSelectedMovieId").value == "-1")
	{
		return false;
	}
	
	return true;
}

function searchCinema()
{
	var query;
	var text = $("TextBoxSearch").value;
	
	if(isHintText(text))
	{
		query = "";
	}
	else
	{
		query = text;
	}
	
	var byName = $("RadioName").checked;
	var byId = $("RadioId").checked;
	var byCity = $("RadioCity").checked;
	
	var url = "/Default.aspx?";

	if(byName)
	{
		location.href = url + "Name=" + encodeURI(query);
	}
	else if(byCity)
	{
		location.href = url + "City=" + encodeURI(query);
	}
	else if(byId)
	{
		if(!/^[0-9]+$/.test(query))
		{
			$("spanError").style.visibility = "visible";
			
			return;
		}
		
		location.href = url + "ID=" + query;
	}
}

function clearHint(obj)
{
	if(obj.className.indexOf("gray") >= 0)
	{
		obj.value = "";
		obj.onfocus = null;
	}

	obj.className = obj.className.replace("gray", "");
}

function clearHintByHall(obj)
{
	obj.parentNode.className = "on";
	
	if(obj.className.indexOf("gray") >= 0)
	{
		obj.value = "";
		obj.className = "";
	}
}

function clearText(obj)
{
	if(isHintText(obj.value))
	{
		obj.value = "";
	}

	$("spanError").style.visibility = "hidden";
}

function isHintText(text)
{
	var filters = new Array('输入影院名称', '输入影院ID', '输入城市名称');
	
	var i;
	
	for(i in filters)
	{
		if(text == filters[i])
		{
			return true;
		}
	}
	
	return false;
}

function setText(id, text)
{
	var obj = $(id);
	
	if(isHintText(obj.value) || obj.value == "")
	{
		obj.value = text;
	}
}

function keyPressSubmit(objId)
{
	if(event.keyCode == 13)
	{
		var obj = $(objId);
		
		obj.click();
		
		return false;
	}
	else
	{
		return true;
	}
}

function uploadComplete()
{
	if($("iframeUpload").contentWindow.document.title == "SUCCESS")
	{
		$("ctl00_ContentPlaceHolderMain_ButtonRefresh").click();
	}
}

function autoFit(obj)
{
	var doc = obj.contentWindow.document;
	var h;
	
	try
	{
		if(document.body)
		{
			h = doc.body.scrollHeight;
		}
	}
	catch(e)
	{
		if(doc.documentElement && doc.documentElement.scrollHeight)
		{
			h = doc.documentElement.scrollHeight;
		}
	}
	
	obj.height = h;
}

function showHide(showId, hideId)
{
	$(showId).show();
	$(hideId).hide();
}

function switchShowHide(id1, id2)
{
	var obj1 = $(id1);
	var obj2 = $(id2);
	
	if(obj1.style.display == "none")
	{
		obj2.hide();
		obj1.show();
	}
	else
	{
		obj1.hide();
		obj2.show();
	}
}

function validateLength(id, length)
{
	if($(id).value.bytelength() > 1000)
	{
		$('pErrorMessage').style.visibility = "visible";
	
		return false;
	}
	
	return true;
}

function clearValidateMessage(id)
{
	$(id).style.visibility = "hidden";
}

function timePriceTextboxBlur(obj)
{
	obj.parentNode.className = "";
}

function priceTextboxBlur(obj)
{
	obj.parentNode.className = "one";
}


function shortcutKey()
{
	setNotification();

	var ops = window.event.srcElement.options;
	var chr = String.fromCharCode(window.event.keyCode).toUpperCase();
	
	for(i = 0; i < ops.length; i++)
	{
		if (ops[i].firstletter == chr)
		{
			ops[i].selected = true;
			
			break;
		}
	}

	updateValues(window.event.srcElement);
}

String.prototype.bytelength = function()
{
	var arr = this.match(/[^\x00-\xff]/ig);

	return this.length + (arr == null ? 0 : arr.length);
};

function getCookie(sName)
{
	var cookie = "" + document.cookie;
	var start = cookie.indexOf(sName);
	
	if (cookie == "" || start == -1) 
		return "";
	var end = cookie.indexOf(';',start);
	
	if (end == -1)
		end = cookie.length;
	
	return unescape(cookie.substring(start+sName.length + 1,end));
}

function setCookie(sName, value)
{
	document.cookie = sName + "=" + escape(value) + ";path=/;";
}

function setPersistentCookie(sName, value)
{
	document.cookie = sName + "=" + escape(value) + ";path=/;expires=Fri, 1 Jan 2010 00:00:00 GMT;";
}

String.prototype.Trim = function() {
	return this.replace(/(^[\s　]*)|([\s　]*$)/g,"");
};

String.prototype.trim = String.prototype.Trim;