// Add to favorites fonction
function bookIt(argVal)
{
   var bookData = new Array();
   bookData = argVal.split("|");
   if (document.all)
      window.external.AddFavorite(bookData[0], bookData[1]);
   else
      alert("Sorry. Netscape users must bookmark the pages manually by hitting <Ctrl-D>");
}
function doSearch()
{
   var oQuery = document.getElementById("iQuery")
   if(oQuery.value != '' && oQuery.value.length >= 2)
    {
      window.document.location.href="search-results.asp?q="+oQuery.value
      //window.document.location.href="http://coveo.neomedia.com/progarchives/default.asp?q="+oQuery.value
     } 
}
function fnTrapKD(){
   if(event.keyCode == 13)
      doSearch()
   else
      event.returnValue=true;
}
function fcTrapFocus()
{
   var oQuery = document.getElementById("iQuery")
   if(oQuery.value != 'SEARCH')
      oQuery.value  = ''
}
function ValidContactForm()
{
    var strEmail = window.document.Fcontact.Iemail.value;
    
    if(window.document.Fcontact.Iname.value == "")
    {
        alert("Please enter your name");
        window.document.Fcontact.Iname.focus();
        return false;
    }
	 else if(strEmail.indexOf("@") == -1 || strEmail.indexOf(".") == -1)
	 {
		 alert("Please, provide a valid email adress");
		 window.document.Fcontact.Iemail.focus();
		 return false;
	 }
	 else if(window.document.Fcontact.Isubject.value == "")
	 {
		 alert("Please, provide a message subject");
		 window.document.Fcontact.Isubject.focus();
		 return false;
	 }
	 else if(window.document.Fcontact.Imessage.value == "")
	 {
		 alert("Please, provide a message");
		 window.document.Fcontact.Imessage.focus();
		 return false;
	 }
    else 
    {
       alert("Your message will be sent!\nYou will now be redirected to the ProgArchives home page.")
       return true;
    }
}

/****************************************************
*	        DOM Image rollover:
*		by Chris Poole
*		http://chrispoole.com
*               Script featured on http://www.dynamicdrive.com
*		Keep this notice intact to use it :-)
****************************************************/

function init() {
  if (!document.getElementById) return
  var imgOriginSrc;
  var imgTemp = new Array();
  var imgarr = document.getElementsByTagName('img');
  for (var i = 0; i < imgarr.length; i++) {
    if (imgarr[i].getAttribute('hsrc')) {
        imgTemp[i] = new Image();
        imgTemp[i].src = imgarr[i].getAttribute('hsrc');
        imgarr[i].onmouseover = function() {
            imgOriginSrc = this.getAttribute('src');
            this.setAttribute('src',this.getAttribute('hsrc'))
        }
        imgarr[i].onmouseout = function() {
            this.setAttribute('src',imgOriginSrc)
        }
    }
  }
}
//onload=init;


function showFullBio()
{
	oDivShort = document.getElementById("shortBio")
	oDivMore = document.getElementById("moreBio")
	oDivShort.style.display = 'none';
	oDivMore.style.display = 'block';
	
	oA = document.getElementById("aMoreLink")
	oA.style.display = 'none';
}

function handleCovers()
{
	if(document.getElementById("ishowcovers").checked == true)
	{
		createCookie('covers','1',365)
		//alert("cover=true")
	}
	else
	{
		createCookie('covers','0',365)
		//alert("cover=false")
	}
    
	window.document.location.href = window.document.location.href
		
}

//WORD and CARACTER counter for review
   var submitcount=0;
   function checkSubmit() {

      if (submitcount == 0)
      {
      submitcount++;
      document.Surv.submit();
      }
   }


function wordCounter(field) 
{
	wordcounter=0;
	
	for (x=0;x<field.value.length;x++) 
	{
      if (field.value.charAt(x) == " " && field.value.charAt(x-1) != " ")  
	  	wordcounter++
    }
	alert(wordcounter + " words")
	
}

function textCounter(field, countfield, maxlimit) {
  if (field.value.length > maxlimit)
      {field.value = field.value.substring(0, maxlimit);}
      else
      {countfield.value = maxlimit - field.value.length;}
  }
  
  function expandIndex()
	{
		
		oDivN = document.getElementById("nav-wrap");
		
		oDivAB = document.getElementById("navAlphaBands");
		oDivAA = document.getElementById("navAlphaAlbums");
		oDivG = document.getElementById("navGenre");
        oDivTop = document.getElementById("navTop");
		
		switch(readCookie('nav'))
		{
			case 'alphabands': // next to alphaalbums
				oDivAB.style.display = 'none';
				oDivAA.style.display = 'block';
				oDivG.style.display = 'none';
                oDivTop.style.display = 'none';
				createCookie('nav','alphaalbums',365);
				break;
				
			case 'alphaalbums': // next to genre
				oDivAB.style.display = 'none';
				oDivAA.style.display = 'none';
				oDivG.style.display = 'block';
                oDivTop.style.display = 'none';
				createCookie('nav','genre',365);
				break;
				
			case 'genre': // next to top
				oDivAB.style.display = 'none';
				oDivAA.style.display = 'none';
				oDivG.style.display = 'none';
                oDivTop.style.display = 'block';
				createCookie('nav','top',365);
				break;
                
            case 'top': // next to alphabands
				oDivAB.style.display = 'block';
				oDivAA.style.display = 'none';
				oDivG.style.display = 'none';
                oDivTop.style.display = 'none';
				createCookie('nav','alphabands',365);
				break;

		}
		
	}
	
	function createCookie(name,value,days)
	{
		if (days)
		{
			var date = new Date();
			date.setTime(date.getTime()+(days*24*60*60*1000));
			var expires = "; expires="+date.toGMTString();
		}
		else var expires = "";
		document.cookie = name+"="+value+expires+"; path=/";
	}
	
	function readCookie(name)
	{
		var nameEQ = name + "=";
		var ca = document.cookie.split(';');
		for(var i=0;i < ca.length;i++)
		{
			var c = ca[i];
			while (c.charAt(0)==' ') c = c.substring(1,c.length);
			if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
		}
		return null;
	}
	
	function eraseCookie(name)
	{
		createCookie(name,"",-1);
	}
    
    
    function openRatingForm()
{
   oDivRatingForm = document.getElementById("divRatings")
   oDivRatingForm.style.display = 'block';
   oSpanNoComments= document.getElementById("lblNoComments")
   if(oSpanNoComments)
      oSpanNoComments.style.display = 'none';
   document.getElementById("icomment").focus()
}


function echeck(str) 
{
    
    var at="@"
    var dot="."
    var lat=str.indexOf(at)
    var lstr=str.length
    var ldot=str.indexOf(dot)
    if (str.indexOf(at)==-1){
     alert("Invalid E-mail ID")
     return false
    }
    
    if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
     alert("Invalid E-mail ID")
     return false
    }
    
    if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
      alert("Invalid E-mail ID")
      return false
    }
    
    if (str.indexOf(at,(lat+1))!=-1){
      alert("Invalid E-mail ID")
      return false
    }
    
    if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
      alert("Invalid E-mail ID")
      return false
    }
    
    if (str.indexOf(dot,(lat+2))==-1){
      alert("Invalid E-mail ID")
      return false
    }
    
    if (str.indexOf(" ")!=-1){
      alert("Invalid E-mail ID")
      return false
    }
    
    return true					
}


function ValidForm()
{
   oForm = document.getElementById("Frateit")
   //oInputName = document.getElementById("Iname")
   oInputEmail = document.getElementById("Iemail")
   oRadioRating = document.getElementById("hRateValue")
   oChkGuidelines = document.getElementById("IacceptRules")

   if( oInputEmail.value!=null & echeck(oInputEmail.value) & oRadioRating.value != '' & oChkGuidelines.checked == true)
   {
	  oForm.submit();
	  return true;
   }
   else
   {
      alert('You must enter your name, email, ratings and read and check the guidelines.\nThank You');
      oInputEmail.focus();
      return false;
   }
   
}
function OpenGuidelines()
{
   oDivRatingForm = document.getElementById("divGuidelines")
   oDivRatingForm.style.display = 'block';
}

function checkFiveStars()
{
   alert('\nPROG ARCHIVES REVIEWS GUIDELINES WARNING\n\n\nBefore assigning a star rating to an album, you should carefully consider what the differing numbers of stars stand for.Please use "zero" and "five star" ratings very sparingly -- most albums you dislike will have at least some positive qualities, and not every album that you enjoy will be a perfect "masterpiece."')
}
