//##########################################################
//#
//#	Date: 		13 Sept 2006
//#	Author:		David Braiden
//#	Comments:	This code can accept a url and a
//#				comma seperated list of url parameters
//#				It will append all of the specified parameter
//#				from the current page onto the specified url
//#				and redirect to that url.In doing so it will
//#				maintain all of the session variables.
//#
//#	Flash Usage:
//#	on (release) {
//#        getURL ("javascript:DotNetRedirect('**URL GOES IN HERE**','BV_SessionID,BV_EngineID,chanId,site')");
//#	}
//#
//#	General use javascript:DotNetRedirect('**URL GOES IN HERE**','BV_SessionID,BV_EngineID,chanId,site')
//#
//##########################################################

function PageQuery(q) {

	q = q.replace(/\%26/g, "&")

	if(q.length > 1) this.q = q.substring(1, q.length);
	else this.q = null;
	this.keyValuePairs = new Array();
	if(q) {
		for(var i=0; i < this.q.split("&").length; i++) {
			this.keyValuePairs[i] = this.q.split("&")[i];
		}
	}
	this.getKeyValuePairs = function() { return this.keyValuePairs; }
	this.getValue = function(s) {
		for(var j=0; j < this.keyValuePairs.length; j++) {
			if(this.keyValuePairs[j].split("=")[0] == s){
				return this.keyValuePairs[j].split("=")[1];
			}
		}
		return false;
	}
	this.getParameters = function() {
		var a = new Array(this.getLength());
			for(var j=0; j < this.keyValuePairs.length; j++) {
				a[j] = this.keyValuePairs[j].split("=")[0];
			}
		return a;
	}
	this.getLength = function() { return this.keyValuePairs.length; }
}

function queryString(key){
	var page = new PageQuery(window.location.search);
	return unescape(page.getValue(key));
}

function getItem(key){
	return(queryString(key));
}

function Build_Url(url,Fields){
	var url_string_param = "";
	var myFields = Fields.split(",");

	for (i=0;i<myFields.length;i++)
	{
		
		var fieldname = myFields[i];
		var fieldvalue = getItem(myFields[i]);
		if(fieldname == "BV_SessionID"){
			
			if(fieldvalue == "false" || fieldvalue == null){
				fieldvalue = document.searchForm.BV_SessionID.value;	
			}
		}
		if(fieldname == "BV_EngineID"){
			if(fieldvalue == "false" || fieldvalue == null){
				fieldvalue = document.searchForm.BV_EngineID.value;
			}
		}
		url_string_param += "&"+myFields[i]+"=" + fieldvalue;
	}
	
	var new_url = url + url_string_param;
	new_url += "&logged_in=true";
	return(new_url);
}

function DotNetRedirect(URL,Fields) {
	var New_URL = Build_Url(URL,Fields);
	window.location =New_URL;
}
function DNR(URL,Fields) {
	var New_URL = Build_Url(URL,Fields);
	window.location =New_URL;
}

function DotNetRedirectAnchor(URL,Fields) {
//##########################################################
//#
//#	Date: 		14 Sept 2006
//#	Author:		David Braiden
//#	Comments:	This code can accept a url with an anchor and a
//#			comma seperated list of url parameters
//#			It will append all of the specified parameter
//#			from the current page onto the specified url
//#			and move the anchor to the end of the URL.
//#			It will then redirect to that url.In doing so it will
//#			maintain all of the session variables.
//#
//#	Flash Usage:
//#	on (release) {
//#        getURL ("javascript:DotNetRedirectAnchor('**URL GOES IN HERE**','BV_SessionID,BV_EngineID,chanId,site')");
//#	}
//#
//#	General use javascript:DotNetRedirectAnchor('**URL GOES IN HERE**','BV_SessionID,BV_EngineID,chanId,site')
//#
//##########################################################
	var temp = new Array();
	temp = URL.split('#');
	URL = temp[0];
	var ANCHOR = temp[1];
	var New_URL = Build_Url(URL,Fields);
	New_URL + "#" + ANCHOR;
	var New_URL_With_Anchor = New_URL + "#" + ANCHOR;
	window.location =New_URL_With_Anchor;
}