var validate = false;

function alertAndFocus(element, alertText) {
	alert(alertText);
	element.focus();	
}
function isSelectedIndex(element, errorAlert, indexValue) {     
	if (element.selectedIndex == indexValue) {  
		alertAndFocus(element, errorAlert)		
		//alert(errorAlert);
		//element.focus();
		return false;        
	}  
	return true;
}
function isChecked(eName)  {	
	//alert(eName);
	formElement = document.getElementsByName(eName);		
	for ( i=0 ; i < formElement.length; i++ ) {		
		if (formElement[i].checked == true ) {			
			return true;			
		}		
	}
	return false;
}

function isEmpty(element, defaultValue, errorAlert) { 
	if ( (element.value == "" ) || (element.value == defaultValue ) ){ 
		alertAndFocus(element,errorAlert); 
		return true;  
	} else {
		return false;  
	}
}
function isNumerical(stringInput, allowedChars) {  
	var decPoints = 0;
	var decCheck = false;    
	
	if (allowedChars.indexOf(".") != -1) {     
		decCheck = true;
	}                 
	for (i = 0;  i < stringInput.length;  i++)  {
		ch = stringInput.charAt(i);            
		if (allowedChars.indexOf(ch) == -1) {    
			return false;
		}             
		if ( (decCheck == true) && (ch == ".") ) {
			decPoints++;
			if (decPoints > 1) {
				return false;
			}
		}         
	}
	return true;
}
function isValidAge(newAge, minAge, maxAge) {	
	if ( (Number(newAge) >= minAge) && (Number(newAge) <= maxAge) ) {
		return true;
	} else {
		return false;
	}
}
function isChild(age) {
	if ( isValidAge(age, 0, 17) ) {
		return true;
	} else {
		return false;
	}
}
function isAdult(age, minAge, maxAge) {
	if ( isValidAge(age, minAge, maxAge) ) {
		return true;
	} else {
		return false;
	}
}
function validateEmail(email, defaultText) {	
	if ((email == "") || (email == defaultText)) {
		return false;
	} else {
		eLength = email.length;
		eAt = email.indexOf("@"); 
		eDot = email.lastIndexOf(".");	
		eSpace = email.indexOf(" ");
		
		// if no @ sign, @ is at start or end of email
		if ( (eAt == -1) || (eAt == 0) || (eAt == eLength-1) ) {
			return false;
		} else {
			// if no dot, dot is at start end or next to or less than @
			if ( (eDot == -1) || (eDot == 0) || (eDot == eLength-1) || (eDot <= eAt+1)  )  {
				return false;
			}		
		}
		if (eSpace != -1) {
			return false;	
		}
	}
	return true;
}
function clearInput(defaultText, elementName) {	
	element = document.getElementById(elementName);			
	//alert(element.value)
	if (element.value == defaultText) {
		element.value= "";
	}	
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function valSignIn() {
	//frmUsername
	//frmPassword
	if ( isEmpty(document.getElementById("frmUsername"), "username", "Please enter your username.")) {
		return false;
	}
	if ( isEmpty(document.getElementById("frmPassword"), "password", "Please enter your password.")) {
		return false;
	}

	return true;
}
function swapImage(strImage,strElement) {
	if ( (strImage != "") && (strElement != "") ) {
		//strImageL = strImage + "&t=l";
		//strImageXL = strImage + "&t=xl";
		//alert(strImageL);
		document.getElementById(strElement).src = strImage;
		//document.getElementById("mainImageLink").href = strImageXL;
	}
	return false;
}
function closeWindow() {
	window.close();
}

function jsLayer_getHTML(elementId, innerContent) {
			
	var showHtml;
	
	showHtml = "";
	showHtml = showHtml + "<div class='layer' id='" + elementId + "'>";					
		showHtml = showHtml + "<div class='top'><a href='#' class='close' title='Close'><img src='/images/buttons/thickbox_close.gif' alt='Close' /></a></div>";
		showHtml = showHtml + "<div class='innerContent'>";					
		showHtml = showHtml + innerContent;
		showHtml = showHtml + "</div>";
	showHtml = showHtml + "</div>";
											
	//alert(showHtml);
	return showHtml;
}


function jsLayer_attachEvents(selector) {
	$("#" + selector + " a.close").click(function() {		
		// hide any layers already showing
		$(this).parent().parent().fadeOut("fast");						
		return false;
	});	
}


	
function jsLayer_show(elementID, contentSourceID) {
	
	if (document.getElementById(elementID)) {
		// the layer already exists so we can just show the layer
		
	} else {			
		// layer does not exist so we need to create it
				
		layerContent = $("#" + contentSourceID).html();															
		alert(layerContent);				
		//layerContent = ""
		
		layerHtml = jsLayer_getHTML(elementID, layerContent);
		
										
		$("#header").after(layerHtml);
		
					
		// attach events needed by the layer, eg close
		jsLayer_attachEvents(elementID);
	}
	
	// hide all open layers
	$("div.layer").hide();		
	
	// show the layer
	$("#" + elementID).fadeIn("fast");		
}

function init_topspinLayers() {
	
	jsLayer_attachEvents("layerGetFreeMusic");	
	//jsLayer_attachEvents("layerJoinFreeland");
	
	$("li.getFreeMusic a").click(function() {		
		// the id of the new layer, the id of the element to copy		
		jsLayer_show("layerGetFreeMusic", "topspin_getFreeMusic")		
		return false;
	});
	
/*	$("li.joinFreeland a").click(function() {
		// hide any layers already showing
		
		jsLayer_show("layerJoinFreeland", "topspin_joinFreeland")
		
		return false;
	});
*/	
}
