// JavaScript Document


function cDebug(_msg) {

}


/////////////////////////////////////////////////////////////////////
// function name: browserDetect()
if (typeof browser != "object") {
	
var browser = {};
function browserDetect() {
	var version = 0;
	var x = navigator.userAgent.toLowerCase();
	browser.chrome = /chrome/.test(x);
	browser.msie = /msie/.test(x);
	browser.safari = /safari/.test(x);
	browser.notChrome = /version/.test(x);
	browser.firefox = /firefox/.test(x);
	browser.opera = /opera/.test(x);
	browser.current = "unknown";
	browser.offsetTop = 0;
	browser.offsetLeft = 0;	
	
	//cDebug( x );
	
	// Is this a version of IE?
	if(browser.msie) {
		version = x.split("msie")[1].split(";")[0].replace(/ /g,'');
		browser.current = "msie";
		if (version.substr(0,1) == "7") {
			browser.offsetTop = 143;
			browser.offsetLeft = 214;
		}
	}
	
	// Is this a version of Chrome?
	if(browser.chrome) {
		version = x.split("chrome/")[1].split(" ")[0];
		browser.safari = false;
		browser.current = "chrome";
	}
	
	// Is this a version of Safari?
	if(browser.safari && browser.notChrome) {
		version = x.split("version/")[1].split(" ")[0];
		browser.current = "safari";
	}
	
	// Is this a version of Mozilla?
	if(browser.firefox) {
		version = x.split("firefox/")[1].split(" ")[0];
		browser.current = "firefox";
	}
	
	// Is this a version of Opera?
	if(browser.opera) {
		version = x.replace(/ .*/i, '').replace(/opera\//, '');
		browser.current = "opera";
	}
	browser.version = version;
	return version;
} 
browserDetect();

}



////////// PROTOTYPES
Array.prototype.Add = function (_value) {
    this.push(_value);
    return this;
};
Array.prototype.Remove = function (_value) {
    for (var i = 0; i < this.length; i++) {
        if (this[i] == _value) {
            this.splice(i, 1);
            break;
        }
    }
    return this;
};
Array.prototype.RemoveAll = function (_value) {
    for (var i = 0; i < this.length; i++) {
        if (this[i] == _value) {
            this.splice(i, 1);
			this.RemoveAll(_value);
            break;
        }
    }
    return this;
};
Array.prototype.maxCol = function (n) {
    var v = 0;
    for (var i = 0; i < this.length; i++) {
        if (this[i][n] * 1 > v * 1) {
            v = this[i][n];
        }
    }
    return v;
};
Array.prototype.MatchPattern = function (_pattern) {
    if (_pattern) { 
        for (var i = 0; i < this.length; i++) {
			if (this[i]) {
				if (this[i].toString() === _pattern.toString()) {
					return true;
				}
			}
        }
    }
    return false;
};
Array.prototype.RemovePattern = function (_pattern) {
    if (_pattern) { 
        for (var i = 0; i < this.length; i++) {
			if (this[i]) {
				if (this[i].toString() === _pattern.toString()) {
                    this.splice(i, 1);
                    this.RemovePattern(_pattern);					
					return true;
				}
			}
        }
    }
    return false;	
};
Array.prototype.SortNumbers = function() {
  var x, y, holder;
  for(x = 0; x < this.length; x++) {
    for(y = 0; y < (this.length-1); y++) {
      if(this[y] > this[y+1]) {
        holder = this[y+1];
        this[y+1] = this[y];
        this[y] = holder;
      }
    }
  }
};
Array.prototype.Clear = function() {
	while (this.length) {
		this.pop();
	}
};
Array.prototype.RemoveMulti = function (_value, _col) {
    for (var i = 0; i < this.length; i++) {
        if (this[i][_col] == _value) {
            this.splice(i, 1);
            break;
        }
    }
    return this;
};
String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}
String.prototype.ltrim = function() {
	return this.replace(/^\s+/,"");
}
String.prototype.rtrim = function() {
	return this.replace(/\s+$/,"");
}



/////////////////////////////////////////////////////////////////////
// function name: iTimer()

function iTimer() {
    this.func = null;
    this.delay = 3000;
    this.tID = null;
	this.isRunning = false;
}
iTimer.prototype.start = function () {
	this.isRunning = true;
    this.clearInterval();
    this.setInterval(this.func, this.delay);
};
iTimer.prototype.setInterval = function (func, delay) {
    this.func = func;
    this.delay = delay;
    this.tID = window.setInterval(func, delay);
};
iTimer.prototype.clearInterval = function () {
	this.isRunning = false;
    if (this.tID) {
        clearInterval(this.tID);
    }
};


/////////////////////////////////////////////////////////////////////
// function name: nInt(_str)

function nInt(_str) {
    if (_str === null || _str === "" || _str === " " || _str === undefined) {
        _str = 0;
    }
	_str = _str.toString().replace(/[^0-9|\-|\.]/gi, '');
	_str = Math.round(_str);
	if (_str.toString() == "NaN" || _str.toString() === "undeifined" || _str.toString() === "") {
		_str = 0;
	}
    return (_str);
}

/////////////////////////////////////////////////////////////////////
// function name: get_time()

function get_time() {
    var t = new Date();
    return t.getTime();
}



/////////////////////////////////////////////////////////////////////
// function name: text2ascii(_string)

function text2ascii(_string) {
    var out = "";
    for (var i = 0; i < _string.toString().length; i++) {
        out += _string.toString().charCodeAt(i) + ".";
    }
    return out;
}
/////////////////////////////////////////////////////////////////////
// function name: ascii2text(_string)

function ascii2text(_string) {
    var out = "";
    var arr = _string.toString().split(".");
    for (var i = 0; i < arr.length; i++) {
        if (arr[i]) {
            out += String.fromCharCode(arr[i]);
        }
    }
    return out;
}


/////////////////////////////////////////////////////////////////////
// function name: randNum(_n)
function randNum(_n) {
	return Math.floor( Math.random() * nInt(_n) );
}


/////////////////////////////////////////////////////////////////////
// function name: qsValue(_id)
function qsValue(_id, qs) {
    if (!qs) { qs = window.location.search.substring(1); }
    qs = qs.split("&");
    for (var i = 0; i < qs.length; i++) {
        var x = qs[i].split("=");
        if (x[0] == _id) {
			if (x[1] && x[1] !== undefined) {
	            return x[1];
			} else {
				return "";	
			}
        }
    }
	return "";
}


/////////////////////////////////////////////////////////////////////
// function name: qsValueReplace(_id, _v, _qs)
function qsValueReplace(_id, _v, qs) {
	var qsOut = [];
	if (!qs) { qs = window.location.search.substring(1); }
	if (qs) {
		if ( qs.indexOf(_id) < 0) { qs = qs + "&"+ _id +"="+ _v; }
	} else {
		return _id +"="+ _v;
	}
    qs = qs.split("&");
    for (var i = 0; i < qs.length; i++) {
		var x = qs[i].split("=");
//cDebug( x );
		if (x) {
			if (x[0] == _id) {
				x[1] = _v;
			}
		}
		qsOut.push( x[0] +"="+ x[1] );
    }
	return qsOut.join("&");
}




function uncheck_cb(_patten) {
    $("input[type=checkbox]" + _patten).each(
	function () {
		if ($(this).is(":checked")) {
			$(this).click();
		}
	});
}
function checkall_cb(_patten) {
    $("input[type=checkbox]" + _patten).each(
	function () {
		if (!$(this).is(":checked")) {
			$(this).click();
		}
	});
}
function ischecked_cb(_patten) {
	var ret = 0;
    $("input[type=checkbox]" + _patten).each(
	function () {
		if ($(this).is(":checked")) {
			ret = 1;
		}
	});
	return ret;
}
function get_values_cb(_patten) {
	var ret = "";
    $("input[type=checkbox]" + _patten).each(
	function () {
		if ($(this).is(":checked")) {
			ret += $(this).val() +",";
		}
	});
	return ret;
}



/////////////////////////////////////////////////////////////////////
// function name: setStyle(_path)
function setStyle(_path) {
cDebug("setStyle("+ _path +")");
	
	var _ok = 1;
	var _head = document.getElementsByTagName('head').item(0);
	var _script = _head.getElementsByTagName('link');
	var _path_split = _path.split('/');
	for (var i=0; i < _script.length; i++) {
		if (_script[i].src) {
			var _src = _script[i].src.split('/');
			if (_src) {
				var _src_string = _src[_src.length -1].toString().split("?");
				var _path_string = _path_split[_path_split.length -1].toString().split("?");
				if (_src_string[0].toLowerCase() == _path_string[0].toLowerCase()) {
					_ok = 0;
				}
			}
		}
	}	
	if (_ok) {
		var Node = document.createElement('link');
		Node.type = 'text/css';
		Node.rel = 'stylesheet';
		Node.href = _path;
		Node.media = 'screen';
		_head.appendChild(Node);
	}
	return true;
}


/////////////////////////////////////////////////////////////////////
// function name: setScript(_path)
function setScript(_path) {
cDebug("setScript("+ _path +")");

	var _ok = 1;
	var _head = document.getElementsByTagName('head').item(0);
	var _script = _head.getElementsByTagName('script');
	var _path_split = _path.split('/');
	for (var i=0; i < _script.length; i++) {
		if (_script[i].src) {
			var _src = _script[i].src.split('/');
			if (_src) {
				var _src_string = _src[_src.length -1].toString().split("?");
				var _path_string = _path_split[_path_split.length -1].toString().split("?");
				if (_src_string[0].toLowerCase() == _path_string[0].toLowerCase()) {
					_ok = 0;
				}
			}
		}
	}
	if (_ok) {
		_path += '?' + Math.random(0, 1000) + '=' + Math.random(0, 1000);
		var Node = document.createElement('script');
		Node.setAttribute('language', 'javascript');
		Node.setAttribute('type', 'text/javascript');
		Node.setAttribute('src', _path);
		_head.appendChild(Node);
	}
    return true;
}



/////////////////////////////////////////////////////////////////////
// function name: set_link_image(_path)
function setLink_image(_path) {
	var _ok = 1;
	var _head = document.getElementsByTagName('head').item(0);
	var _script = _head.getElementsByTagName('link');
	for (var i=0; i < _script.length; i++) {
		if (_script[i].rel) {
			var _rel = _script[i].rel;
			if (_rel) {
				if (_rel == "image_src") {
					_script[i].href = _path;
					_ok = 0;
				}
			}
		}
	}	
	if (_ok) {
		var Node = document.createElement('link');
		Node.rel = 'image_src';
		Node.href = _path;
		_head.appendChild(Node);
	}
	return true;
}





////////// SPINNER
var SPINNER = {
    id: function () {
        return 'SPINNER';
    },
    show2: function () {
        var id = SPINNER.id();
		$("#"+ id).empty().remove();
        DIV.overlay(id, false);
		
		$('#' + id).css({'background-image':'url(http://op.chamberlandhosting.com/image/bg.trans.40W.diag.png)'});
		$('#' + id +" > table tbody > tr > td").append('<div id="SpinnerContent"></div>');
		
        $.ajax({
            type: "GET",
            url: "http://op.chamberlandhosting.com/js/jquery/plugin/swfobject.js",
            dataType: "script",
            success: function () {
                $(document).ready(function () {
                    if (swfobject.hasFlashPlayerVersion("8")) {
                        var att = {
                            data: "http://op.chamberlandhosting.com/swf/spinner_v1.swf",
                            width: 150,
                            height: 150,
                            align: "middle"
                        };
                        var par = {
                            menu: "false",
                            wmode: "transparent"
                        };
                        var id = "SpinnerContent";
                        var myFlashContent = swfobject.createSWF(att, par, id);
                    }
					
					
                });
            }
        });
    },	
	
    show: function (_page) {
        var id = SPINNER.id();
		$("#"+ id).empty().remove();
        DIV.overlay2(id, "ui-widget-overlay");
//        $('#' + id +" > table tbody > tr > td").append('<div id="SpinnerContent"></div>');
		$('#' + id).append('<div id="'+ SPINNER.id() +'-content"></div>');
		
		var _loadIt = true;
		$("head > script").each(
		function() {
			if ($(this).attr("src") != undefined) {
				if ($(this).attr("src").toString().indexOf("swfobject.js") > -1) {
					_loadIt = false;
				}
			}
		});
		
		
		if (_loadIt) {
			$.ajax({
				type: "GET",
				url: "http://op.chamberlandhosting.com/js/jquery/plugin/swfobject.js",
				dataType: "script",
				success: function () {
					$(document).ready(function () {
						if (swfobject.hasFlashPlayerVersion("9")) {
							var att = {
								data: "http://op.chamberlandhosting.com/swf/loading.circles.swf",
								width: "55",
								height: "55",
								align: "middle"
							};
							var par = {
								menu: "false",
								wmode: "transparent"
							};
							var id = SPINNER.id() +"-content";
							var myFlashContent = swfobject.createSWF(att, par, id);
							//if (_page) { setTimeout(function() { DIV.page(_page); }, 300); }
							
							$("#"+ SPINNER.id() +"-content").css({"margin-top": (top.$(window).height() * 0.5) +"px"});
						}
					});
				}
			});
		} else {
			
			if (swfobject.hasFlashPlayerVersion("8")) {
				var att = {
					data: "http://op.chamberlandhosting.com/swf/loading.circles.swf",
					width: "55",
					height: "55",
					align: "middle"
				};
				var par = {
					menu: "false",
					wmode: "transparent"
				};
				var idWait = "SpinnerContent";
				var myFlashContent = swfobject.createSWF(att, par, idWait);
				if (_page) { setTimeout(function() { DIV.page(_page); }, 1500); }
			}			
			
		}
    },	
	
	
    hide: function () {
        var id = SPINNER.id();
        $('#' + id).empty().remove();
    }
};




////////// DIV
var DIV = {

	params: {},
	
	id: function () {
		if (!this.params.time) {
			this.params.time = get_time();
			this.params.order = 0;
		}
		this.params.order++;
		
		if (!DIV.params.width) { DIV.params.width = 0; }
		if (!DIV.params.height) { DIV.params.height = 0; }
		if (!DIV.params.top) { DIV.params.top = 0; }
		if (!DIV.params.width) { DIV.params.width = 0; }
		
		this.params.id = "D_" + this.params.time + "_" + this.params.order;
        return this.params.id
    },	
	
	page: function(_src, _title, _class, _w, _h, _top, _left) {
			if (_class === undefined || !_class) { _class = "bgNoise30blk"; }
			if (_title === undefined || !_title) { _title = ""; }
			if (_w) { DIV.params.width = _w; }
			if (_h) { DIV.params.height = _h; }
			if (_top) { DIV.params.top = _top; }
			if (_left) { DIV.params.left = _left; }			
			
			top.DIV.iframe(DIV.id(), _src, _class, _title);
	},
	
	
	iframe: function(_id, _src, _class, _title) {
			if (!_id) { _id = DIV.id(); }
			this.overlay(_id, _class);			
		
			var html = '' +
					'<div align="center" id="O'+ _id +'" class="bg80blk" style="position:absolute; '+
							'top:'+ DIV.params.top +'px; left:'+ DIV.params.left +'px; margin:0px; padding:0px;">' +
						'<div align="center" style="height: 24px;">' +
							'<div align="center" class="popTitle marginL20" style="float: left; padding-top: 3px;">'+ _title +'</div>' +
							'<div align="right" style="float: right;" class="padR5">' +
								'<span id="close-'+ _id +'" onclick="DIV.Close(\''+ _id +'\')" class="ui-icon ui-icon-circle-close marginT5 pointer closeBtn"> </span>' +
							'</div>' +
						'</div>' +
						'<div align="center" id="M'+ _id +'" style="background-color: #FFF; margin: 10px;">' +
							'<iframe width="0" height="0" frameborder="no" scrolling="no" id="IF'+ _id +'" name="IF'+ _id +'" src="'+ _src +'" onload=""></iframe>' +
						'</div>' +
					'</div>';
			//$(document).ready( function() { });
			top.$("#C"+ _id).append( html );
			top.$("div[id^=OD_], div[id^=MD_]").addClass("ui-corner-all");
			$("#close-"+ _id).button();
			
			if (DIV.params.width) { $("#IF"+ _id).attr("width", DIV.params.width) }
			if (DIV.params.height) { $("#IF"+ _id).attr("height", DIV.params.height) }			
	},	
	
	overlay: function(_id, _class) {			
			
			var div = ''+
					'<div id="'+ _id +'" order="'+ this.params.order +'" align="center" '+
					'style="position:absolute; margin:0px; padding:0px; width:100%; height:'+ top.$(document).height() +'px; top:0px; left:0px; text-align: center; z-index: 10000;"'+
					'class="'+ _class +'">'+
						'<table align="center" width="100%" height="" cellpadding="0" cellspacing="0"><tbody>'+
						'<tr>'+
							'<td id="C'+ _id +'" align="center" valign="middle">'+
							'</td>'+
						'</tr>'+				
						'</tbody></table>'+
				'</div>';
			
			top.$("body").append($(div));
			return _id;
	},
	

	
	
	overlay2: function(_id, _class) {
			if (!_class) { _class = ""; }
			
			var div = ''+
					'<div id="'+ _id +'" align="center" '+
					'style="position:absolute; width:100%; height:'+ top.$(document).height() +'px; top:0px; left:0px; z-index: 10000;"'+
					'class="'+ _class +'"></div>';
			top.$("body").append($(div));
			return _id;
	},
	
	iframeShadow: function(_id, _src, _class, _title) {
			
			this.overlay(_id, _class);			
			if (!_title) { _title = ""; }
			
			var html = '' +
					'<table id="O'+ _id +'" style="margin-bottom:15%;" align="center" cellpadding="0" cellspacing="0"><tbody>'+
					'<tr>'+
						'<td width="20" class="TL-80-000"></td>' +
						'<td algin="left" class="TH-80-000">'+
							'<div align="left" style="float:left; position:relative; top:19px; left:5px; width:60%;">'+
								'<span id="popTitle" class="ui-color fs10 font-verdana bold">'+ _title +'</span>'+
							'</div>'+
						'</td>'+
						'<td align="left" valign="top" class="TR-80-000">'+
							'<div style="float:left; position:relative; display:inline-block; top:19px; right:16px; width:16px; height:16px;">'+
								'<span id="popClose" class="ui-icon ui-icon-circle-close pointer"></span>'+
							'</div>'+
						'</td>'+				
					'</tr>'+
					'<tr>'+
						'<td width="20" class="VL-80-000"></td>' +
						'<td  align="center" id="M'+ _id +'" style="background-color:#fff; padding:10px;">'+
							'<iframe id="IF'+ _id +'" name="IF'+ _id +'" width="0" height="0" frameborder="no" scrolling="no"'+
							' src="'+ _src +'" onload="$(window).ready( function() { DIV.resize(\''+ _id +'\'); DIV.resize(\''+ _id +'\'); });"></iframe>' +				
						'</td>'+
						'<td class="VR-80-000"></td>'+				
					'</tr>'+				
					'<tr>'+
						'<td width="20" class="BL-80-000"></td>' +
						'<td class="BH-80-000"></td>'+
						'<td class="BR-80-000"></td>'+				
					'</tr>'+				
					'</tbody></table>';
				
			top.$("#"+ _id +" > table tbody > tr > td").append( html );	
			
			top.$("#popClose").live("click",
				function() {
					top.$("#"+ _id).empty().empty().remove();
				});
						

			
	},
	
	
	
	pageShadow: function(_src, _title, _class) {
			if (_class === undefined) { _class = "bgNoise30blk"; }
			this.iframeShadow(this.id(), _src, _class, _title);
	},
	
	
	
	resize: function (_id, _w, _h) { 
		
		
		if (!_id) { _id = window.name;  }
		if (!_id) { return false; }
		_id = _id.toString().replace("IFD_", "D_");
		
		if (!_h) { _h = 0; }
		if (!_w) { _w = 0; }
		
		var F = top.document.getElementById("IF"+ _id);	
		if (!F) { return false; }
		
			if (!_h) {
				_h = top.$("#IF"+ _id).contents().find('body').attr("offsetHeight");
				if (!_h) {
					_h = top.$("#IF"+ _id).contents().find('body').attr("scrollHeight");
				}
				if (!_h) {
					top.$("#IF"+ _id).contents().find("body > *").each(
					function() {
						_h += nInt($(this).height());
					});						
				}
			}
			
			if (!_w) { 
			
				_w = top.$("#IF"+ _id).contents().find("body > *:first").width();
				if (!_w) { _w = F.contentWindow.document.body.scrollWidth+30; }
			}			
			
			F.height = _h; //FF 3.0.11, Opera 9.63, and Chrome
			F.width = _w; //FF 3.0.11, Opera 9.63, and Chrome
	},
	
	
	centerPopin: function(_id) {
		
			if (!_id) {
				_id = DIV.params.id;
			}
		
			var _w = $("#O"+ _id).width() / 2;
			var _h = $("#IF"+ _id).height();
			var _bh = $(window).height() -100;
			
//			console.log("IF: "+ _h);
//			console.log("DOC: "+ _bh);
			
			_t = Math.floor($(window).height() * 0.5 - _h);
			if (_t < 0) { _t = 20; }
			$("#O"+ _id).css({'top': _t +'px','left': Math.floor($(window).width() * 0.5 - _w) +'px'});
						
			if (_h > _bh) { 
				$("#M"+ _id).css({'height': (_bh - 30) +'px','overflow-y':'scroll'});
			}

	},
	
	Center: function() {
			var _w = top.$("#O"+ DIV.params.id).width() / 2;
			var _h = top.$("#O"+ DIV.params.id).height();
			top.$("#O"+ DIV.params.id).css({'top': Math.floor($(window).height() * 0.5 - _h) +'px','left': Math.floor($(window).width() * 0.5
			 - _w) +'px'});
	},
	
	GetParent: function(_id) {
		var _time = _id.split("_")[1];
		var _order = _id.split("_")[2];
		var _target = _order;
		top.$("div[id*="+ _time +"][order]").each(
			function() {
				var n = $(this).attr("order");
				if (n < _target ) {
					_target = n;	
				}
			});
		//return "IFD_"+ _time +"_"+ _target;
		return top.document.getElementById("IFD_"+ _time +"_"+ _target).contentWindow;
	},
	
	
	Close: function (_id) {
       setTimeout( function() {  top.$('#' + _id.replace("IFD_", "D_")).empty().remove(); }, 200);
    }
	
};






