﻿/*--------------------------------------------------+
 | Tog - Toggle visibility of two opposing elements |
 +--------------------------------------------------*/
var Tog = {
	check : function (a, b) {
		for (var i = 0; i < a.length; i++) {
			if (document.getElementById(a[i]).checked) {
				Tog.toggle(b[i]);
			}
		}
	}, 
	checkRadioSelected : function (radiolist, toggleElement) {
		for(var i=0; i < radiolist.length;i++)
		{
			if( radiolist[i].checked)
			{
			  if(radiolist[i].value == "3")
			   {
				 Tog.toggle(toggleElement);
			   }
			}
		}
	},
	swap : function (a, b) {
		a = document.getElementById(a);
		b = document.getElementById(b);
		
		if (!a || !b) return false;
		
		if (a.className.indexOf("closed") != -1) {
			oldClass = a.className;
			newClass = oldClass.replace(/closed/g, "");
			a.className = newClass;
			
			b.className += " closed";
		} else {
			oldClass = b.className;
			newClass = oldClass.replace(/closed/g, "");
			b.className = newClass;
			
			a.className += " closed";
		}
	},
	toggle : function (a) {
		a = document.getElementById(a);
		if (!a) return false;
		
		if (a.className.indexOf("closed") != -1) {
			oldClass = a.className;
			newClass = oldClass.replace(/closed/g, "");
			a.className = newClass;
		} else {
			a.className += " closed";
		}
	},
	show : function (a) {
	    a = document.getElementById(a);
	    if (!a) return false;
	    
	    if (a.className.indexOf("closed") != -1) {
	        oldClass = a.className;
	        newClass = oldClass.replace(/closed/g, "");
	        a.className = newClass;
	    }
	},
	hide : function (a) {
	    a = document.getElementById(a);
	    if (!a) return false;
	    
	    if (a.className.indexOf("closed") == -1) {
	        a.className += " closed";
	    }
	},
	showVisibility : function (a) {
	    a = document.getElementById(a);
	    if (!a) return false;
	    
	    if (a.className.indexOf("off") != -1) {
	        oldClass = a.className;
	        newClass = oldClass.replace(/off/g, "");
	        a.className = newClass;
	    }
	},
	hideVisibility : function (a) {
	    a = document.getElementById(a);
	    if (!a) return false;
	    
	    if (a.className.indexOf("off") == -1) {
	        a.className += " off";
	    }
	},
	togglePropertyValue : function (a, prop, value1, value2) {
		a = document.getElementById(a);
		
		if (!a) return false;
		
		if (a[prop].indexOf(value1) != -1) {
			a[prop] = value2;
		} else {
			a[prop] = value1;
		}
	}
};

var ValidateField = 
{
    isZip : function(s)
    {
        reZip = new RegExp(/(^\d{5}$)|(^\d{5}-\d{4}$)/);
        if (!reZip.test(s)) 
        {
            return false;
        }
        return true;
    }
}

/*-----------------------------------+
 | Email - Obfuscate email addresses |
 +-----------------------------------*/
var Email = 
{
	// Finds all email links with the class name "email-link" and reverses the innerHTML and href
	// Also removes the "email-link" class so the style sheet won't reverse the innerHTML
	fixEmails : function ()
	{
		$$(".email-link").each
		(
			function(emailAddr)
			{
				var emailLink = emailAddr.href.replace("mailto:", "");
				emailAddr.href = "mailto:" + Email.reverseString(emailLink);
				emailAddr.innerHTML = Email.reverseString(emailLink);
				emailAddr.className = emailAddr.className.replace("email-link", "");
			}
		)
	},

	// Takes in a string and returns the reverse of it
	reverseString : function(sourceString)
	{
		var reversedString = "";
		for(var i = sourceString.length - 1; i >= 0; i--)
		{
			reversedString += sourceString.charAt(i);
		}
		return reversedString;
	}
}

function wopen(url, name, w, h)
{
    w += 32;
    h += 96;
     var win = window.open(url,
      name,
      'width=' + w + ', height=' + h + ', ' +
      'location=no, menubar=no, ' +
      'status=no, toolbar=no, scrollbars=yes, resizable=no');
     //window.moveTo(0,0);
     //win.resizeTo(w, h);
     //win.focus();
}