var HTTP_Ref = "http"
var HTTP_SSL_Ref = "https"

var remote;
remote = null;

function returnToOpener( pg, secure )
{
	var newUrl;
	var url = document.URL;

	var lastSlash = url.lastIndexOf("/");
	var colon = url.indexOf(":");
	//var body = url.substr(colon, lastSlash - colon + 1);
	var body = url.substr(colon, lastSlash - colon );
	
	var urlLine;
	
	if (secure) {
		newUrl = HTTP_SSL_Ref   // SSL Secure (https)
	} else {
		newUrl = HTTP_Ref	 	// Non-Secure (http)
	};
	
	if (pg.substr(0,2) == ".." ) {
		pg = pg.substr(3,pg.length);
		lastSlash = body.lastIndexOf("/");
		body = body.substr(0,lastSlash + 1);
	}
	
	urlLine = newUrl + body + pg
	
	//window.open(urlLine,"_parent")
	opener.location.href = urlLine;
  	window.close();

}


function goToPage( pg, secure )
{
	var newUrl;
	var url = document.URL;

	var lastSlash = url.lastIndexOf("/");
	var colon = url.indexOf(":");
	//var body = url.substr(colon, lastSlash - colon + 1);
	var body = url.substr(colon, lastSlash - colon );
	
	var urlLine;
	
	if (secure) {
		newUrl = HTTP_SSL_Ref   // SSL Secure (https)
	} else {
		newUrl = HTTP_Ref	 	// Non-Secure (http)
	};
	
	if (pg.substr(0,2) == ".." ) {
		pg = pg.substr(3,pg.length);
		lastSlash = body.lastIndexOf("/");
		body = body.substr(0,lastSlash + 1);
	}
	
	urlLine = newUrl + body + pg
	
	window.open(urlLine,"_parent")

}

function goToSelectPage( pg, secure, checkNotEmpty, buttonText )
{
	var newUrl;
	var url = document.URL;

	var lastSlash = url.lastIndexOf("/");
	var colon = url.indexOf(":");
	//var body = url.substr(colon, lastSlash - colon + 1);
	var body = url.substr(colon, lastSlash - colon );
	
	var urlLine;
	
	if (secure) {
		newUrl = HTTP_SSL_Ref   // SSL Secure (https)
	} else {
		newUrl = HTTP_Ref		// Non-Secure (http)
	};
		
	if (pg.substr(0,2) == ".." ) {
		pg = pg.substr(3,pg.length);
		lastSlash = body.lastIndexOf("/");
		body = body.substr(0,lastSlash + 1);
	}
	
	urlLine = newUrl + body + pg
	
	if (checkNotEmpty.length != 0) {
		window.open(urlLine,"_parent");
	} else {
		alert("Please select a value before clicking '" + buttonText + "'.");
	};

}

function goToForm( form, pg, secure )
{
	var newUrl;
	var url = document.URL;

	var lastSlash = url.lastIndexOf("/");
	var colon = url.indexOf(":");
	//var body = url.substr(colon, lastSlash - colon + 1);
	var body = url.substr(colon, lastSlash - colon );
	
	var urlLine;
	
	if (secure) {
		newUrl = HTTP_SSL_Ref   // SSL Secure (https)
	} else {
		newUrl = HTTP_Ref		// Non-Secure
	};
		
	if (pg.substr(0,2) == ".." ) {
		pg = pg.substr(3,pg.length);
		lastSlash = body.lastIndexOf("/");
		body = body.substr(0,lastSlash + 1);
	}
	
	urlLine = newUrl + body + pg
	
	form.action = urlLine
	form.submit();

}

function popUp(pageName) {
	
	if (remote == null) {
		remote = window.open (pageName,'remoteWin', 'toolbar=no,width=515,height=330,left=150,top=200, screenX=500,screenY=200,status=no,scrollbars=no,resizable=no');
	}
	
	if (remote.opener == null) remote.opener = window;
	remote = null;
}

function genericPopUp(pageName,w,h,l,t,x,y) {
	
	if (remote == null) {
		var text = "toolbar=no,width=" + w + ",height=" + h + ",left=" + l + ",top=" + t + ", screenX=" + x + ",screenY=" + y + ",status=no,scrollbars=no,resizable=no";
		remote = window.open (pageName,'remoteWin', text);
	}
	
	if (remote.opener == null) remote.opener = window;
	remote = null;
}

function ws() {
	
	window.status=' ';
	return true;
}

function validateLength(oSrc, args){
   args.IsValid = (args.Value.length >= 8);
}

function downloadDocument( documentName, stateAbbrev, buttonText )
{
	var newUrl;
	var url = document.URL;
	var pg;

	var lastSlash = url.lastIndexOf("/");
	var colon = url.indexOf(":");
	var body = url.substr(colon, lastSlash - colon );
	
	var urlLine;
	
	newUrl = "http"
	
	pg = "../Requests/DownloadDocument.aspx?DocName=" + documentName + "&State=" + stateAbbrev
	if (pg.substr(0,2) == ".." ) {
		pg = pg.substr(3,pg.length);
		lastSlash = body.lastIndexOf("/");
		body = body.substr(0,lastSlash + 1);
	}
	
	urlLine = newUrl + body + pg;
	
	//alert(urlLine);
	
	
	
	if (stateAbbrev.length != 0) {
		window.open(urlLine, "_self");
		//window.open(urlLine, "_parent");
		//window.open(urlLine, "DocumentDownload");
		//window.open(urlLine);
	} else {
		alert("Please select a value before clicking '" + buttonText + "'.");
	};

}

function loadPage(anchor)
{
	window.location.hash = anchor;
	return;
}

//************** Open Center Window Function
 function openCenteredWindow(url, height, width, name, parms) {
     if (height <= 1) { height = Math.floor(screen.height * height); }
     if (width <= 1) { width = Math.floor(screen.width * width); }
  var left = Math.floor( (screen.width - width) / 2);
     var top = Math.floor( (screen.height - height) / 2);
     var winParms = "top=" + top + ",left=" + left + ",height=" + height + ",width=" + width;
     if (parms) { winParms += "," + parms; }
     var win = window.open(url, name, winParms);
     if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
     return win;
 }
//************** End Open Center Window Function
