imgout = new Image(16,13);
imgin = new Image(16,13);
imgout.src = "/images/icons/folder_close.gif";
imgin.src  = "/images/icons/folder_open.gif";

function filter(imagename,objectsrc){
	if (document.images){
		document.images[imagename].src=eval(objectsrc+".src");
 	}
}

function fadein(divid){
	//if (document.getElementById(divid).style.display = 'none'){	
		Effect.Appear(divid);
		fadeout(divid);
	//}
	//Effect.Fade('menu6');
	
}

function showhide(divtoshow,divtohide) {
 	document.getElementById(divtoshow).style.display = "block"
 	document.getElementById(divtohide).style.display = "none"
}

function expand(handle,id) {
 if (document.getElementById(handle+id).style.display == "none"){
 	filter(('img' + handle + id),'imgin');
 	document.getElementById(handle+id).style.display = "block"
	
 } else {
 	filter(('img' + handle + id),'imgout');
	document.getElementById(handle+id).style.display = "none"
 }
}

function fadeout(divid){
	var x=document.getElementsByTagName("div");
	for (var i=0;i<x.length;i++)
  	{
	if (x[i].id.indexOf("menu")>-1){	
			
			if (x[i].id != divid){
			
			document.getElementById(x[i].id).style.display = 'none';	
			//Effect.Fade(x[i].id);	
			}
		}
	}
	
}

//VALIDATION
function validEmail(email) {
			var re = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
			return re.test(email); 
		}
		
//VALIDATION
function trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}
		
//VALIDATION
function ltrim(stringToTrim) {
	return stringToTrim.replace(/^\s+/,"");
}
		
//VALIDATION
function rtrim(stringToTrim) {
	return stringToTrim.replace(/\s+$/,"");
}
		
//VALIDATION
function isFilled(elm) {
	//alert(elm.type);
	//Last Updated by Sol - 6/14/07
	switch(elm.type){
	case "text":
		if (trim(elm.value) == "" || elm.value == null){
		return false;}
		else {return true;}
		break;
	case "password":
		if (trim(elm.value) == "" || elm.value == null){
		return false;}
		else {return true;}
		break;
	case "textarea":
		if (trim(elm.value) == "" || elm.value == null){
		return false;}
		else {return true;}
		break;
	case "select-one":
		var myindex=elm.selectedIndex;
		if (myindex==0){
		return false;}
		else {return true;}
		break;
	}
}

//VALIDATION
function validateform(formname,color1,color2){
	//last updated on 9/27/07
	//index of is mo betta
	var x = document.forms[formname];
	var allgood = true;
	for (var i=0;i<x.length;i++){
		if (x.elements[i].className.indexOf('required')>-1) {
		 	var thisformname = x.elements[i].name;
			var thisformid = x.elements[i].id;
			if (!isFilled(x.elements[i])) {
				document.getElementById(thisformid).style.background = color1;
				allgood = false;
				} else {
				  document.getElementById(thisformid).style.background = color2; 
				}
			}
		}
		if (allgood) {
			return true;
			} else {
			return false;
			}
	}

//IMAGE ROLLOVER
//Last Update August 1, 2008
function setupRollover(thisImage) {
	thisImage.outImage = new Image();
	thisImage.outImage.src = thisImage.src;
	thisImage.onmouseout = rollOut;
	thisImage.overImage = new Image();
	thisImage.overImage.src = thisImage.src.replace('/off/','/on/')
	thisImage.onmouseover = rollOver;	
}

//ROLLOVER
function rolloverInit(){
	for (var i=0; i<document.images.length; i++) {
		if (document.images[i].getAttribute('name') == "rollover") {			
			setupRollover(document.images[i]);
		}
	}
}

//ROLLOVER
function rollOver() {
	this.src = this.overImage.src;
}

//ROLLOVER
function rollOut() {
	this.src = this.outImage.src;
}

function logina(formname,validateid,color1,color2) {
	//VALIDATE REQUIRED
	
	if(validateform(formname,color1,color2)){
		document.getElementById("indicator").style.display = "block";
		//AJAX POST
		new Ajax.Request('/ajax/login.asp', {
		method: "post",
		parameters: Form.serialize(document.forms[formname]),
		onSuccess: function(transport,formname) { 	
			//LOG IN EXISTS?
			if (transport.responseText=='true'){
				document.getElementById(validateid).innerHTML = '';
				document.location.href = '/investors'
			} else {
				document.getElementById("indicator").style.display = "none";
				if (transport.responseText=='falselockout'){
					document.getElementById("login").innerHTML = 'Too many attempts.  Sorry.';
				} else {
				document.getElementById(validateid).innerHTML = 'Invalid Log In';
				if (document.getElementById(validateid).style.display == "none"){
					Effect.Appear(validateid,'blind');
				} else {
					Effect.Shake(validateid);
					}
				}
				}
			}//-onSuccess
			}//-request arguments
			);// new ajax request		
	} else {
			//FILL IN THE REQUIRED FIELDS
			if (document.getElementById(validateid).style.display == "none"){
				document.getElementById(validateid).innerHTML = 'Please fill in required fields';
					Effect.Appear(validateid,'blind');
					} else {
					Effect.Shake(validateid);
					}
	}
}

function arethesame(condition1,condition2){
	if (condition1 == condition2) {
			return true;
			} else {
			return false;
			}
}

function buildaccount(formname,validateid,color1,color2) {
	var allgood
	allgood = true;
	var validatemessage
	validatemessage = ''
	
	//VALIDATE REQUIRED
	if (!validateform(formname,color1,color2)){
		allgood = false;
		validatemessage += 'Please Fill in Required Fields<br>'
	}
	
	//EMAIL IS VALID?
	var email = document.getElementById("email").value;
	if(!validEmail(email)){
		validatemessage += 'Invalid Email<br>'
		document.getElementById("email").style.background = "yellow"; 
		allgood = false;
	}
		
	//PASSWORDS	MATCH?
	var condition1 = document.getElementById("password").value;
	var condition2 = document.getElementById("password2").value;
	var passwordgood 
	if (!arethesame(condition1,condition2)){
		validatemessage += 'Your Password don\'t match<br>'
		document.getElementById("password").style.background = "yellow"; 
		document.getElementById("password2").style.background = "yellow"; 
		allgood = false;
		}
	
	//AJAX, IF USER EXISTS
	if(allgood){
		document.getElementById("accindicator").style.display = "block";
		new Ajax.Request('/ajax/account.asp', {
		method: "post",
		parameters: Form.serialize(document.forms[formname]),
		onSuccess: function(transport,formname) { 	
			//LOG IN EXISTS?
			if (transport.responseText=='false'){
				document.getElementById("accindicator").style.display = "none";
				document.getElementById(validateid).innerHTML = '';
				document.getElementById("accountform").style.display = "none";
				document.getElementById("accthankyou").style.display = "block";
				//done and thank you
				
			} else {
				document.getElementById("accindicator").style.display = "none";
				
				document.getElementById(validateid).innerHTML = 'This Username is Not Available';
				if (document.getElementById(validateid).style.display == "none"){
					Effect.Appear(validateid,'blind');
				} else {
					Effect.Shake(validateid);
					}
				
			}
		}//-onSuccess
		}//-request arguments
		);// new ajax request		
	} else {
			//FILL IN THE REQUIRED FIELDS
			if (document.getElementById(validateid).style.display == "none"){
				document.getElementById(validateid).innerHTML = validatemessage;
					Effect.Appear(validateid,'blind');
					} else {
					Effect.Shake(validateid);
					}
	}
}

function logoff(){
		//AJAX POST
		new Ajax.Request('/ajax/logoff.asp', {
		method: "get",
		onSuccess: function(transport,formname) { 	
				document.location.reload()
			}
			//-onSuccess
			}//-request arguments
			);// new ajax request		
}

window.onload = masterloader;

function masterloader(){
	rolloverInit();
}
