﻿//======================================================//
function AddLoadEvent(func){
	var oldonload = window.onload;
	if(typeof window.onload != 'function') {
	window.onload = func;
	}else{
	window.onload = function() {
		if(oldonload){
		oldonload();
		}
		func();
	}}
}
//======================================================//
var wini;
function Win(URL, name, width, height)
{
	var x = screen.width;
	var y = screen.height;
	x=(x/2)-(width/2);
	y=(y/2)-(height/2);
	wini = window.open(URL, name, "top="+y+",left="+x+",toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,width="+width+",height="+height+",resizable=yes");
	wini.window.focus();
}
var swini;
function SemiWin(URL, name, width, height)
{
	var x = screen.width;
	var y = screen.height;
	x=(x/2)-(width/2);
	y=(y/2)-(height/2);
	swini = window.open(URL, name, "top="+y+",left="+x+",toolbar=no,location=yes,status=yes,menubar=no,scrollbars=yes,width="+width+",height="+height+",resizable=yes");
	swini.window.focus();
}
//======================================================//
function ResetForm()
{
	document.aspnetForm.reset();
	var sel = $Tag("select");
	for(var i = 0;i < sel.length;i++)
		RefreshDDL(sel[i]);
	Custom.clear();
}
//======================================================//
function HideSubmit(obj, vldGrp)
{
	if(typeof(Page_ClientValidate) == 'function')
	{
		Page_ClientValidate(vldGrp);
		if(Page_IsValid)
			obj.style.display = 'none';
		else
			return false;
	}
	return true;
}
//======================================================//
function WaterMark(id, opt, txt, flipDir)
{
	if(!$G(id))
		return;

	if($G(id).value == ""){$G(id).style.color=opt._onblur;$G(id).value=txt;}
	$G(id).onblur = function(){
		if($G(id).value==""){$G(id).value=txt}
		if($G(id).value==txt){$G(id).style.color=opt._onblur;if(flipDir){FlipDir(id,opt);}}
	};
	$G(id).onfocus = function(){
		if($G(id).value==txt){$G(id).value=""}
		$G(id).style.color=opt._onfocus;
		if($G(id).value==""){if(flipDir){FlipDir(id,opt);}}
	};
}
function FlipDir(id,opt)
{
	if($G(id).style.direction == "")
		$G(id).style.direction = opt.dir;
	if($G(id).style.direction == "rtl")
		$G(id).style.direction = "ltr";
	else
		$G(id).style.direction = "rtl";
}
//======================================================//
function Wait()
{
	document.body.style.cursor = 'wait';
}
//======================================================//
function ClearDiv(divID)
{
	if($G(divID))
		$G(divID).innerHTML = "";
}
//======================================================//
function RefreshUpdatePanel(hiddenFieldID)
{
	var hiddenField = $G(hiddenFieldID);
	if(hiddenField){
		hiddenField.value = (new Date()).getTime();
		__doPostBack(hiddenFieldID,'');
	}
}
//======================================================//
function FileName(obj)
{
	if(obj.value != "")
		document.getElementById(obj.divi).innerHTML = obj.value.substring(obj.value.lastIndexOf('\\')+1);
}
//======================================================//
function Limit()
{
	if(document.all && event.type == "paste")
		this.blur();
	
	if(this.value.length > this.getAttribute("maxi"))
		this.value = this.value.substring(0,this.getAttribute("maxi"));
	$G(this.getAttribute("spani")).innerHTML = this.getAttribute("maxi") - this.value.length;
}
function Maxi()
{
	var ar = $Tag("textarea");
	
	for(var i=0; i < ar.length; i++)
		if(ar[i].getAttribute("maxi") != null)
		{
			ar[i].onpaste = Limit;
			ar[i].onkeyup = Limit;
			ar[i].onblur = Limit;
		}
}
AddLoadEvent(Maxi);
//======================================================//
function AddFav(title,url)
{
	if (window.sidebar) // firefox
		window.sidebar.addPanel(title, url, "");
	else if(window.opera && window.print){ // opera
		var elem = document.createElement('a');
		elem.setAttribute('href',url);
		elem.setAttribute('title',title);
		elem.setAttribute('rel','sidebar');
		elem.click();
	}
	else if(document.all)// ie
		window.external.AddFavorite(url, title);
}
function MakeHome(obj,url)
{
	if(document.all)
	{
		obj.style.behavior = "url(#default#homepage)";
		obj.setHomePage(url);
	}
}
//======================================================//
function $G(e){if(typeof e=='string') e=document.getElementById(e);return e};
function $Tag(e){if(typeof e=='string')e=document.getElementsByTagName(e);return e};
//======================================================//
function Trim(strTmp)
{
	strTmp = strTmp.replace(/^\s*|\s*$/g,"");
	return strTmp;
}
//======================================================//
var myimages = new Array();
function PreloadingImg()
{
	for(x = 0;x < PreloadingImg.arguments.length;x++)
	{
		z=myimages.length;
		myimages[z] = new Image();
		myimages[z].src = PreloadingImg.arguments[x];
	}
}
//======================================================//
function IsIE6()
{
	return (/MSIE (5\.5|6\.)/.test(navigator.userAgent));
}
//======================================================//
function CreateCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}
function ReadCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}
function EraseCookie(name) {
	CreateCookie(name,"",-1);
}
//======================================================//
var fa;
function Fader(id, t, r, txt, fadeAfter)
{
	fadeAfter = (fadeAfter == null) ? 7000 : fadeAfter;
	clearTimeout(fa);
	if(t != null)
		$G(id).style.top=t+"px";
	if(r != null)
		$G(id).style.right=r+"px";
	if(txt != null)
		$G(id).innerHTML=txt;

	if($("#" + id).stop)
		$("#" + id).stop(true, true);
	$("#" + id).show();
	fa = setTimeout('$("#'+id+'").fadeOut(5000)', fadeAfter);
}
//======================================================//
function RedirectSec(intSec, spani, url)
{
	intSec--;

	$G(spani).innerHTML = intSec+1;
	if(intSec == -1)
	{
		setTimeout('window.location="' + url + '"',200);
		return;
	}
	setTimeout("RedirectSec(" + intSec + ", '" + spani + "', '" + url + "')", 1000);
}
//======================================================//
