function ValidateEmail()
{		
	var emailID = document.formCart.email
	
	if ((emailID.value==null)||(emailID.value=="")){
		alert("Please Enter your Email address")
		emailID.focus()
		return false
	}
	if (IsValidEmailAddress(emailID.value)==false){
		emailID.value=""
		emailID.focus()
		return false
	}
	return true				
}

function IsValidEmailAddress(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 CreateList(QString, List)
{
	var oSongList
	if(List == 1)
	{
		oSongList = List1();
	}
	else
	{
		oSongList = List2();
	}
	
	for(var i=0; i < oSongList.length; i++)
	{
		document.write("<TR><TD><FONT face=arial color=#ffffff size=2><B><I><SPAN>");
		document.write(oSongList[i][1]);
		document.write("</SPAN></I></B></FONT></TD></TR>");
		document.write("<TR><TD><FONT face=arial color=#ffffff size=2>Album:<B><I><SPAN>");
		document.write(oSongList[i][0]);
		document.write("</SPAN></I></B></FONT></TD></TR>");
		document.write("<TR><TD><TABLE border=0>");
		for(var j=0; j < oSongList[i][2].length; j ++)
		{
			document.write("<TR><TD><FONT face=arial color=#ffffff size=2>");
			document.write("<INPUT type=checkbox name=songs value=" + oSongList[i][2][j][0]);
			if(QString.indexOf(oSongList[i][2][j][0]) != -1)
			{
				document.write(" checked=true ");
			}
			document.write(">");
			document.write("<SPAN>" + oSongList[i][2][j][1] + "</SPAN></FONT></TD></TR>");
		}
		document.write("</TABLE></TD></TR>");
	}
}

function GetSongsIndex(Checkboxlist)
{
		var strResult = "";
		var orderCount = 0;				
		
		for (var i=0; i<Checkboxlist.length; i++) 
		{
			if (Checkboxlist[i].checked)
			{
					if(orderCount>0)
					{
						strResult = strResult + ",";
					}
					strResult = strResult + Checkboxlist[i].value;
					orderCount = orderCount + 1;					
			}		
        }
        
        
        if(orderCount>0)
        {
			window.location = "cart.htm?songid=" + strResult;
        }
        else
        {
			alert("No orders have been made yet.");
        }
        
}

function GetSongs(Checkboxlist, action)
{
		
		var strResult = "";
		var orderCount = 0;
		if(Checkboxlist.length + "" == "undefined")
		{
			if(!Checkboxlist.checked)
			{
				orderCount = 1;
				strResult = Checkboxlist.value;
			}
		}
		else
		{
			for (var i=0; i<Checkboxlist.length; i++) 
			{
				if (!Checkboxlist[i].checked)
				{				
					if(orderCount>0)
					{
						strResult = strResult + ",";
					}
					strResult = strResult + Checkboxlist[i].value;
					orderCount = orderCount + 1;							
				}
			}			
		}
	if(orderCount < 1)
        {
			if(action == 3)
			{
				window.location = "index.htm"
			}
			else
			{
				alert("No orders have been made yet.");
				return false;			
			}
        }
        else
        {
			switch(action)
			{				
				case 2: window.location = "index.htm?songid=" + strResult; break;
				case 3: window.location = "cart.htm?songid=" + strResult; break;
				case 4: 
					var emailadd = document.formCart.email.value
					window.location = "http://www.pldtmypad.com/msn/shoppingcart/triad.asp?songID=" + strResult + "$" + emailadd; break;				
			}
			return;
	}      
}
	
function PageQuery(q) 
{
		if(q.length > 1) this.q = q.substring(1, q.length);
		else this.q = null;
		this.keyValuePairs = new Array();
		if(q) 
		{
			for(var i=0; i < this.q.split("&").length; i++) 
			{
				this.keyValuePairs[i] = this.q.split("&")[i];
			}
		}
		this.getKeyValuePairs = function() { return this.keyValuePairs; }
		this.getValue = function(s) 
		{
			for(var j=0; j < this.keyValuePairs.length; j++) 
			{
				if(this.keyValuePairs[j].split("=")[0] == s)
				return this.keyValuePairs[j].split("=")[1];
			}
			return false;
		}
		this.getParameters = function() 
		{
			var a = new Array(this.getLength());
			for(var j=0; j < this.keyValuePairs.length; j++) 
			{
				a[j] = this.keyValuePairs[j].split("=")[0];
			}
			return a;
		}
		this.getLength = function() { return this.keyValuePairs.length; } 
}
		
function queryString(key)
{
		var page = new PageQuery(window.location.search); 
		return unescape(page.getValue(key)); 
}
