function XMLHTTPRequest(){
	var xhr;
	try {xhr = new ActiveXObject("Msxml2.XMLHTTP");} 
	catch (e) {
		try {xhr = new ActiveXObject("Microsoft.XMLHTTP");} 
		catch (e) {xhr = false;}
		if (!xhr && typeof XMLHttpRequest != 'undefined') xhr = new XMLHttpRequest();
	}
	return xhr;
}
function getObject(str){
	if(typeof str == "Object" || typeof str == "object" ) return str;
	else return document.getElementById(str);
}

function sendRequestHttp(req,url,params,httpMethod){	
	req.open(httpMethod,url,true);
	req.setRequestHeader("Content-type","application/x-www-form-urlencoded");
	req.send(params);	
}

function getPage(obj, params)
{	
	var xhr=new XMLHTTPRequest();	
	xhr.onreadystatechange=function(){
	
		if(xhr.readyState == 4){
			if (xhr.status==200){
				var xmlDoc=xhr.responseXML;
				//alert(xhr.responseText);
				
				if (!xmlDoc || !xmlDoc.documentElement){
					LOAD.showBottomStatus(xhr.responseText); 
					return;
				}
				
				//LOAD.showBottomStatus(lang['processing_success']);
				if (typeof obj == "string" || typeof obj == "String") obj = getObject(obj);
				obj.innerHTML = xmlDoc.getElementsByTagName('data')[0].firstChild.nodeValue;				
				
			}
		}
	}
	
	sendRequestHttp(xhr, txtfile ,params,"POST");	
}

//
// getPageSize()
// Returns array with page width, height and window width, height

function getPageSize()
{
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}

	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight);
	return arrayPageSize;
}

function isNumber(str){
    str = str.toString();
    var re = /^[-]?\d*\.?\d*$/;
    if (!str.match(re)||str.length=="") return false;
	else  return true;
}

function formatCommas(numString) {
    var re = /(-?\d+)(\d{3})/;
    while (re.test(numString)) {
        numString = numString.replace(re, "$1,$2");
    }
    return numString;
}

function isEmail(vl) {
    var re = /^[\w-]+(\.[\w-]+)*@([\w-]+\.)+[a-zA-Z]{2,7}$/;
    if (!vl.match(re)) {        
        return false;
    } else {
        return true;
    }
}

//********************/
// loaddingImg
//
var LOAD = new Object();
var arr_visable = Array();
	arr_visable[0] = "embed";
	arr_visable[1] = "select";

LOAD.crLoading = function(txt)
{
	this.hiddenTag(arr_visable, "hidden");
	
	var bodyObj = document.getElementsByTagName("body")[0];	
	if(bodyObj.firstChild.id != 'boxLoading')
	{
		box = document.createElement("div");
		box.setAttribute("id","boxLoading");
		bodyObj.insertBefore(box, bodyObj.firstChild);	
		box.onclick=function()
		{
			box.style.visibility = "hidden";
			LOAD.hiddenTag(arr_visable, "visible");
		}
	}		
	this.box = bodyObj.firstChild;	
	this.box.style.visibility = "visible";		
	var pageSize = getPageSize();	
	this.box.style.height 	=  pageSize[1]+"px"; //
	
	this.showBottomStatus(txt, true);
}

LOAD.reLoading = function()
{
	if(getObject("boxLoading") && getObject("boxLoading").style.visibility != "hidden")
	{
		this.hiddenTag(arr_visable, "visible");
		this.box = getObject("boxLoading");
		this.slide();
	}	 
}

LOAD.hiddenTag = function(_arr, _hidden)
{
	for (var i = 0; i < _arr.length; i++)
	{
		var _f = document.getElementsByTagName( _arr[i] );
		if(_f)
		{
			for (var j = 0; j< _f.length; j++)
			{
				_f[j].style.visibility = _hidden;
			}
		}
	}
}
var oTimeStatus = null;
LOAD.showBottomStatus = function(txt, flag)
{
	objLoaddingStatus.style.display = 'block';
	objLoaddingStatus.lastChild.innerHTML = "<blink>"+txt+"</blink>";
	
	if(!flag || typeof(flag) == "undefined")
	{		
		LOAD.reLoading();
	}
	if(oTimeStatus)
	{
		window.clearTimeout(oTimeStatus);
		oTimeStatus = null;
	}
	
	oTimeStatus = window.setTimeout("showbox('DIV_2009_BOTTOM','none')",3000);
}


var maxFilter = 60;
var timeFilter = 0;
var speed = 10;
LOAD.slide = function()
{
	maxFilter -= 18;
	if(maxFilter > 0){
		timeFilter = window.setTimeout("LOAD.slide()",speed);
		this.box.style.filter = "alpha(opacity="+maxFilter+")";
		this.box.style.opacity = maxFilter / 100;			
	}
	else {
		maxFilter = 60;
		timeFilter = 0;
		window.clearTimeout(timeFilter);		
		this.box.style.visibility = "hidden";
		this.box.style.filter = "alpha(opacity="+maxFilter+")";
		this.box.style.opacity = maxFilter / 100;
	}
}

LOAD.boxBorder = function(str){
	var htm = "<div class='dialog_box'>"
				+"<div class='topBar' onmousedown=\"dragStart(event,'boxBlock')\" OnMouseUp=\"dragStop(event)\">"
					+"<div class='title'>"+str+"</div>"
					+"<div class='close'>X</div>"
				+"</div>"
				+"<div class='content'><br/><br/><br/><br/><br/><br/></div>"
				+"</div>";
	return htm;
}

function getCheckbox(frm, field)
{
	var str = "";
	var n =  frm[field].length;
	if(n > 1){
		for (var i = 0; i < frm[field].length; i++)
		{
			if(frm[field][i].checked) str += frm[field][i].value+",";
		}
		str = str.substring(0, str.length - 1);
	}
	else if(n == 1)
	{
		if(frm[field].checked) str += frm[field].value;
	}
	return str;
}

// extends checkbox == radio
clickCheck2Radio = function(frmfrm, obj, field)
{
	if(obj.checked ==  true)
	{
		for(var i = 0; i < frmfrm[field].length; i++)
		{	
			frmfrm[field][i].checked = false;
		}
		obj.checked = true;
	}
}

function validateImg(imgUrl){
	if(imgUrl){
	    validformFile = /(.gif|.GIF|.jpg|.JPG|.png|.PNG)$/;
	    if(!validformFile.test(imgUrl)){
	      	alert('Support *.gif| *.jpg| *.png');
		  	return false;
		}
	}else {return false;}
}

function showbox(id,show){	
	var obj = getObject(id);	
	if(!show) obj.style.display='none';
	else obj.style.display=(obj.style.display != 'block')?"block":"none";
}

var txtfile = "txtprocessing.php";
var xmlfile = "xmlprocessing.php";



var loadingImg = new Image();
	loadingImg.src ='images/lightbox-ico-loading.gif';//loading.gif

