
function PreloadImages(length, path, type)  {
    for(var i = 0; i<=length; i++) {
	this[i]= new Image()
	this[i].src= path + i + type
    }
    return this;
}
//overImgNew = new PreloadImages(11,'/policeone/data/images/NewMenu/mbnew_','.gif');
//normImgNew = new PreloadImages(11,'/policeone/data/images/NewMenu/manew_','.gif');

	//overImg = new PreloadImages(11,'/policeone/data/images/mb_','.gif');
	//normImg = new PreloadImages(11,'/policeone/data/images/ma_','.gif');

function rollOnNew(num) {
    if(document.images) { 
	eval('document.images["norm'+num+'"].src='+'overImgNew[num].src');
    }
}

function rolloffNew(num) {
    if(document.images){
	eval('document.images["norm'+num+'"].src='+'normImgNew[num].src');
    }
}
/************************************************/

function testOS() 
{
  var OS = "";
  if ((navigator.userAgent.indexOf ('Win') != -1) &&
     (navigator.userAgent.indexOf('NT 5.1') != -1))
  {  OS = "Windows XP"; }
  else if ((navigator.userAgent.indexOf ('Win') != -1) &&
     (navigator.userAgent.indexOf('98') != -1))
  {  OS = "Windows 98"; }
  else if((navigator.userAgent.indexOf('Win') != -1) &&
    (navigator.userAgent.indexOf('95') != -1))
    { OS = "Windows 95"; }
  else if(navigator.appVersion.indexOf("16") !=-1)
   { OS = "Windows 3.1"; }
  else if (navigator.appVersion.indexOf ("NT") !=-1)
   { OS= "Windows NT"; } 
  else if (navigator.appVersion.indexOf ("Linux") !=-1)
   { OS = "Linux"; } 
  else if (navigator.userAgent.indexOf ('Mac') != -1)
   { OS = "Macintosh"; }
  else { OS = "other"; }
  return OS ;
}

function testCookiesSupport()
{	
		if (navigator.cookieEnabled)
			return "Yes"
		else  
			return "No"; 
}

function testResolution()
{ 
   return screen.width + "x" + screen.height + ", " + screen.colorDepth + "bit";
}

function testJavaSupport()
{ 
   return (navigator.javaEnabled() ?  "Yes" : "No")
}

function SysInfo(os, cookiessupport, resolution, jssupport)
{
try {
		 os.value = "Operating system:  " + testOS();
		 cookiessupport.value = "Cookies support:  " + testCookiesSupport();
		 resolution.value = "Definition:  " + testResolution();
		 jssupport.value = "Javascript support:  Yes, version " + jsver;
} catch(ex) { }
}

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; }
    return true;
}

function sizeImgWH(obj, _w, _h) {
    var tmpImg = new Image();
    tmpImg.src = obj.src;
    if (tmpImg.height > _h) { obj.height = _h; }
    if (tmpImg.width > _w) { obj.width = _w; }

}
function sizeImgPower (im, w) {
	if (im.width > w) { im.style.width = w; }
	if (im.style.width > w) { im.style.width = w; }
	sizeImg(im, w)
	return true;
}
function sizeImgWHpropor(obj, _w, _h) {
    var tmpImg = new Image();
    tmpImg.src = obj.src;
	var differenceH = 0;
	var differenceW = 0;
    if (tmpImg.height > _h) { 
		differenceH = obj.height - _h;
	}
    if (tmpImg.width > _w) { 
		differenceW = tmpImg.width - _w;
	}
	if (differenceH >= differenceW && differenceH != 0){
		obj.width = Math.round(_h * obj.width / obj.height);
		obj.height = _h;
	} else if (differenceW != 0){
		obj.height = Math.round(_w * obj.height / obj.width);
		obj.width = _w;
	}
}
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 = 410;
    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 httpRequest(url, encoding, toReceive) {
	/*var toResolve		= 10000;
	var toConnect		= 10000;
	var toSend			= 40000;

	var request;
	var WinHttpReq = null;

	var request = "";
	try {
	
		if(!WinHttpReq) try {
			WinHttpReq = new ActiveXObject("MSXML2.XMLHTTP.3.0");	
		} catch (e){}		

		if(!WinHttpReq) try {
			WinHttpReq=new ActiveXObject('Msxml2.XMLHTTP');
		} catch (e){}

		if(!WinHttpReq) try {
			WinHttpReq=new ActiveXObject('Microsoft.XMLHTTP');
		} catch (e){}

		if(!WinHttpReq) try {
			WinHttpReq=new XMLHttpRequest();
		} catch (e){}		
		
		WinHttpReq.open("GET", url, false);
		WinHttpReq.send();
		return WinHttpReq.responseText;

		
		if(WinHttpReq.StatusText == "OK") {
			request = BinaryToString1(WinHttpReq.ResponseBody, encoding);
		} else { request = "1- " + WinHttpReq.StatusText; }
	} catch(e) { request = "2- " + "WinHttpRequest has caused an error"; }
	return request;*/
	
	return httpRequestPost(url, encoding, toReceive,"");
}

function httpRequestPost(url, encoding, toReceive, params) {
	var toResolve		= 10000;
	var toConnect		= 10000;
	var toSend			= 40000;

	var request;
	var WinHttpReq = null;

	var request = "";
	try {
	
		if(!WinHttpReq) try {
			WinHttpReq = new ActiveXObject("MSXML2.XMLHTTP.3.0");	
		} catch (e){}		

		if(!WinHttpReq) try {
			WinHttpReq=new ActiveXObject('Msxml2.XMLHTTP');
		} catch (e){}

		if(!WinHttpReq) try {
			WinHttpReq=new ActiveXObject('Microsoft.XMLHTTP');
		} catch (e){}

		if(!WinHttpReq) try {
			WinHttpReq=new XMLHttpRequest();
		} catch (e){}	
	
	WinHttpReq.open("POST", url, false);
	WinHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	WinHttpReq.setRequestHeader('HTTP_COOKIE', document.cookie);
	
	WinHttpReq.send(params);
	return WinHttpReq.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 _getCookie( name ) {
	var start = document.cookie.indexOf( name + '=' );
	var len = start + name.length + 1;
	if ( ( !start ) && ( name != document.cookie.
substring( 0, name.length ) ) ) {
		return null;
	}
	if ( start == -1 ) return null;
	var end = document.cookie.indexOf( ';', len );
	if ( end == -1 ) end = document.cookie.length;
	return unescape( document.cookie.substring( len, end ) );
}
	
function _setCookie( name, value, expires, path, domain, secure ) {
	var today = new Date();
	today.setTime( today.getTime() );
	if ( expires ) {
		expires = expires * 1000 * 60 * 60 * 24;
	}
	var expires_date = new Date( today.getTime() + (expires) );
	document.cookie = name+'='+escape( value ) +
		( ( expires ) ? ';expires='
+expires_date.toGMTString() : '' ) +
//expires.toGMTString()
		( ( path ) ? ';path=' + path : '' ) +
		( ( domain ) ? ';domain=' + domain : '' ) +
		( ( secure ) ? ';secure' : '' );
}
	
function _deleteCookie( name, path, domain ) {
	if ( getCookie( name ) ) document.cookie = name + '=' +
			( ( path ) ? ';path=' + path : '') +
			( ( domain ) ? ';domain=' + domain : '' ) +
			';expires=Thu, 01-Jan-1970 00:00:01 GMT';
}

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 tipCheckForm() {
  with(document.tipSubmitForm) {
    if(!Title.value.length) { alert('Please enter Tip Title'); Title.focus(); return false; }
    if(!Body.value.length) { alert('Please enter your Tip'); Body.focus(); return false; }
    if(!(MemberName.value > ' ')) { alert('Please enter your Name'); MemberName.focus(); return false; }
    if(!Department.value.length) { alert('Please enter your Department'); Department.focus(); return false; }
    if(!DepartmentState.value.length) { alert('Please enter Department State'); DepartmentState.focus(); return false; }
    if(!checkMail(MemberEmail.value)) { alert('Please enter Email Address'); MemberEmail.focus(); return false; }
    return true;						
  }
}

function addEvent(el, eType, fn, uC) {
	if (el.addEventListener) {
		el.addEventListener(eType, fn, uC);
		return true;
	} else if (el.attachEvent) {
		return el.attachEvent('on' + eType, fn);
	} else {
		el['on' + eType] = fn;
	}
} 
function processGoogleSearch(){
	var keyword = document.forms["cse-search-box"]["q"].value  ; 
	keyword = keyword.replace(/[:]/ig, "" ).toLowerCase() ;
	var found  = document.getElementById('cse-search-results').offsetHeight > 260 ;
	p.prop7 = (found ? "" : "null:")  + keyword ; 
	for ( var prop in p ){ s[prop] = p[prop]; }
	var s_code=s.t();if(s_code)document.write(s_code);
}

	function ShowInformation(view, w, h) {
		l = parseInt((screen.width - w) / 2);
		t = parseInt((screen.height - h) / 2);
		var page = 'http://origin.policeone.com/test/popupfoto.asp?action=foto&view=' + view + '&w=' + w + '&h=' + h;
		window.open(page, "", "width=260, height=200,left=" + l + ",top=" + t + ",location=0,resizable=1,menubar=0,status=0,toolbar=0,scrollbars=0");
	}
