﻿//======================================================//
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 = document.getElementsByTagName("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 EmailValid(val)
{
	var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	return filter.test(val);
}
//======================================================//
function WaterMark(id, opt, txt, flipDir)
{
	if($(id).value == ""){$(id).style.color=opt._onblur;$(id).value=txt;}
	$(id).onblur = function(){
		if($(id).value==""){$(id).value=txt}
		if($(id).value==txt){$(id).style.color=opt._onblur;if(flipDir){FlipDir(id,opt);}}
	};
	$(id).onfocus = function(){
		if($(id).value==txt){$(id).value=""}
		$(id).style.color=opt._onfocus;
		if($(id).value==""){if(flipDir){FlipDir(id,opt);}}
	};
}
function FlipDir(id,opt)
{
	if($(id).style.direction == "")
		$(id).style.direction = opt.dir;
	if($(id).style.direction == "rtl")
		$(id).style.direction = "ltr";
	else
		$(id).style.direction = "rtl";
}
//======================================================//
function ClearDiv(divID)
{
	if($(divID))
		$(divID).innerHTML = "";
}
//======================================================//
function HideDiv(divID)
{
	if($(divID))
		$(divID).className = "hidden";
}
//======================================================//
function RefreshUpdatePanel(hiddenFieldID)
{
	var hiddenField = $(hiddenFieldID);
	if (hiddenField) {
		hiddenField.value = (new Date()).getTime();
		__doPostBack(hiddenFieldID,'');
	}
}
function FileName(obj, divID)
{
	if(obj.value != "")
	{
		document.getElementById(divID).innerHTML = obj.value.substring(obj.value.lastIndexOf('\\')+1);

	}
}
//======================================================//
function addBookmark(title,url)
{
	if(window.sidebar)
	{window.sidebar.addPanel(title, url,"");}
	else
		if(document.all)
		{window.external.AddFavorite( url, title);}
		else
			if(window.opera && window.print )
			{return true;}
}
//======================================================//
function $(e){if(typeof e=='string')e=document.getElementById(e);return e};
function $G(e){if(typeof e=='string')e=document.getElementById(e);return e};
function collect(a,f){var n=[];for(var i=0;i<a.length;i++){var v=f(a[i]);if(v!=null)n.push(v)}return n};
//======================================================//
ajax={};
ajax.x=function(){try{return new ActiveXObject('Msxml2.XMLHTTP')}catch(e){try{return new ActiveXObject('Microsoft.XMLHTTP')}catch(e){return new XMLHttpRequest()}}};
ajax.serialize=function(f){var g=function(n){return f.getElementsByTagName(n)};var nv=function(e){if(e.name)return encodeURIComponent(e.name)+'='+encodeURIComponent(e.value);else return ''};var i=collect(g('input'),function(i){if((i.type!='radio'&&i.type!='checkbox')||i.checked)return nv(i)});var s=collect(g('select'),nv);var t=collect(g('textarea'),nv);return i.concat(s).concat(t).join('&');};
ajax.send=function(u,f,m,a){var x=ajax.x();x.open(m,u,true);x.onreadystatechange=function(){if(x.readyState==4)f(x)};if(m=='POST')x.setRequestHeader('Content-type','application/x-www-form-urlencoded');x.send(a)};
ajax.get=function(url,func){ajax.send(url,func,'GET')};
ajax.gets=function(url){var x=ajax.x();x.open('GET',url,false);x.send(null);return x};
ajax.post=function(url,func,args){ajax.send(url,func,'POST',args)};
ajax.update=function(url,elm){var e=$(elm);var f=function(r){e.innerHTML=r};ajax.get(url,f)};
ajax.submit=function(url,fun,frm){ajax.post(url,fun,ajax.serialize(frm))};
//======================================================//
function DoTrim(strTmp)
{
	strTmp = strTmp.replace(/^\s*|\s*$/g,"");
	return strTmp;
}
//======================================================//
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 faderT,lastID;
function DivFader(id, msg)
{
	if($(id))
	{
		if(lastID == id)
			clearTimeout(faderT);
		$(id).innerHTML = msg;
		changeOpac(100, id);
		$(id).style.display='';
		faderT = setTimeout("opacity('" + id + "', 100, 0, 700)", 6000);
		faderT = setTimeout("$('" + id + "').style.display='none'", 6800);
		lastID = id;
	}
}
//======================================================//
function opacity(id, opacStart, opacEnd, millisec) {
    //speed for each frame
    var speed = Math.round(millisec / 100);
    var timer = 0;

    //determine the direction for the blending, if start and end are the same nothing happens
    if(opacStart > opacEnd) {
        for(i = opacStart; i >= opacEnd; i--) {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    } else if(opacStart < opacEnd) {
        for(i = opacStart; i <= opacEnd; i++)
            {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    }
}
//change the opacity for different browsers
function changeOpac(opacity, id) {
    var object = document.getElementById(id).style;
    object.opacity = (opacity / 100);
    object.MozOpacity = (opacity / 100);
    object.KhtmlOpacity = (opacity / 100);
    object.filter = "alpha(opacity=" + opacity + ")";
}
//======================================================//
function ToggleDisplay(id, isDis)
{
	var dis = (isDis) ? "" : "none";
	for (var i=2; i<ToggleDisplay.arguments.length; i++)
		$(arguments[i]+id).style.display = dis;
}
//======================================================//
function Comm(id)
{
	if($(id))
		$(id).style.display = ($(id).style.display == "none") ? "" : "none";
}
//======================================================//

