/* ------------------------------------------------------------------------------------------------------------------------------------------------
Description: Sets the current document location. Attributes can be added to open the given document in a blank window, or to specify window 
	attributes other than the default.
Written by: B. Kevin Bell
Written on: 5/6/03
Examples:
	javascript:setDocument('swing/calendar.htm')
	javascript:setDocument('swing/calendar.htm', 'blank')
	javascript:setDocument('swing/calendar.htm', 'blank', 'height=450,width=600')
------------------------------------------------------------------------------------------------------------------------------------------------ */

function setDocument(documentString, target, windowAttributes) {
	windowAttributes = (windowAttributes != "") ? (windowAttributes) : ("height=450,width=600,status=no,toolbar=no,menubar=no,location=no,resizable=yes,scrollbars=yes");
	
	if ((target == "blank") || (target == "_blank")) {
		window.open(documentString, null, windowAttributes);
	}
	else if (target != null) {
		try {
			var ref = eval(target + ".document");
			
			ref.location = documentString;
		}
		catch(e) {
			alert("Error in JavaScript function setDocument!");
		}
	}
	else {
		document.location = documentString;
	}
}

/* ------------------------------------------------------------------------------------------------------------------------------------------------
Written by: B. Kevin Bell
Written on: 8/13/03
Examples:
	<a href="javascript:setEmail('bell', 'fxpal.com')">email me</a>
------------------------------------------------------------------------------------------------------------------------------------------------ */
function setEmail(name, domain) {
	document.location = "ma" + "il" + "to" + ":" + name + "@" + domain;
}

/* ------------------------------------------------------------------------------------------------------------------------------------------------
Written by: B. Kevin Bell
Written on: 8/13/03
Examples:
	<a href="javascript:setEmail('bell', 'fxpal.com')">email me</a>
------------------------------------------------------------------------------------------------------------------------------------------------ */
function sendMail(domain, name) {
	setEmail(name, domain);
}

/* ------------------------------------------------------------------------------------------------------------------------------------------------
Written by: B. Kevin Bell
Written on: 9/10/03
Examples:
	<a href="javascript:setEmail('bell', 'fxpal.com')">email me</a>
------------------------------------------------------------------------------------------------------------------------------------------------ */
function showMail(domain, name) {
	window.status = "ma" + "il" + "to" + ":" + name + "@" + domain;
}

/* ------------------------------------------------------------------------------------------------------------------------------------------------
Written by: B. Kevin Bell
Written on: 5/6/03
------------------------------------------------------------------------------------------------------------------------------------------------ */
function submitForm(formRef, action) {
	formRef.action = formRef.action + action;
	formRef.submit();
}

/* ------------------------------------------------------------------------------------------------------------------------------------------------
Written by: B. Kevin Bell
Written on: 5/7/03
------------------------------------------------------------------------------------------------------------------------------------------------ */
function movePhoto(id) {
	var ref = document.all[id].parentElement.style;
	
	ref.left = window.event.x + 10;
	ref.top = window.event.y + 10;
}

/* ------------------------------------------------------------------------------------------------------------------------------------------------
Written by: B. Kevin Bell
Written on: 5/7/03
------------------------------------------------------------------------------------------------------------------------------------------------ */
function showPhoto(id) {
	var ref = document.all[id].parentElement.style;
	
	ref.left = window.event.x + 10;
	ref.top = window.event.y + 10;
	ref.display = "block";
}

/* ------------------------------------------------------------------------------------------------------------------------------------------------
Written by: B. Kevin Bell
Written on: 5/7/03
------------------------------------------------------------------------------------------------------------------------------------------------ */
function hidePhoto(id) {
	var ref = document.all[id].parentElement.style;
	
	ref.left = window.event.x + 10;
	ref.top = window.event.y + 10;
	ref.display = "none";
}

/* ------------------------------------------------------------------------------------------------------------------------------------------------
Description: Sets an HTML SELECT box of a given name to the given value. The name and value are supplied in a specific format as shown below.
Written by: B. Kevin Bell
Written on: 5/27/03
Examples:
	setSelectTo("SelectName=>sortBy", "SelectText=>username"); // where 'SelectName' is the value of the 'name' attribute in the HTML SELECT box.
	setSelectTo("SelectName=>sortBy", "SelectText=>" + getParam("column"));
------------------------------------------------------------------------------------------------------------------------------------------------ */
function setSelectTo() {
	function trim(aString) {
		aString = aString.replace(/^\s+/,'');
		aString = aString.replace(/\s+$/,'');
		return(aString);
	}
	
	function getArgs(anArray) {
		var tempArray = new Array();
		var nameValueArray = new Array();
	
		for (var i = 0; i < anArray.length; i++) {
			tempArray = anArray[i].split("=>");
			nameValueArray[trim(tempArray[0])] = trim(tempArray[1]);
		}
	
		return(nameValueArray);
	}

	var paramArray = getArgs(arguments);
	var obj = eval(paramArray["SelectName"]);

	for (var i = 0; i < obj.options.length; i++) {
		if (obj.options[i].value == paramArray["SelectText"]) {
			obj.selectedIndex = i;
			break;
		}
	}
}

/*--------------------------------------------------------------------------------------------------------------------
Description: Takes a key and returns the value from the query string.
Written by: B. Kevin Bell
Written on: 03/23/01
Examples:
	Given:
		http://localhost:8080/PlasmaPoster/servlet/TransformServlet?action=list&xsl=account.xsl&column=userid&order=ascending
		
		getParam("column"); // returns 'userid'
--------------------------------------------------------------------------------------------------------------------*/
function getParam(key) {
	var nameValueArray = window.location.search.substr(1).split("&");
	var tempArray;
	
	for (var i = 0; i < nameValueArray.length; i++) {
		tempArray = nameValueArray[i].split("=");
		if (tempArray[0] == key) return(tempArray[1]);
	}
	
	return("");
}

/*--------------------------------------------------------------------------------------------------------------------
Description: Returns true if the String parameter is in the form of a valid email address, otherwise, returns false
Written By: B. Kevin Bell, based on code from Yehuda Shiran
Written On: 06/14/01
--------------------------------------------------------------------------------------------------------------------*/
function isEmailAddress(aString) {
	var re1 = /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)|([:;,\/]+)/;
	var re2 = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;

	return(!re1.test(aString) && re2.test(aString));
}

/*--------------------------------------------------------------------------------------------------------------------
Description: Sets a cookie from the client side
Written By: ?
Written On: ?
Usage:
	name - name of the cookie
	value - value of the cookie
	[expires] - expiration date of the cookie (defaults to end of current session)
	[path] - path for which the cookie is valid (defaults to path of calling document)
	[domain] - domain for which the cookie is valid (defaults to domain of calling document)
	[secure] - Boolean value indicating if the cookie transmission requires a secure transmission
	* an argument defaults when it is assigned null as a placeholder
	* a null placeholder is not required for trailing omitted arguments
Examples:
	setCookie("refresh", "true");
	document.writeln(getCookie("refresh"));
	setCookie("refresh", "false");
	document.writeln(getCookie("refresh"));
--------------------------------------------------------------------------------------------------------------------*/
function setCookie(name, value, expires, path, domain, secure) {
	var curCookie = name + "=" + escape(value) + ((expires) ? "; expires=" + expires.toGMTString() : "") + ((path) ? "; path=" + path : "") + ((domain) ? "; domain=" + domain : "") + ((secure) ? "; secure" : "");
	document.cookie = curCookie;
}

/*--------------------------------------------------------------------------------------------------------------------
Description: Gets a cookie from the client side
Written By: ?
Written On: ?
Usage:
	name - name of the desired cookie
	* return string containing value of specified cookie or null if cookie does not exist
--------------------------------------------------------------------------------------------------------------------*/
function getCookie(name) {
	var dc = document.cookie;
	var prefix = name + "=";
	var begin = dc.indexOf("; " + prefix);
	
	if (begin == -1) {
		begin = dc.indexOf(prefix);
		if (begin != 0) return null;
	} 
	else {
		begin += 2;
	}
	
	var end = document.cookie.indexOf(";", begin);
	if (end == -1) end = dc.length;
	return unescape(dc.substring(begin + prefix.length, end));
}

/*--------------------------------------------------------------------------------------------------------------------
Description: Deletes a cookie from the client side
Written By: ?
Written On: ?
Usage:
	name - name of the cookie
	[path] - path of the cookie (must be same as path used to create cookie)
	[domain] - domain of the cookie (must be same as domain used to create cookie)
	* path and domain default if assigned null or omitted if no explicit argument proceeds
--------------------------------------------------------------------------------------------------------------------*/
function deleteCookie(name, path, domain) {
	if (getCookie(name)) {
		document.cookie = name + "=" + ((path) ? "; path=" + path : "") + ((domain) ? "; domain=" + domain : "") + "; expires=Thu, 01-Jan-70 00:00:01 GMT";
	}
}

/*--------------------------------------------------------------------------------------------------------------------
Description: Sidebar expand/collapse sub-categories
--------------------------------------------------------------------------------------------------------------------*/

function poptoggle(postid) {
	var whichpost = document.getElementById(postid);
	if (whichpost.className=="expandblock") {
		whichpost.className="collapseblock";
	}
	else {
	whichpost.className="expandblock";
	}
}

/*
Add to favorie or book mark the link or url of the page
We store URL of sites by using my favorite or book mark feature. The URL of the site will be added to favorite or bookmark links. On clicking the link browser will open the window for conformation and adding the link to the list. 
*/

function bookmark()
{
	title = "FXPAL Home"; 
	url = "http://fxpal.com";
	if (window.sidebar)  // Mozilla Firefox Bookmark
	    window.sidebar.addPanel(title, url,"");
	else if( window.external )  // IE Favorite
  	    window.external.AddFavorite( location.href, document.title); 
	 else if(window.opera && window.print) // Opera Hotlist
	    return true;  
 
}

/* detect browser*/

function GetBrowser()
{
   var agt=navigator.userAgent.toLowerCase();
   if( ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1)) )
       return "IE";
   else if( ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1)
         && (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1)
         && (agt.indexOf('webtv')==-1) && (agt.indexOf('hotjava')==-1)) )
       return "Netscape";
   else
       return "unknown";
}


/*--------------------------------------------------------------------------------------------------------------------
Description: Change flag 
--------------------------------------------------------------------------------------------------------------------*/
/*
function changePicPlus(el, pic1, alt1, pic2, alt2) {
	if ((el.src).match("images/"+pic1+".gif")!=null) {
		el.src="images/"+pic2+".jpg";
		el.alt=alt2;
		el.title=alt2;
//		Session("language") = "english";
		setCookie("language", "english");		

	}
	else {
		el.src="images/"+pic1+".gif";
		el.alt=alt1;
		el.title=alt1;
//		Session("language") = "japan";
		setCookie("language", "japan");


	}
}

window.onload=function() {
	var pic=document.getElementById('lan');
	pic.onclick=function(){
		changePicPlus(this,'flag_jp','japan','flag','english');
	}
}

*/