// Fading Effect Functions Start
var fadeDuration = 300;
function resetfade(degree)
{
        if (window.fadepictoview)
        {
            clearInterval(fadepictoview)
		}
        if (typeof piccontainerobj.style.MozOpacity=="string")
        {
        	piccontainerobj.style.MozOpacity=degree/100
		}
        else if (piccontainerobj.filters)
        {
            piccontainerobj.filters.alpha.opacity=degree
		}
		
}



function gradualfade()
{
        if (typeof piccontainerobj.style.MozOpacity=="string" && piccontainerobj.style.MozOpacity<1)
                piccontainerobj.style.MozOpacity=Math.min(parseFloat(piccontainerobj.style.MozOpacity)+0.2, 0.99)
        else if (piccontainerobj.filters && piccontainerobj.filters.alpha.opacity<100)
                piccontainerobj.filters.alpha.opacity+=20
        else //if not IE or Moz
                clearInterval(fadepictoview)
             
}

function showHideDiv(divID,act)
{
	if(act=="Show")
	{
		document.getElementById(divID).style.display="inline";
	}
	if(act=="Hide")
	{
		document.getElementById(divID).style.display="none";
	}
}
function copyBillingInfo()
{
	document.getElementById("shippingFirstName").value = document.getElementById("billingFirstName").value;
	document.getElementById("shippingLastName").value = document.getElementById("billingLastName").value;
	document.getElementById("shippingCompany").value = document.getElementById("billingCompany").value;
	document.getElementById("shippingTitle").value = document.getElementById("billingTitle").value;
	document.getElementById("shippingAddress1").value = document.getElementById("billingAddress1").value;
	document.getElementById("shippingAddress2").value = document.getElementById("billingAddress2").value;
	document.getElementById("shippingCity").value = document.getElementById("billingCity").value;
	document.getElementById("shippingState").selectedIndex = document.getElementById("billingState").selectedIndex;
	document.getElementById("shippingZip").value = document.getElementById("billingZip").value;
	document.getElementById("shippingCountry").selectedIndex = document.getElementById("billingCountry").selectedIndex;
	document.getElementById("shippingDayTimePhone").value = document.getElementById("billingDayTimePhone").value;
	document.getElementById("shippingEveningPhone").value = document.getElementById("billingEveningPhone").value;
	document.getElementById("shippingFax").value = document.getElementById("billingFax").value;
	
	if(document.getElementById("billingPreferredEmail").checked==true)
	{
		document.getElementById("shippingPreferredEmail").checked = true;
	}
	else if(document.getElementById("billingPreferredPhone").checked==true)
	{
		document.getElementById("shippingPreferredPhone").checked = true;
	}
	document.getElementById("shippingBestTimeToCall").selectedIndex = document.getElementById("billingBestTimeToCall").selectedIndex;
}

function check_credit_card_div()
{
	if(document.getElementById("billingPaymentTypeCreditCard").checked==true)
	{
		document.getElementById("payment_option").value="Creditcard";
		document.getElementById("credit_card_div").style.display="inline";
	}
	else if(document.getElementById("billingPaymentTypePaypal").checked==true)
	{
		document.getElementById("payment_option").value="Paypal";
		document.getElementById("credit_card_div").style.display="none";
	}
	else 
	{
		document.getElementById("payment_option").value="Check";
		document.getElementById("credit_card_div").style.display="none";
	}
}
function validateSelectState()
{
	if(document.getElementById("shippingCountry").selectedIndex<=0)
	{
		alert("Please select shipping Country");
		document.getElementById("shippingCountry").focus();
		return false;
	}
	else if(document.getElementById("shippingCountry").selectedIndex==1 && document.getElementById("shippingState").selectedIndex<=0)
	{
		alert("Please select shipping State");
		document.getElementById("shippingState").focus();
		return false;
	}
	else
	{
		return true;
	}
	
}
function validateCheckoutForm()
{
	if(trim(document.getElementById("billingFirstName").value)=="")
	{
		alert("Please provide your First Name");
		document.getElementById("billingFirstName").focus();
		return false;
	}
	else if(trim(document.getElementById("billingLastName").value)=="")
	{
		alert("Please provide your Last Name");
		document.getElementById("billingLastName").focus();
		return false;
	}
	else if(trim(document.getElementById("billingAddress1").value)=="")
	{
		alert("Please provide Address1");
		document.getElementById("billingAddress1").focus();
		return false;
	}
	else if(trim(document.getElementById("billingCity").value)=="")
	{
		alert("Please provide City Name");
		document.getElementById("billingCity").focus();
		return false;
	}
	else if(document.getElementById("billingCountry").selectedIndex<=0)
	{
		alert("Please select your Country");
		document.getElementById("billingCountry").focus();
		return false;
	}
	else if(((document.getElementById("billingCountry").options[document.getElementById("billingCountry").selectedIndex].text)=="U S A") && ((document.getElementById("billingState").selectedIndex)==0))
	{
		alert("Please select your State");
		document.getElementById("billingState").focus();
		return false;
	}
	else if(((document.getElementById("billingCountry").options[document.getElementById("billingCountry").selectedIndex].text)=="U S A") && (trim(document.getElementById("billingZip").value)==""))
	{
		alert("Please provide your zip");
		document.getElementById("billingZip").focus();
		return false;
	}
	else if(((document.getElementById("billingCountry").options[document.getElementById("billingCountry").selectedIndex].text)!="U S A") && (trim(document.getElementById("billingRegion").value)==""))
	{
		alert("Please provide your region");
		document.getElementById("billingRegion").focus();
		return false;
	}
	else if(trim(document.getElementById("billingDayTimePhone").value)=="")
	{
		alert("Please provide your day time phone number");
		document.getElementById("billingDayTimePhone").focus();
		return false;
	}
	else if(document.getElementById("customerType").value=="Walkin" && (trim(document.getElementById("customer_email").value)==""))
	{
		alert("Please provide your Email");
		document.getElementById("customer_email").focus();
		return false;
	}
	else if(document.getElementById("customerType").value=="Walkin" && (!echeck(document.getElementById("customer_email").value)))
	{
		alert("Please provide proper Email");
		document.getElementById("customer_email").focus();
		return false;
	}
	else if((document.getElementById("payment_option").value=="Creditcard")&& trim(document.getElementById("credit_card").value)=="")
	{
		alert("Please provide your credit card number");
		document.getElementById("credit_card").focus();
		return false;
	}
	else if((document.getElementById("payment_option").value=="Creditcard")&& (document.getElementById("exp_month").selectedIndex)<=0)
	{
		alert("Please select your credit card expiry month");
		document.getElementById("exp_month").focus();
		return false;
	}
	else if((document.getElementById("payment_option").value=="Creditcard")&& (document.getElementById("exp_year").selectedIndex)<=0)
	{
		alert("Please select your credit card expiry year");
		document.getElementById("exp_year").focus();
		return false;
	}
	else if((document.getElementById("payment_option").value=="Creditcard")&& trim(document.getElementById("credit_card_ccv").value)=="")
	{
		alert("Please provide your credit card security code");
		document.getElementById("credit_card_ccv").focus();
		return false;
	}
	else if(trim(document.getElementById("shippingFirstName").value)=="")
	{
		alert("Please provide your First Name");
		document.getElementById("shippingFirstName").focus();
		return false;
	}
	else if(trim(document.getElementById("shippingLastName").value)=="")
	{
		alert("Please provide your Last Name");
		document.getElementById("shippingLastName").focus();
		return false;
	}
	else if(document.getElementById("shippingCountry").selectedIndex<=0)
	{
		alert("Please select your Country");
		document.getElementById("shippingCountry").focus();
		return false;
	}
	else if(((document.getElementById("shippingCountry").options[document.getElementById("shippingCountry").selectedIndex].text)=="U S A") && ((document.getElementById("shippingState").selectedIndex)==0))
	{
		alert("Please select your State");
		document.getElementById("shippingState").focus();
		return false;
	}
	else if(((document.getElementById("shippingCountry").options[document.getElementById("shippingCountry").selectedIndex].text)=="U S A") && (trim(document.getElementById("shippingZip").value)==""))
	{
		alert("Please provide your Zip Code");
		document.getElementById("shippingZip").focus();
		return false;
	}
	else if(((document.getElementById("shippingCountry").options[document.getElementById("shippingCountry").selectedIndex].text)!="U S A") && (trim(document.getElementById("shippingRegion").value)=="") )
	{
		alert("Please provide your Region");
		document.getElementById("shippingRegion").focus();
		return false;
	}
	else if((trim(document.getElementById("shippingDayTimePhone").value)==""))
	{
		alert("Please provide your phone");
		document.getElementById("shippingDayTimePhone").focus();
		return false;
	}
	else
	{
		return true;
	}
}
function confirmDelete(itemID)
{
	var ans = confirm("Are you sure you want to delete this item from your cart?");
	if(ans==true)
	{
		document.getElementById("deleteItem").value = itemID;
		document.cartForm.submit();
	}
}
function validateloginCredentialsForm()
{
	if(trim(document.getElementById("Email").value)=="")
	{
		alert("Please provide your Email");
		document.getElementById("Email").focus();
		return false;
	}
	else if(!echeck(document.getElementById("Email").value))
	{
		alert("Please provide proper Email");
		document.getElementById("Email").focus();
		return false;
	}
	else if(trim(document.getElementById("OldPassword").value)=="")
	{
		alert("Please provide Current Password");
		document.getElementById("OldPassword").focus();
		return false;
	}
	else if(trim(document.getElementById("NewPassword").value)=="")
	{
		alert("Please provide New Password");
		document.getElementById("NewPassword").focus();
		return false;
	}
	else if((document.getElementById("NewPassword").value)!=(document.getElementById("ConfirmPassword").value))
	{
		alert("Both Password do not match");
		document.getElementById("ConfirmPassword").focus();
		return false;
	}
	else if((document.getElementById("SecurityQuestion").selectedIndex)==0)
	{
		alert("Please select Security Question");
		document.getElementById("SecurityQuestion").focus();
		return false;
	}
	else if(trim(document.getElementById("SecurityAnswer").value)=="")
	{
		alert("Please provide Security Answer");
		document.getElementById("SecurityAnswer").focus();
		return false;
	}
	else
	{
		return true;
	}
}
function validateBillingInfoForm()
{
	if(trim(document.getElementById("FirstName").value)=="")
	{
		alert("Please provide your First Name");
		document.getElementById("FirstName").focus();
		return false;
	}
	else if(trim(document.getElementById("LastName").value)=="")
	{
		alert("Please provide your Last Name");
		document.getElementById("LastName").focus();
		return false;
	}
	else if(((document.getElementById("Country").options[document.getElementById("Country").selectedIndex].text)=="U S A") && ((document.getElementById("State").selectedIndex)==0))
	{
		alert("Please select your State");
		document.getElementById("State").focus();
		return false;
	}
	else if(((document.getElementById("Country").options[document.getElementById("Country").selectedIndex].text)=="U S A") && (trim(document.getElementById("Zip").value)==""))
	{
		alert("Please provide your Zip Code");
		document.getElementById("Zip").focus();
		return false;
	}
	
	else if((document.getElementById("Country").selectedIndex)<=0)
	{
		alert("Please select your country");
		document.getElementById("Country").focus();
		return false;
	}
	else
	{
		return true;
	}
}

function validateCreateAccountForm()
{
	if(trim(document.getElementById("FirstName").value)=="")
	{
		alert("Please provide your First Name");
		document.getElementById("FirstName").focus();
		return false;
	}
	else if(trim(document.getElementById("LastName").value)=="")
	{
		alert("Please provide your Last Name");
		document.getElementById("LastName").focus();
		return false;
	}
	else if(trim(document.getElementById("Email").value)=="")
	{
		alert("Please provide your Email");
		document.getElementById("Email").focus();
		return false;
	}
	else if(!echeck(document.getElementById("Email").value))
	{
		alert("Please provide proper Email");
		document.getElementById("Email").focus();
		return false;
	}
	else if(trim(document.getElementById("Password").value)=="")
	{
		alert("Please provide Password");
		document.getElementById("Password").focus();
		return false;
	}
	else if((document.getElementById("Password").value)!=(document.getElementById("ConfirmPassword").value))
	{
		alert("Both Password do not match");
		document.getElementById("ConfirmPassword").focus();
		return false;
	}
	else if((document.getElementById("SecurityQuestion").selectedIndex)==0)
	{
		alert("Please select Security Question");
		document.getElementById("SecurityQuestion").focus();
		return false;
	}
	else if(trim(document.getElementById("SecurityAnswer").value)=="")
	{
		alert("Please provide Security Answer");
		document.getElementById("SecurityAnswer").focus();
		return false;
	}
	else
	{
		return true;
	}
}
function validateSignInForm()
{
	if(trim(document.getElementById("LoginEmail").value)=="")
	{
		alert("Please provide your Email");
		document.getElementById("LoginEmail").focus();
		return false;
	}
	else if(!echeck(document.getElementById("LoginEmail").value))
	{
		alert("Please provide proper Email");
		document.getElementById("LoginEmail").focus();
		return false;
	}
	else if(trim(document.getElementById("LoginPassword").value)=="")
	{
		alert("Please provide Password");
		document.getElementById("LoginPassword").focus();
		return false;
	}
	else
	{
		return true;
	}
}
function removeLastRow()
{
	document.getElementById("action").value="removeRow";
	document.wantsForm.submit();
}
function addNewRow()
{
	document.getElementById("action").value="addNewRow";
	document.wantsForm.submit();
}
function validateWantsForm()
{
	if(trim(document.getElementById("FirstName").value)=="")
	{
		alert("Please provide your First Name");
		document.getElementById("FirstName").focus();
		return false;
	}
	else if(trim(document.getElementById("LastName").value)=="")
	{
		alert("Please provide your Last Name");
		document.getElementById("LastName").focus();
		return false;
	}
	else if(((document.getElementById("Country").options[document.getElementById("Country").selectedIndex].text)=="U S A") && ((document.getElementById("State").selectedIndex)==0))
	{
		alert("Please select your State");
		document.getElementById("State").focus();
		return false;
	}
	else if(((document.getElementById("Country").options[document.getElementById("Country").selectedIndex].text)=="U S A") && (trim(document.getElementById("Zip").value)==""))
	{
		alert("Please provide your Zip Code");
		document.getElementById("Zip").focus();
		return false;
	}

	else if(trim(document.getElementById("Email").value)=="")
	{
		alert("Please provide your Email");
		document.getElementById("Email").focus();
		return false;
	}
	else if(!echeck(document.getElementById("Email").value))
	{
		alert("Please provide proper Email");
		document.getElementById("Email").focus();
		return false;
	}
	else
	{
		return true;
	}
}
function validateContactPrintsWeBuyForm()
{
	if(trim(document.getElementById("FirstName").value)=="")
	{
		alert("Please provide your First Name");
		document.getElementById("FirstName").focus();
		return false;
	}
	else if(trim(document.getElementById("LastName").value)=="")
	{
		alert("Please provide your Last Name");
		document.getElementById("LastName").focus();
		return false;
	}
	else if(((document.getElementById("Country").options[document.getElementById("Country").selectedIndex].text)=="U S A") && ((document.getElementById("State").selectedIndex)==0))
	{
		alert("Please select your State");
		document.getElementById("State").focus();
		return false;
	}
	else if(((document.getElementById("Country").options[document.getElementById("Country").selectedIndex].text)=="U S A") && (trim(document.getElementById("Zip").value)==""))
	{
		alert("Please provide your Zip Code");
		document.getElementById("Zip").focus();
		return false;
	}
	
	else if(trim(document.getElementById("Email").value)=="")
	{
		alert("Please provide your Email");
		document.getElementById("Email").focus();
		return false;
	}
	else if(!echeck(document.getElementById("Email").value))
	{
		alert("Please provide proper Email");
		document.getElementById("Email").focus();
		return false;
	}
	else
	{
		return true;
	}
}
function validateContactUsForm()
{
	if(trim(document.getElementById("FirstName").value)=="")
	{
		alert("Please provide your First Name");
		document.getElementById("FirstName").focus();
		return false;
	}
	else if(trim(document.getElementById("LastName").value)=="")
	{
		alert("Please provide your Last Name");
		document.getElementById("LastName").focus();
		return false;
	}
	else if(((document.getElementById("Country").options[document.getElementById("Country").selectedIndex].text)=="U S A") && ((document.getElementById("State").selectedIndex)==0))
	{
		alert("Please select your State");
		document.getElementById("State").focus();
		return false;
	}
	else if(((document.getElementById("Country").options[document.getElementById("Country").selectedIndex].text)=="U S A") && (trim(document.getElementById("Zip").value)==""))
	{
		alert("Please provide your Zip Code");
		document.getElementById("Zip").focus();
		return false;
	}

	else if(trim(document.getElementById("Email").value)=="")
	{
		alert("Please provide your Email");
		document.getElementById("Email").focus();
		return false;
	}
	else if(!echeck(document.getElementById("Email").value))
	{
		alert("Please provide proper Email");
		document.getElementById("Email").focus();
		return false;
	}
	else
	{
		return true;
	}
}
function showSRDiv()
{
	document.getElementById("image_gallery").src="images/image_gallery_active.gif";
	document.getElementById("image_biography").src="images/biography.gif";
	document.getElementById("biography").style.display="none";
	document.getElementById("searchResults").style.display="inline";
	document.getElementById("pageDiv").style.display="inline";
	document.getElementById("pageDiv2").style.display="inline";
	document.getElementById("paginationDiv").style.display="inline";
}
function showBioDiv()
{
	document.getElementById("image_gallery").src="images/image_gallery.gif";
	document.getElementById("image_biography").src="images/biography_active.gif";
	document.getElementById("biography").style.display="inline";
	document.getElementById("searchResults").style.display="none";
	document.getElementById("pageDiv").style.display="none";
	document.getElementById("pageDiv2").style.display="none";
	document.getElementById("paginationDiv").style.display="none";
}
function validateJoinMailingList(source)
{
	if(source=="rightPanel")
	{
		if(trim(document.getElementById("joinMailingList").value)=="")
		{
			alert("Please provide your Email Address");
			return false;
		}
		else if(!echeck(document.getElementById("joinMailingList").value))
		{
			alert("Please provide proper Email Address");
			return false;
		}
		else
		{
			return true;
		}
	}
	if(source=="homePage")
	{
		if(trim(document.getElementById("joinMailingListHP").value)=="")
		{
			alert("Please provide your Email Address");
			return false;
		}
		else if(!echeck(document.getElementById("joinMailingListHP").value))
		{
			alert("Please provide proper Email Address");
			return false;
		}
		else
		{
			return true;
		}
	}
}

function IsNumeric(sText)
{
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;

 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
   
}

function validateSearchForm()
{
	if((document.getElementById("searchByArtist").selectedIndex==0) && (document.getElementById("searchArchives").selectedIndex==0))
	{
		alert("Please select Artist");
		return false;
	}
	else if((document.getElementById("searchByArtist").selectedIndex>0) && (document.getElementById("searchArchives").selectedIndex>0))
	{
		
		return false;
	}
	else
	{
		return true;
	}
}
function trim(stringToTrim)
{
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}

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){
     return false;
  }
  if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
     return false;
  }
  if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
      return false;
  }
   if (str.indexOf(at,(lat+1))!=-1){
      return false;
   }
   if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
      return false;
   }
   if (str.indexOf(dot,(lat+2))==-1){
      return false;
   }
   if (str.indexOf(" ")!=-1){
      return false;
   }
   return true;          
}

$(function(){
	$('#swfupload-control').swfupload({
		upload_url: "upload-file.php",
		file_post_name: 'uploadfile',
		file_size_limit : "1024",
		file_types : "*.jpg;*.png;*.gif",
		file_types_description : "Image files",
		file_upload_limit : 5,
		flash_url : "js/swfupload/swfupload.swf",
		button_image_url : 'js/swfupload/wdp_buttons_upload_114x29.png',
		button_width : 114,
		button_height : 29,
		button_placeholder : $('#button')[0],
		debug: false
	})
		.bind('fileQueued', function(event, file){
			var listitem='<li id="'+file.id+'" >'+
				'File: <em>'+file.name+'</em> ('+Math.round(file.size/1024)+' KB) <span class="progressvalue" ></span>'+
				'<div class="progressbar" ><div class="progress" ></div></div>'+
				'<p class="status" >Pending</p>'+
				'<span class="cancel" >&nbsp;</span>'+
				'</li><input type="hidden" name="FileName'+file.id+'" id="FileName'+file.id+'" value="'+file.name+'">';
			$('#log').append(listitem);
			$('li#'+file.id+' .cancel').bind('click', function(){
				var swfu = $.swfupload.getInstance('#swfupload-control');
				swfu.cancelUpload(file.id);
				$('li#'+file.id).slideUp('fast');
			});
			// start the upload since it's queued
			$(this).swfupload('startUpload');
		})
		.bind('fileQueueError', function(event, file, errorCode, message){
			alert('Size of the file '+file.name+' is greater than limit');
		})
		.bind('fileDialogComplete', function(event, numFilesSelected, numFilesQueued){
			$('#queuestatus').text('');
		})
		.bind('uploadStart', function(event, file){
			$('#log li#'+file.id).find('p.status').text('Uploading...');
			$('#log li#'+file.id).find('span.progressvalue').text('0%');
			$('#log li#'+file.id).find('span.cancel').hide();
		})
		.bind('uploadProgress', function(event, file, bytesLoaded){
			//Show Progress
			var percentage=Math.round((bytesLoaded/file.size)*100);
			$('#log li#'+file.id).find('div.progress').css('width', percentage+'%');
			$('#log li#'+file.id).find('span.progressvalue').text(percentage+'%');
		})
		.bind('uploadSuccess', function(event, file, serverData){
			var item=$('#log li#'+file.id);
			item.find('div.progress').css('width', '100%');
			item.find('span.progressvalue').text('100%');
			var pathtofile='<a href="uploads/'+file.name+'" target="_blank" >view &raquo;</a>';
			item.addClass('success').find('p.status').html('Done!!! | '+pathtofile);
		})
		.bind('uploadComplete', function(event, file){
			// upload has completed, try the next one in the queue
			$(this).swfupload('startUpload');
		})
	
});	