/////////////////////////////////////////////////////////////
//
//  GLOBAL JAVASCRIPT FUNCTIONS
//
/////////////////////////////////////////////////////////////

function chkBrowser()
{
	var detect = navigator.userAgent.toLowerCase();
	if (checkIt('msie', detect))
	{
		return "block";
	}
	else
	{
		return "table-row";
	}
}	

function checkIt(string, detect)
{
	place = detect.indexOf(string) + 1;
	thestring = string;
	return place;
}


//  toggle a layer display

function toggleLayer(whichLayer)
{
	var useCSS = chkBrowser();

	useItem = window.document.getElementById(whichLayer).style.display;

	if ( ("block" == useItem) || ("table-row" == useItem) || ("" == useItem))
	{

		window.document.getElementById(whichLayer).style.display = 'none';
	}
	else
	{
		window.document.getElementById(whichLayer).style.display = useCSS;
	}
}

	function emailCheck (emailStr)
	{

		var checkTLD=1;
		var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;
		var emailPat=/^(.+)@(.+)$/;
		var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";
		var validChars="\[^\\s" + specialChars + "\]";
		var quotedUser="(\"[^\"]*\")";
		var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
		var atom=validChars + '+';
		var word="(" + atom + "|" + quotedUser + ")";
		var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
		var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");

		var matchArray=emailStr.match(emailPat);

		if (matchArray==null)
		{
			//alert("Email address seems incorrect (check @ and .'s)");
			return false;
		}

		var user=matchArray[1];
		var domain=matchArray[2];

		for (i=0; i<user.length; i++)
		{
			if (user.charCodeAt(i)>127)
			{
				//alert("Ths username contains invalid characters.");
				return false;
			}
		}

		for (i=0; i<domain.length; i++)
		{
			if (domain.charCodeAt(i)>127)
			{
				//alert("Ths domain name contains invalid characters.");
				return false;
			}
		}

		if (user.match(userPat)==null)
		{
			//alert("The username doesn't seem to be valid.");
			return false;
		}

		var IPArray=domain.match(ipDomainPat);
		if (IPArray!=null)
		{
			for (var i=1;i<=4;i++)
			{
				if (IPArray[i]>255)
				{
					//alert("Destination IP address is invalid!");
					return false;
				}
			}
			return true;
		}

		var atomPat=new RegExp("^" + atom + "$");
		var domArr=domain.split(".");
		var len=domArr.length;

		for (i=0;i<len;i++)
		{
			if (domArr[i].search(atomPat)==-1)
			{
				alert("The domain name does not seem to be valid.");
				//return false;
			}
		}

		if (checkTLD && domArr[domArr.length-1].length!=2 && domArr[domArr.length-1].search(knownDomsPat)==-1)
		{
			//alert("The address must end in a well-known domain or two letter " + "country.");
			return false;
		}

		if (len<2)
		{
			//alert("This address is missing a hostname!");
			return false;
		}

		return true;
	}
	
function getLayer(whichLayer)
{
	if (document.getElementById)
	{
		// this is the way the standards work
		return document.getElementById(whichLayer);
	}
	else if (document.all)
	{
		// this is the way old msie versions work
		return document.all[whichLayer];
	}
	else if (document.layers)
	{
		// this is the way nn4 works
		return document.layers[whichLayer];
	}
}

function changeMain(changeTo, layer)
{
	useImg = getLayer(layer);
	useImg.src=changeTo;
}


	function chkExtension(file, allowed)
	{
		if ( "" != file )
		{
			extLoc = file.lastIndexOf('.');

			if ( allowed != file.substring(extLoc) )
			{
				return false;
			}
		}

		return true;
	}




function openMov(movfile, title, width, height)
{

	winWidth = parseInt(width)+20;
	winHeight = parseInt(height)+20;
	
	
	url = "media/showmovie.php?mov="+movfile+"&width="+width+"&height="+height;
	
	window.open(url, "", "width="+winWidth+", height="+winHeight);
}


function openArtistMov(movfile, title, width, height)
{

	winWidth = parseInt(width)+20;
	winHeight = parseInt(height)+20;
	
	
	url = "media/showmovie.php?artist=1&mov="+movfile+"&width="+width+"&height="+height;
	
	window.open(url, "", "width="+winWidth+", height="+winHeight);
}

function chkDate(strValue)
{
	re = /^\d{1,2}\/\d{1,2}\/\d{4}$/;

    	if( !strValue.match(re) ) 
    	{
	 	return false;
    	}
	else
	{
    		for (i=0; i<strValue.length; i++) 
		{
			if ( strValue.charAt(i)>'9' || strValue.charAt(i)<'0')
			{
				break;
			}
		}

		var strSeparator=strValue.charAt(i);
		var arrayDate = strValue.split(strSeparator);
		var arrayLookup = { '01' : 31,'03' : 31, '04' : 30,'05' : 31,'06' : 30,'07' : 31, '08' : 31,'09' : 30,'10' : 31,'11' : 30,'12' : 31}
		
		var intDay = parseInt(arrayDate[0]);

		//  check if month value and day value agree
		
		if(arrayLookup[arrayDate[1]] != null) 
		{
			if (intDay <= arrayLookup[arrayDate[1]] && intDay != 0)
			{
				return true; //found in lookup table, good date
			}
		}	

		var intMonth = parseInt(arrayDate[0]);

		if (intMonth == 2) 
		{ 
			var intYear = parseInt(arrayDate[2]);

			if( ((intYear % 4 == 0 && intDay <= 29) || (intYear % 4 != 0 && intDay <=28)) && intDay !=0)
			{
				return true; //Feb. had valid number of days
			}	
		}
	}
	return false; //any other values, bad date
}


function openEmail(email, password)
{
	var subject = "Welcome to AMCK";
	var bodyText = "Welcome to AMCK.%0A%0ATo login to your artists section go to http://www.amck.tv/artists.%0A%0Ausername: " + email + "%0Apassword: " + password;
	
	window.location.href="mailto:" + email + "?subject=" + subject + "&body=" + bodyText;


}


startList = function() 
{
	if (document.all&&document.getElementById) 
	{
		navRoot = document.getElementById("navlist");
		
		for (i=0; i<navRoot.childNodes.length; i++) 
		{
			node = navRoot.childNodes[i];
		
			if (node.nodeName=="LI") 
			{
				node.onmouseover=function() 
				{
					this.className+=" over";
				}
		
				node.onmouseout=function() 
				{
					this.className=this.className.replace(" over", "");
				}
			}
		}
	}
}

window.onload=startList;



	