﻿//======================================================//
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();
}
//======================================================//
function ResetForm()
{
	document.aspnetForm.reset();
}
//======================================================//
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 ClearDiv(divID)
{
	if($(divID))
		$(divID).innerHTML = "";
}
//======================================================//
function HideDiv(divID)
{
	if($(divID))
		$(divID).className = "hidden";
}
//======================================================//
var myimages = new Array();
function PreloadingImg(){
	for (x=0; x<PreloadingImg.arguments.length; x++){
		myimages[x] = new Image();
		myimages[x].src = PreloadingImg.arguments[x];
	}
}
//======================================================//
function $(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);
}
//======================================================//
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 ToggleDis(id)
{
	if($(id).style.display == "none")
		$(id).style.display = "";
	else
		$(id).style.display = "none";
}
//======================================================//