function PreloadImages(length, path, type)  {
    for(var i = 0; i<=length; i++) {
	this[i]= new Image()
	this[i].src= path + i + type
    }
    return this;
}

	//overImg = new PreloadImages(10,'/policeone/data/images/mb_','.gif');
	//normImg = new PreloadImages(10,'/policeone/data/images/ma_','.gif');

function rollOn(num) {
    if(document.images) { 
	eval('document.images["norm'+num+'"].src='+'overImg[num].src');
    }
}

function rolloff(num) {
    if(document.images){
	eval('document.images["norm'+num+'"].src='+'normImg[num].src');
    }
}

function mOvr(src,clrOver) {
    if (!src.contains(event.fromElement)) {
	src.style.cursor = 'hand'; src.bgColor = clrOver;
    }
}

function mOut(src,clrIn) {
    if (!src.contains(event.toElement)) {
	src.style.cursor = 'default'; src.bgColor = clrIn;
    }
}

function sizeImg(obj, _width) {
    var tmpImg = new Image();
    tmpImg.src = obj.src;
    if (tmpImg.width > _width) { obj.width = _width; }
}
function sizeImgWH(obj, _width, _height) {
    var tmpImg = new Image();
    tmpImg.src = obj.src;
    if (tmpImg.width > _width) { obj.width = _width; }
    if (tmpImg.height > _height) { obj.height = _height; }
}
function SIP(obj, _w, _h) {
  /////////////// this is the correct function is proportional to change size
  var tmpImg = new Image();
  tmpImg.src = obj.src;
  //alert(tmpImg.width)
  if (_w/tmpImg.width > _h/tmpImg.height) {
  	if (tmpImg.width > _w) {
      obj.height = tmpImg.height*(_w/tmpImg.width);
      obj.width = _w;
    }
    if (tmpImg.height > _h) {
		  obj.width = tmpImg.width*(_h/tmpImg.height);
		  obj.height = _h;
    }
	} else {
    if (tmpImg.height > _h) {
		  obj.width = tmpImg.width*(_h/tmpImg.height);
		  obj.height = _h;
    }
  	if (tmpImg.width > _w) {
      obj.height = tmpImg.height*(_w/tmpImg.width);
      obj.width = _w;
    }
  }
}

function PrinterFriendly(url) {

	remote = window.open("","_self");
    remote.location.href=url;
    if (remote.opener == null) remote.opener = window;
}



function PrinterFriendly760(url) {
    var width = 760,
        height = 400;
    remote = window.open("", "opener", "menubar=0,scrollbars=0,resizable=0,toolbar=0,left=" + ((screen.availWidth  - width) / 2) + ",top=" + ((screen.availHeight  - height) / 2) + ",Width=" + width + ",height=" + height);
    remote.location.href=url;
    if (remote.opener == null) remote.opener = window;
}


function showText(obj) {
    obj.onmouseout = function() { window.status = ""; }
    window.status = obj.innerText;
}

function checkMail(mail) {
	var myRegExp = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	return myRegExp.test(mail);
}

// from Root Header
function GoProd(s) {
    var d = s.options[s.selectedIndex].value;
    window.top.location.href = d;
    s.selectedIndex = 0;
}

function redirect(target_url) {
    document.location = target_url;
}

// Form checking utilities

function checkEmail(mail) {
	var myRegExp = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	return myRegExp.test(mail);
}

function Wrong(obj, message) {
	alert(message);
	obj.focus();
	return false;
}

function getCookie(name) {

	var regExp 	= new RegExp(name + "=([^;]*)","gi");
	var ck 		= regExp.exec(String(document.cookie));	
	ck 			= RegExp.$1;

	return ck;
}


function httpRequestCreate() {
	var httpRequest = false;
	if ( window.XMLHttpRequest ) 
	{ // Mozilla, Safari
		httpRequest = new XMLHttpRequest();
		if ( httpRequest.overrideMimeType ) {
			httpRequest.overrideMimeType('text/xml');
		}
	} else if ( window.ActiveXObject ) 
	{ // IE
		try {
			httpRequest = new ActiveXObject("MSXML2.XMLHTTP.3.0");
		} catch (e) {
			try {
				httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
				} catch (e) { /*document.write(e);*/ }
		}
	}
	return httpRequest;
}
function httpRequest(url, encoding, toReceive) {
	return httpRequestPost(url, encoding, toReceive,"");
}
function httpRequestPost(url, encoding, toReceive, params) {
	var toResolve		= 10000;
	var toConnect		= 10000;
	var toSend			= 40000;
	var request;
	var WinHttpReq;
	var request = "";
	try {
		var xmlHttpReq = httpRequestCreate(); //new ActiveXObject("MSXML2.XMLHTTP.3.0");
		xmlHttpReq.open("POST", url, false);
		xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		xmlHttpReq.setRequestHeader('HTTP_COOKIE', document.cookie);
		xmlHttpReq.send(params);
		return xmlHttpReq.responseText;
		if(WinHttpReq.StatusText == "OK") {
			request = BinaryToString1(WinHttpReq.ResponseBody, encoding);
		} else { request = "<div style=\"display: none;\">2-1 " + WinHttpReq.StatusText+"</div>"; }
	} catch(e) { request = "<div style=\"display: none;\">2-2 " + "WinHttpRequest has caused an error </div>"; }
	return request;
}


function setSiteHomePage( anchor, divId, linkId ){
	var url = window.location.href;
if (document.all){
	anchor.style.behavior='url(#default#homepage)';
	anchor.setHomePage(url);
} else {
	divPopup = document.getElementById(divId);
	divPopup.style.display = "block";
	hpLink = document.getElementById(linkId);
	hpLink.href=url;
}
return true;
}
function closePopup(divId){
	document.getElementById(divId).style.display = "none";
}

function signPanelFormSubmit( form ){
	form.backurl.value = window.location.href;
	return true;
}
function addLoadEvent(func) {
        var oldonload = window.onload;
        if (typeof window.onload != 'function') {
                window.onload = func;
        }
        else {
                window.onload = function() {
                        oldonload();
                        func();
                }
        }
}

 function autoIframe(frameId){
        try{
                frame = document.getElementById(frameId);
                innerDoc = (frame.contentDocument) ? frame.contentDocument : frame.contentWindow.document;
                objToResize = (frame.style) ? frame.style : frame;
                objToResize.height = innerDoc.body.scrollHeight + 10;
        }
        catch(err){
                //window.status = err.message;
                alert(err.message);
        }
} 
