//CC date validation
//javascript functions
function setDate() {
	
	var dt = new Date();
	dt = addMonth(dt,1);
	document.CreateRPProfileForm.profileStartDateDay.options[dt.getDate()-1].selected = true;
	document.CreateRPProfileForm.profileStartDateMonth.options[dt.getMonth()].selected = true;
	for(index=0; index<document.CreateRPProfileForm.profileStartDateYear.options.length;index++)
	{
		if(document.CreateRPProfileForm.profileStartDateYear.options[index].value == dt.getFullYear())
		{
			document.CreateRPProfileForm.profileStartDateYear.options[index].selected = true;
			break;
		}
	}
	
}
function addMonth(d,month){
	 t  = new Date (d);
	  t.setMonth(d.getMonth()+ month) ;
	  if (t.getDate() < d.getDate())
	 	{
	      t.setDate(0);
	  	}
	  return t;
}  


//signup page subdomain availability checker
$(document).ready(function() {
	$('#subdomainLoading').hide();
	$('#emailLoading').hide();
	$('#cardLoading').hide();
	$('#uploadingimage').hide();
	
	$('#subdomain').blur(function(){
	  $('#subdomainLoading').show();
      $.post(siteurl+"/processors/check-subdomain.php", {
        subdomain: $('#subdomain').val()
      }, function(response){
        $('#subdomainResult').fadeOut();
        setTimeout("finishAjax('subdomainLoading', 'subdomainResult', '"+escape(response)+"')", 400);
      });
    	return false;
	});
	
	$('#cardNum').blur(function(){
		  $('#cardLoading').show();
	      $.post(siteurl+"/processors/cc.php", {
	        cardNum: $('#cardNum').val(),
	        cardType: $('#cardType').val()
	      }, function(response){
	        $('#cardResult').fadeOut();
	        setTimeout("finishAjax('cardLoading', 'cardResult', '"+escape(response)+"')", 400);
	      });
	    	return false;
		});
	
	//function for checking existing email account in system
	$('#email').blur(function(){
	  $('#emailLoading').show();
      $.post(siteurl+"/processors/check-email.php", {
        email: $('#email').val()
      }, function(response){
        $('#emailResult').fadeOut();
        setTimeout("finishAjax('emailLoading', 'emailResult', '"+escape(response)+"')", 400);
      });
    	return false;
	});
	
	//function for photograph uploads
	//$('#photograph-upload-button').live('click', function() {
	$("#photograph-upload-button").click(function() {
		$('#uploadingimage').show();
		var filename = $('form#filename').val();
		var pieceID = $('form#pieceID').val();
		var maxSize = $('form#maxSize').val();
		var maxW = $('form#maxW').val();
		var maxH = $('form#maxH').val();
		var fullPath = $('form#fullPath').val();
		var relPath = $('form#relPath').val();
		var colorR = $('form#colorR').val();
		var colorG = $('form#colorG').val();
		var colorB = $('form#colorB').val();
		var pic_description = $('form#pic_description').val();
		var pic_name = $('form#pic_name').val();
		var iframe = $( '<iframe name="postframe" id="postframe" class="hidden" src="about:none" style="border: 0px; width: 900px; font: 100%  Verdana, Helvetica, sans-serif;""/>' );
		$('div#iframe').append( iframe );

		$('#photo-form').attr( "action", siteurl+"/account/processors/ajaxupload.php" ),
		$('#photo-form').attr( "method", "post" ),
		$('#photo-form').attr( "filename", filename ),
		$('#photo-form').attr( "pieceID", pieceID ),
		$('#photo-form').attr( "maxH", maxH ),
		$('#photo-form').attr( "maxW", maxW ),
		$('#photo-form').attr( "fullPath", fullPath ),
		$('#photo-form').attr( "relPath", relPath ),
		$('#photo-form').attr( "colorR", colorR ),
		$('#photo-form').attr( "colorG", colorG ),
		$('#photo-form').attr( "colorB", colorB ),		
		$('#photo-form').attr( "pic_description", pic_description ),
		$('#photo-form').attr( "pic_name", pic_name ),
		$('#photo-form').attr( "enctype", "multipart/form-data" ),
		$('#photo-form').attr( "encoding", "multipart/form-data" ),
		$('#photo-form').attr( "target", "postframe" ),
		$('#photo-form').submit();
		//need to get contents of the iframe
		$("#postframe").load(
			function(){
				iframeContents = $("iframe")[0].contentDocument.body.innerHTML;
				//$("div#upload_area").html(iframeContents);
				$('#uploadingimage').hide();
				setTimeout(function() {
		            var path = window.location.href;
		            window.location = path;
		          },1000); 
			}
		);
		return false;
	});
	
	
	});



function finishAjax(lddivid,id,response) {
  $('#'+lddivid).hide();
  $('#'+id).html(unescape(response));
  $('#'+id).fadeIn();
} //finishAjax


//Lightbox JQuery
$(function() {
	// Use this example, or...
	//$('a[@rel*=lightbox]').lightBox(); // Select all links that contains lightbox in the attribute rel
	// This, or...
	$('#piece-pic a').lightBox(); // Select all links in object with gallery ID
	// This, or...
	//$('a.lightbox').lightBox(); // Select all links with lightbox class
	// This, or...
	//$('a').lightBox(); // Select all links in the page
	// ... The possibility are many. Use your creative or choose one in the examples above
});

//Search script for pieces
$(function() 
		{
				$('input#filter-pieces').quicksearch('table#pieces-listing tbody tr');
		});

//calendar and divs
    $(function()
    		{
    			$('.date-pick').datePicker({startDate:'01/01/1900'});
    		});

//Divs for add and edit piece screens
animatedcollapse.addDiv('new-photo-form', 'fade=1')
animatedcollapse.addDiv('delete-photo-form_1', 'fade=1')
animatedcollapse.addDiv('delete-photo-form_2', 'fade=1')
animatedcollapse.addDiv('delete-photo-form_3', 'fade=1')
animatedcollapse.addDiv('delete-photo-form_4', 'fade=1')
animatedcollapse.addDiv('delete-photo-form_5', 'fade=1')
animatedcollapse.addDiv('delete-photo-form_6', 'fade=1')
animatedcollapse.addDiv('delete-photo-form_7', 'fade=1')
animatedcollapse.addDiv('delete-photo-form_8', 'fade=1')
animatedcollapse.addDiv('delete-photo-form_9', 'fade=1')
animatedcollapse.addDiv('delete-photo-form_10', 'fade=1')
animatedcollapse.addDiv('delete-photo-form_11', 'fade=1')
animatedcollapse.addDiv('delete-photo-form_12', 'fade=1')
animatedcollapse.addDiv('delete-photo-form_13', 'fade=1')
animatedcollapse.addDiv('delete-photo-form_14', 'fade=1')
animatedcollapse.addDiv('delete-photo-form_15', 'fade=1')
animatedcollapse.addDiv('delete-photo-form_16', 'fade=1')
animatedcollapse.addDiv('delete-photo-form_17', 'fade=1')
animatedcollapse.addDiv('delete-photo-form_18', 'fade=1')
animatedcollapse.addDiv('delete-photo-form_19', 'fade=1')
animatedcollapse.addDiv('delete-photo-form_20', 'fade=1')
animatedcollapse.addDiv('delete-photo-form_21', 'fade=1')
animatedcollapse.addDiv('delete-photo-form_22', 'fade=1')
animatedcollapse.addDiv('delete-photo-form_23', 'fade=1')
animatedcollapse.addDiv('delete-photo-form_24', 'fade=1')
animatedcollapse.addDiv('delete-photo-form_25', 'fade=1')
animatedcollapse.addDiv('edit-photo-form_1', 'fade=1')
animatedcollapse.addDiv('edit-photo-form_2', 'fade=1')
animatedcollapse.addDiv('edit-photo-form_3', 'fade=1')
animatedcollapse.addDiv('edit-photo-form_4', 'fade=1')
animatedcollapse.addDiv('edit-photo-form_5', 'fade=1')
animatedcollapse.addDiv('edit-photo-form_6', 'fade=1')
animatedcollapse.addDiv('edit-photo-form_7', 'fade=1')
animatedcollapse.addDiv('edit-photo-form_8', 'fade=1')
animatedcollapse.addDiv('edit-photo-form_9', 'fade=1')
animatedcollapse.addDiv('edit-photo-form_10', 'fade=1')
animatedcollapse.addDiv('edit-photo-form_11', 'fade=1')
animatedcollapse.addDiv('edit-photo-form_12', 'fade=1')
animatedcollapse.addDiv('edit-photo-form_13', 'fade=1')
animatedcollapse.addDiv('edit-photo-form_14', 'fade=1')
animatedcollapse.addDiv('edit-photo-form_15', 'fade=1')
animatedcollapse.addDiv('edit-photo-form_16', 'fade=1')
animatedcollapse.addDiv('edit-photo-form_17', 'fade=1')
animatedcollapse.addDiv('edit-photo-form_18', 'fade=1')
animatedcollapse.addDiv('edit-photo-form_19', 'fade=1')
animatedcollapse.addDiv('edit-photo-form_20', 'fade=1')
animatedcollapse.addDiv('edit-photo-form_21', 'fade=1')
animatedcollapse.addDiv('edit-photo-form_22', 'fade=1')
animatedcollapse.addDiv('edit-photo-form_23', 'fade=1')
animatedcollapse.addDiv('edit-photo-form_24', 'fade=1')
animatedcollapse.addDiv('edit-photo-form_25', 'fade=1')

//Divs for pieces screen
animatedcollapse.addDiv('add-piece-name', 'fade=1')
animatedcollapse.addDiv('add-insurance-policy', 'fade=1')
animatedcollapse.addDiv('add-artist', 'fade=1')
animatedcollapse.addDiv('add-type', 'fade=1')
animatedcollapse.addDiv('add-technique', 'fade=1')
animatedcollapse.addDiv('add-material', 'fade=1')
animatedcollapse.addDiv('add-dynasty', 'fade=1')

//Div for search screen on user galleries
animatedcollapse.addDiv('advanced-search-options', 'fade=1')

//Divs for collection screen
animatedcollapse.addDiv('collection-add', 'fade=1')
animatedcollapse.ontoggle=function($, divobj, state){ //fires each time a DIV is expanded/contracted
	//$: Access to jQuery
	//divobj: DOM reference to DIV being expanded/ collapsed. Use "divobj.id" to get its ID
	//state: "block" or "none", depending on state
}
animatedcollapse.init()
