/**************************************************/
//window functions
/**************************************************/
function openWin(file,winname, w, h)
{	
	var myWin;
	details="top=0,left=0,width="+w+",height="+h+",status=no,";
	details += "resizable=yes,scrollbars=yes,menubar=no,location=no";

	myWin = window.open(file, winname, details);
	myWin.focus();
}

/**************************************************/
//div functions
/**************************************************/
function toggleDiv(tagname)
{
	var openclose;
	obj = document.getElementById(tagname);
	if(obj.style.display == 'block')
	{
		openclose = 0;
		obj.style.display = 'none';
	}
	else if(obj.style.display ==  'none')
	{
		openclose = 1;
		obj.style.display = 'block';
	}
	else if(obj.style.diplay == null || obj.style.display == '')
	{
		openclose = 0;
		obj.style.display = 'none';
	}

	return openclose;
}
function showHideDiv(tagname, showhide)
{
    if (showhide == 1)
    {
		obj = document.getElementById(tagname);
		if(obj)
			obj.style.display='block';
    }

    if (showhide == 0)
    {
		obj = document.getElementById(tagname);
		if(obj)
			obj.style.display='none';
    }

}

function validEmail(eAddr) 
{ 
	var regexp;

	if(eAddr == "" || eAddr == null)
	{
		return false;
	}

	result = eAddr.match(/^[a-z0-9]+([_\.-][a-z0-9]+)*@([a-z0-9]+([\.-][a-z0-9]+)*)+\.[a-z]{2,}$/i);

	if(result == null || result == '')
		return false;
	else	
		return true;
} 

/**************************************************/
//masking functions
/**************************************************/
function maskSSN(thefield)
{
	strobj = new String(thefield.value);
	value = new String (strobj.replace(/\D*/g, ""));

	if(value.length > 3)		
	{
		firstset = value.substr(0,3);
		n2 = value.substr(3,2);

		newvalue = firstset + "-";	
		newvalue = newvalue + n2;

		if(value.length > 5)
		{
			n4 = value.substr(5,4);
			newvalue = newvalue + "-" + n4; 
		}

		thefield.value = newvalue;
	}
	else
	{
		thefield.value = value;
	}
}
function maskPhoneNumber(thefield)
{
	strobj = new String(thefield.value);
	value = new String (strobj.replace(/\D*/g, ""));

	if(value.length > 3)		
	{
		areacode = value.substr(0,3);
		n3 = value.substr(3,3);

		newvalue = areacode + "-";	
		newvalue = newvalue + n3;

		if(value.length > 6)
		{
			n4 = value.substr(6,4);
			newvalue = newvalue + "-" + n4; 
		}

		thefield.value = newvalue;
	}
	else
	{
		thefield.value = value;
	}
}
function maskDecimal(thefield, limit)
{
    strobj = new String(thefield.value);
    newvalue = new String (strobj.replace(/[^\d\.-]*/g, ""));
	if(newvalue.length > limit)
		value = newvalue.substr(0,limit);
	else
		value = newvalue;
		
    thefield.value = value;
}

function maskAlphaNumeric(thefield, limit)
{
    strobj = new String(thefield.value);
    newvalue = new String (strobj.replace(/[^\w-_]*/g, ""));
	if(newvalue.length > limit)
		value = newvalue.substr(0,limit);
	else
		value = newvalue;
		
    thefield.value = value;
}
function maskNumber(thefield, limit)
{
    strobj = new String(thefield.value);
    newvalue = new String (strobj.replace(/\D*/g, ""));
	if(newvalue.length > limit)
		value = newvalue.substr(0,limit);
	else
		value = newvalue;
		
    thefield.value = value;
}

function maskZipCode(thefield, limit)
{
    strobj = new String(thefield.value);
    newvalue = new String (strobj.replace(/[^\w-_ ]*/g, ""));
	if(newvalue.length > limit)
		value = newvalue.substr(0,limit);
	else
		value = newvalue;
		
    thefield.value = value;
}

/**************************************************/
// PNG functions
// correctly handle PNG transparency in Win IE 5.5 or higher.
/**************************************************/
function correctPNG()
{
	var arVersion = navigator.appVersion.split("MSIE")
	var version = parseFloat(arVersion[1])

	if ((version <= 6) && (document.body.filters))
	{
		for(var i=0; i<document.images.length; i++)
		{
			var img = document.images[i]
			var imgName = img.src.toUpperCase()
			if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
			{
				var imgID = (img.id) ? "id='" + img.id + "' " : ""
				var imgClass = (img.className) ? "class='" + img.className + "' " : ""
				var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
				var imgStyle = "display:inline-block;" + img.style.cssText
				if (img.align == "left") imgStyle = "float:left;" + imgStyle
				if (img.align == "right") imgStyle = "float:right;" + imgStyle
				if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
				var strNewHTML = "<span " + imgID + imgClass + imgTitle
				+ " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
				+ "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
				+ "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>"
				img.outerHTML = strNewHTML
				i = i-1
			}
		}
	}
}

/**************************************************/
// VIDEO functions
/**************************************************/
function closeVideo(divid)
{
	 showHideDiv(divid,0);
}

function showVideo(divid, url, width, height, bgcolor)
{
	if(document.getElementById(divid))
	{
		showHideDiv(divid,1);
	}
	else
	{
		//display you tube video
		var browserName = navigator.appName; 
		var content = "";
		/*if(browserName == "Microsoft Internet Explorer")
		{
			//openWin("youtubevideo.php?src=" + url, 'gbtvideo', 500,400);
		}
		else
		{
		*/
			var newdiv = document.createElement('div');
			var html;
			var leftdif = width/2;
			var topdif = height/2;
			
			newdiv.setAttribute('id', divid);
			   
			   html = "<div id='"+ divid +" class='videoFloat' style='padding: 15px; background-color: #ffffff; position: absolute; left: 50%; top: 50%; -moz-border-radius: 5px; -webkit-border-radius: 5px; margin-top: -"+ topdif +"px; margin-left: -"+ leftdif +"px; z-index: 100000;'>";
				   html += "<div style='padding: 15px; background-color: "+ bgcolor +"; -moz-border-radius: 5px; -webkit-border-radius: 5px;'>";
					   html += "<object classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" codebase=\"http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0\" width=\"320\" height=\"255\" id=\""+ divid +"_video\" align=\"middle\">";
					   html += "<param name=\"allowScriptAccess\" value=\"sameDomain\" />";
					   html += "<param name=\"movie\" value=\""+ url +"\" />";
					   html += "<param name=\"quality\" value=\"high\" />";
					   html += "<param name=\"bgcolor\" value=\""+ bgcolor +"\" />";
						   html += "<embed src=\""+ url + "\" quality=\"high\" bgcolor=\""+ bgcolor +"\" width=\""+ width +"\" height=\""+ height +"\" name=\""+ divid +"_video\" align=\"middle\" allowScriptAccess=\"sameDomain\" type=\"application/x-shockwave-flash\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\">";
					   html += "</object>";
				   html += "</div>";
				   html += "<a style='-moz-border-radius: 5px; -webkit-border-radius: 5px; background-color: #eeeeee; float: right; clear; both; color: #666666; display: block; border: 1px #666666 solid; padding: 4px 8px; margin: 4px 0 0 0; text-decoration: none;' href=\"javascript:closeVideo('"+ divid +"');\">CLOSE</a>";
			   html += "</div>";
			   if (html)
				   newdiv.innerHTML = html;
			   
			   document.body.insertBefore(newdiv, document.body.childNodes[0]);

		//}	
	}	
}


