// JavaScript Document
startList = function() {
	//code only for IE
	if(!document.body.currentStyle) return;
	var subs = document.getElementsByName('submenu');
	for(var i=0; i<subs.length; i++) {
		var li = subs[i].parentNode;
		if(li && li.lastChild.style) {
			li.onmouseover = function() {
				this.lastChild.style.visibility = 'visible';
			}
			li.onmouseout = function() {
				this.lastChild.style.visibility = 'hidden';
			}
		}
	}
}
window.onload=startList;

function confirmMsg(msg){
	if(!confirm(msg)){
		return false;

	} else {
		return true;

	}
}
function showdeli(){
		if(document.frm_music.chk_upcome.checked){
		delistyle=document.getElementById("delivery");
		    if(delistyle){
			delistyle.style.display="block";
			delistyle.style.visibility="visible";
			}				
		}
		else
		{
			delistyle=document.getElementById("delivery");
			if(delistyle){
			delistyle.style.display="none";
			delistyle.style.visibility="hidden";
			}
		}
	}

function final_check()
{
//	Credit card Validation
	if (document.frm_finalcheckout.Cardname.value == ""){
		alert ("Please Select your Card Name");
		document.frm_finalcheckout.Cardname.focus();
		return false;
	}
	if (document.frm_finalcheckout.CardexpM.value == ""){
		alert ("Please Select the Expiry Month");
		document.frm_finalcheckout.CardexpM.focus();
		return false;
	}
	if (document.frm_finalcheckout.CardexpY.value == ""){
		alert ("Please Select the Expiry Year ");
		document.frm_finalcheckout.CardexpY.focus();
		return false;
	}
	if (document.frm_finalcheckout.Nameoncard.value == ""){
		alert ("Please enter your name as shown on your credit card");
		document.frm_finalcheckout.Nameoncard.focus();
		return false;
	}
	if (document.frm_finalcheckout.cardnumber.value == ""){
		alert ("Please Enter the Card Number");
		document.frm_finalcheckout.cardnumber.focus();
		return false;
	}
	if (isNaN(document.frm_finalcheckout.cardnumber.value) || (document.frm_finalcheckout.cardnumber.value.indexOf('-') > -1)){
		alert ("Card Number is invalid");
		document.frm_finalcheckout.cardnumber.value = "";
		document.frm_finalcheckout.cardnumber.focus();
		return false;
	}
	/*if (document.frm_finalcheckout.cvv2.value == ""){
		alert ("Please Enter the 3 digit code that is on the back of their credit card");
		document.frm_finalcheckout.cvv2.focus();
		return false;
	}*/
}


function forgetvalidate()
{
	if(document.Frmgetpass.username.value == "")
	{
		alert("Please Enter the Username");
		document.Frmgetpass.username.focus();
		return false;
	}
	if(!validateEmail(document.Frmgetpass.txtEmail.value,1,1)) 
	{
		document.Frmgetpass.txtEmail.focus();
		return false;
	}
}


function openw(){
	window.location.href = "studio.php";
}

function openwi(){
	window.location.href = "checkout.php";
}

function openwindow(){
	document.viewcart.action="deletecart.php";
	document.viewcart.submit();
}

function pop_printorder(url)
{
	var width = 700;
	var height = 600; 
	var left = screen.width/2 - (width/2);
	var top = 100;
	newwindow=window.open(url,'name','scrollbars=yes,resizable=yes,height='+height+',width='+width+',left='+left+',top='+top+'');
	if (window.focus) {newwindow.focus()}
}

function pop_news(url)
{
	var width = 650;
	var height = 400; 
	var left = screen.width/2 - (width/2);
	var top = 100;
	newwindow=window.open(url,'name','scrollbars=yes,resizable=yes,height='+height+',width='+width+',left='+left+',top='+top+'');
	if (window.focus) {newwindow.focus()}
}

function opencart(){
 	var len=document.viewcart.ONE.length;
		   var flag=0;
		  	for(var index=0;index<len;index++)
			{
			quantity = document.viewcart.ONE[index].value;
			stockvalue = document.viewcart.STOCK[index].value;
				if( (quantity == "")  || isNaN(quantity) || (quantity == 0) || (quantity.indexOf("-") >= 0) || (quantity.indexOf(".") >= 0) || (quantity > 65535) )
				{
					
							alert("Type the valid quantity");
							document.viewcart.ONE[index].focus();
							return false;
				}
				
				if(parseInt(quantity) > parseInt(stockvalue)){
						alert("Quantity is out of stock");
						document.viewcart.ONE[index].focus();
						return false;
				}
						
			}
document.viewcart.action="modifycart.php";
document.viewcart.submit();
}

function checkout_validate()
{
	if(document.checkout.fname.value == ""){
		alert("Please Enter the First Name");
		document.checkout.fname.focus();
		return false;
	}
	if(document.checkout.lname.value == ""){
		alert("Please Enter the Last Name");
		document.checkout.lname.focus();
		return false;
	}
	if(document.checkout.addr.value == ""){
		alert("Please Enter the Address");
		document.checkout.addr.focus();
		return false;
	}
	if(document.checkout.city.value == ""){
		alert("Please Enter the City");
		document.checkout.city.focus();
		return false;
	}
	if(document.checkout.state.value == "" && document.checkout.state1.value == "" && document.checkout.chk_state.checked == false){
		alert("Please Select or Enter the State");
		document.checkout.state.focus();
		return false;
	}
	if(document.checkout.country.value == ""){
		alert("Please Select the Country");
		document.checkout.country.focus();
		return false;
	}
	if(document.checkout.zip.value == "" && document.checkout.chk_zip.checked == false){
		alert("Please Enter the Zipcode");
		document.checkout.zip.focus();
		return false;
	}
	phone = document.checkout.phone;
	if (checkInternationalPhone(phone.value)==false)
	{
		alert("Please Enter a Valid Phone Number")
		phone.value=""
		phone.focus()
		return false
	}
	if (!validateEmail(document.checkout.email.value,1,1)) 
	{
		document.checkout.email.focus();
		return false;
	}
	if(!(document.checkout.chkDelivery.checked))
	{
		if(document.checkout.delifname.value == ""){
			alert("Please Enter the First Name");
			document.checkout.delifname.focus();
			return false;
		}
		if(document.checkout.delilname.value == ""){
			alert("Please Enter the Last Name");
			document.checkout.delilname.focus();
			return false;
		}
		if(document.checkout.deliaddr.value == ""){
			alert("Please Enter the Address");
			document.checkout.deliaddr.focus();
			return false;
		}
		if(document.checkout.delicity.value == ""){
			alert("Please Enter the City");
			document.checkout.delicity.focus();
			return false;
		}
		if(document.checkout.delistate.value == "" && document.checkout.delistate1.value == "" && document.checkout.chk_delistate.checked == false){
			alert("Please Select or Enter the State");
			document.checkout.delistate.focus();
			return false;
		}
		if(document.checkout.delicountry.value == ""){
			alert("Please Select the Country");
			document.checkout.delicountry.focus();
			return false;
		}
		if(document.checkout.delizip.value == "" && document.checkout.chk_delizip.checked == false){
			alert("Please Enter the Zipcode");
			document.checkout.delizip.focus();
			return false;
		}
		phone = document.checkout.deliphone;
		if (checkInternationalPhone(phone.value)==false)
		{
			alert("Please Enter a Valid Phone Number")
			phone.value=""
			phone.focus()
			return false
		}
		if (!validateEmail(document.checkout.deliemail.value,1,1)) 
		{
			document.checkout.deliemail.focus();
			return false;
		}
	}
}

var ShippingFname;
var ShippingLname;
var ShippingAddress;
var ShippingCity;
var ShippingState;
var ShippingState1;
var ShippingNoState;
var ShippingCountry;
var ShippingZip;
var ShippingNoZip;
var ShippingPhone;
var ShippingEmail;

function InitSaveVariables(form) {
		ShippingFname = form.fname.value;
		ShippingLname = form.lname.value;
		ShippingAddress = form.addr.value;
        ShippingCity = form.city.value;
		ShippingStateIndex = form.state.selectedIndex;
        ShippingState = form.state[ShippingStateIndex].value;
		ShippingState1 = form.state1.value;
		ShippingNoState = form.chk_state.checked;
		ShippingCountryIndex = form.country.selectedIndex;
		ShippingCountry = form.country[ShippingCountryIndex].value;
        ShippingZip = form.zip.value;
		ShippingNoZip = form.chk_zip.checked;
		ShippingPhone = form.phone.value;
		ShippingEmail = form.email.value;
}
function ShipToBillPerson(form) {
        if (form.chkDelivery.checked) {
                InitSaveVariables(form);
                form.delifname.value = form.fname.value;
                form.delilname.value = form.lname.value;
                form.deliaddr.value = form.addr.value;
                form.delicity.value = form.city.value;
                form.delistate.selectedIndex = form.state.selectedIndex;
				form.delistate1.value = form.state1.value;
				form.chk_delistate.checked = form.chk_state.checked;
                form.delicountry.selectedIndex = form.country.selectedIndex;
                form.delizip.value = form.zip.value;
				form.chk_delizip.checked = form.chk_zip.checked;
                form.deliphone.value = form.phone.value;
                form.deliemail.value = form.email.value;
			 }
       /* else {
                form.fname.value = ShippingFname;
                form.lname.value = ShippingLname;
                form.addr.value = ShippingAddress;
                form.city.value = ShippingCity;
                form.state.selectedIndex = ShippingState;
                form.country.selecIndex = ShippingCountry;
                form.zip.value = ShippingZip;
                form.phone.value = ShippingPhone;
                form.email.value = ShippingEmail;
			}*/
}

//Email Validation Script
function validateEmail(addr,man,db) {
	if (addr == '' && man) {
	   if (db) alert('Email address is mandatory');
	   return false;
	}
	var invalidChars = '\/\'\\ ";:?!()[]\{\}^|';
	for (i=0; i<invalidChars.length; i++) {
	   if (addr.indexOf(invalidChars.charAt(i),0) > -1) {
		  if (db) alert('Email address contains invalid characters');
		  return false;
	   }
	}
	for (i=0; i<addr.length; i++) {
	   if (addr.charCodeAt(i)>127) {
		  if (db) alert("Email address contains non ascii characters.");
		  return false;
	   }
	}
	var atPos = addr.indexOf('@',0);
	if (atPos == -1) {
	   if (db) alert('Email address must contain an @');
	   return false;
	}
	if (atPos == 0) {
	   if (db) alert('Email address must not start with @');
	   return false;
	}
	if (addr.indexOf('@', atPos + 1) > - 1) {
	   if (db) alert('Email address must contain only one @');
	   return false;
	}
	if (addr.indexOf('.', atPos) == -1) {
	   if (db) alert('Email address must contain a period in the domain name');
	   return false;
	}
	if (addr.indexOf('@.',0) != -1) {
	   if (db) alert('period must not immediately follow @ in email address');
	   return false;
	}
	if (addr.indexOf('.@',0) != -1){
	   if (db) alert('period must not immediately precede @ in email address');
	   return false;
	}
	if (addr.indexOf('..',0) != -1) {
	   if (db) alert('two periods must not be adjacent in email address');
	   return false;
	}
	var suffix = addr.substring(addr.lastIndexOf('.')+1);
	if (suffix.length != 2 && suffix != 'com' && suffix != 'net' && suffix != 'org' && suffix != 'edu' && suffix != 'int' && suffix != 'mil' && suffix != 'gov' & suffix != 'arpa' && suffix != 'biz' && suffix != 'aero' && suffix != 'name' && suffix != 'coop' && suffix != 'info' && suffix != 'pro' && suffix != 'museum') {
	   if (db) alert('invalid primary domain in email address');
	   return false;
	}
return true;
}

//Function phone validation Script
// Declaring required variables
var digits = "0123456789";
// non-digit characters which are allowed in phone numbers
var phoneNumberDelimiters = "()-. ";
// characters which are allowed in international phone numbers
// (a leading + is OK)
var validWorldPhoneChars = phoneNumberDelimiters + "+";
// Minimum no of digits in an international phone no.
var minDigitsInIPhoneNumber = 10;

function isInteger(s)
{   var i;
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag)
{   var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function checkInternationalPhone(strPhone){
s=stripCharsInBag(strPhone,validWorldPhoneChars);
return (isInteger(s) && s.length >= minDigitsInIPhoneNumber);
}

function contact_validate()
{
	if(document.frm_contact.name.value == "")
	{
		alert("Please Enter the Name");
		document.frm_contact.name.focus();
		return false;
	}
	if (!validateEmail(document.frm_contact.email.value,1,1)) 
	{
		document.frm_contact.email.focus();
		return false;
	}
	if(document.frm_contact.comment.value == "")
	{
		alert("Please Enter the Message");
		document.frm_contact.comment.focus();
		return false;
	}
}


function news_pop_validate()
{
	if(document.frm_newsltr.fname.value == "")
	{
		alert("Please Enter the First Name");
		document.frm_newsltr.fname.focus();
		return false;
	}
	if(document.frm_newsltr.lname.value == "")
	{
		alert("Please Enter the Last Name");
		document.frm_newsltr.lname.focus();
		return false;
	}
	if (!validateEmail(document.frm_newsltr.email.value,1,1)) 
	{
		document.frm_newsltr.email.focus();
		return false;
	}
}