/* submit.js */

/* this should really be renamed common.js */

checkTextLimits = function( data ) {
   //parse data { { 'text01', 1, 20 }, { 'text02', 2, 30 }, { 'text03', 2, 24|12 } }
   var truncated = false;
   for ( var i = 0; i < data.length; i++ ) {
       var el = document.getElementById( data[i][0] );
       var orgTxt = el.value;
       //trim trailing whitespace off lines of orgTxt
       var lines = orgTxt.split( '\n' );
       var orgAr = new Array();
       for ( var j = 0; j < lines.length; j++ ) {
          orgAr[j] = lines[j].replace( /\s+$/, '' );
       }
       orgTxt = orgAr.join( '\n' );
       el.value = limitText( el.name, el.value, data[i][1], data[i][2].toString().split( '|' ) );

       if ( orgTxt.toString().replace( /[\r\n]/g, '' ) != el.value.toString().replace( /[\r\n]/g, '' ) ) {
          el.focus();
          alert( 'All of your text did not fit. Please review it.' );
          return false;
       }
   }
   return true;
}

limitText = function( fld, txt, lc, ll ) {
  var lines = txt.split( '\n' );
  var txtAr = new Array();
  if ( ll.length > 1 ) {
     lim = lines.length < ll.length ? lines.length : ll.length;
     for ( var i = 0; i < lim; i++ ) {
        txtAr[i] = lines[i].substring( 0, ll[i] ).replace( /\s+$/, '' );
     }
  } else {
     lim = lines.length < lc ? lines.length : lc;
     for ( var i = 0; i < lim; i++ ) {
        txtAr[i] = lines[i].substring( 0, ll[0] ).replace( /\s+$/, '' );
     }
  }
  //reassemble text
  var nt = txtAr.join( '\n' );
  return nt;
}

testLimitsAdd = function( data ) {
   if ( ! checkTextLimits( data ) ) {
      setOrAddElement( 'theForm', 'natc', 'false' );
   }
   return true;
}

chkForm = function( data ) {
  if ( document.theForm.Quantity.value <= 0 ) {
    alert( 'Please choose a quantity.' );
    return false;
  }
  return testLimitsAdd( data );
}

function changePic( picName, imgName) {
   if ( document.images ) {
      document[picName].src= imgName;
   }
}

function changeText( id, newtext ) {
   document.getElementById(id).innerHTML=newtext
}

function changeLink( id, newlink ) {
   document.getElementById(id).href=newlink
}

function changeStock() {
   document.theForm.submit();
}

function Scale2 ( selectedScale )
{
  document.theForm.scale2.value = selectedScale ;
  document.theForm.submit() ;
}
function QuarkDocColor2 ( selectedQuarkDocColor )
{
  document.theForm.QuarkDocColor2.value = selectedQuarkDocColor ;
  document.theForm.submit() ;
}

function sendMessage( messageText ) {
  //this should be nicer than an alert.
  var messageElement = document.getElementById( 'sp_message' );
  if ( typeof document.body.style.maxHeight == "undefined" ) {
    document.getElementById( 'hideSelect' ).style.display = 'block';
  }
  if ( messageText == '' ) {
    messageElement.innerHTML = '';
    messageElement.style.padding = 0;
  } else {
    var msgHtml  = '<p style="text-align: center; padding: 20px;">' + messageText + '</p>';
       // msgHtml += '<p style="text-align: center; padding: 25px 10px;">';
       // msgHtml += '<input class="btn" type="button" value="OK" onclick="okMessage();" />';
       // msgHtml += '</p>';
    messageElement.innerHTML = msgHtml;
    messageElement.style.padding = '30px';
    messageElement.style.color   = '#990000';
  }
  messageElement.style.display = 'block';
  document.getElementById( 'sp_overlay' ).style.display = 'block';
  setTimeout( "okMessage()", 1900 );
}

function okMessage() {
  document.getElementById( 'sp_message' ).style.display = 'none';
  document.getElementById( 'sp_overlay' ).style.display = 'none';
  if ( document.getElementById( 'hideSelect' ) ) { document.getElementById( 'hideSelect' ).style.display = 'none'; }
}

function createInput( inName, inValue, inType ) {
  myInput = document.createElement( 'input' );
  myInput.setAttribute( "name",  inName );
  myInput.setAttribute( "value", inValue );
  myInput.setAttribute( "type",  inType );
  return myInput;
}

function setOrAddElement( inForm, inElement, inValue ) {
  var exists = false;
  for( var i = 0; i < document.forms.length; i++ ) {
    if ( document.forms[i].name == inForm ) {
      for ( var j = 0; j < document.forms[i].elements.length; j++ ) {
        if ( document.forms[i].elements[j].name == inElement ) {
          document.forms[i].elements[j].value = inValue;
          exists = true;
          break
        }
      }
      if ( !exists ) {
        document.forms[i].appendChild( createInput( inElement, inValue, 'hidden' ));
      }
    }
  }
}

function imageUpload( message_text ) {
  setOrAddElement( 'uploadFile', 'natc', 'false' );
  var umel = document.getElementById( 'uploadMessage' );
  if ( message_text == '' ) {
    umel.innerHTML = '';
    umel.style.padding = '0';
  } else {
    umel.innerHTML = message_text;
    umel.style.padding = '10px';
    umel.style.color = '#990000';
  }
  document.getElementById( 'sp_overlay' ).style.display = 'block';
  document.getElementById( 'sp_uploadImage' ).style.display = 'block';
  if ( typeof document.body.style.maxHeight == "undefined" ) {
    document.getElementById( 'hideSelect' ).style.display = 'block';
  }
  //transfer text fields from one form to the other
  var x = document.forms[0];

  for ( i = 0; i < x.elements.length; i++ ) {
    var xel = x.elements[i];

    var alreadyTransferred = false;

    var y = document.forms[1];

    if ( ( xel.type == 'text' ) || ( xel.type == 'textarea' ) || ( xel.type == 'hidden' ) ) {
      for( j = 0; j < y.elements.length; j++ ) {
        var yel = y.elements[j];
        if ( xel.name == yel.name ) {
           alreadyTransferred = true;
           yel.value = xel.value;
        }
      }

      if ( !alreadyTransferred ) {
         myInput = document.createElement( 'input' );
	       myInput.setAttribute( "name", xel.name );
	       myInput.setAttribute( "value", xel.value );
	       myInput.setAttribute( "type", "hidden" );
	       y.appendChild( myInput );
      }
    }
  }
}

function changeParam( parameter ) {
   document.getElementById( 'sp_overlay' ).style.display = 'block';
   document.getElementById( parameter ).style.display    = 'block';
   if ( typeof document.body.style.maxHeight == "undefined" ) {
    document.getElementById( 'hideSelect' ).style.display = 'block';
  }
}

function changeCancel( element ) {
   $( '.spPanel' ).css( 'display', 'none' );
}

function clearChoicePanes() {
   $( '.spPanel' ).css( 'display', 'none' );
}

function changeCharms( confirm ) {
   document.getElementById( 'sp_overlay' ).style.display = 'block';
   document.getElementById( 'sp_changeCharm' ).style.display = 'block';
   if ( confirm == 'false' ) {
      setOrAddElement( 'theForm', 'charm1Confirm', true );
   }
     if ( typeof document.body.style.maxHeight == "undefined" ) {
      document.getElementById( 'hideSelect' ).style.display = 'block';
   }
}

function selectCharm( charm ) {
   setOrAddElement( 'theForm', 'charm1', charm );
   setOrAddElement( 'theForm', 'charm1Confirm', true );
   document.theForm.submit();
}

function charmAlert() {
   document.getElementById( 'sp_overlay' ).style.display = 'block';
   document.getElementById( 'sp_charmAlert' ).style.display = 'block';
}

function charmAlertContinue( proceed, saveValue ) {
   if( proceed ){
      setOrAddElement( 'theForm', 'charm1Confirm', true );
      $( '#sp_charmAlert' ).css( 'display', 'none' );
      addToBasketConfirm( saveValue );
   }
   else {
      $( '#sp_charmAlert' ).css( 'display', 'none' );
      $( '.activeCharm' ).css( 'border', '1px dotted #666' );
      changeCharms( 'true' );
   }
}

function bigTextChange() {
  var bigText = document.getElementById( 'bigText' ).value;
  setOrAddElement( 'theForm', 'text12', bigText );
  document.theForm.submit();
}

function styleChange( qd, styleID ) {
  setOrAddElement( 'theForm', 'quarkDoc', qd );
  setOrAddElement( 'theForm', 'StyleID', styleID );
  setOrAddElement( 'theForm', 'changeStyle', '1' );
  //setOrAddElement( 'theForm', 'recenter', 'true' );
  document.theForm.submit();
}

function monogramChange( monogram ) {
  setOrAddElement( 'theForm', 'monogram', monogram );
  setAltMonoCheckBox();
  document.theForm.submit();
}

function fontChange( fontName ) {
  setOrAddElement( 'theForm', 'iconFont', fontName );
  document.theForm.submit();
}

function colorChange( qd, colorID ) {
  setOrAddElement( 'theForm', 'quarkDoc', qd );
  setOrAddElement( 'theForm', 'iconColor', colorID );
  document.theForm.submit();
}

function iconChange( artFile ) {
  setOrAddElement( 'theForm', 'iconArt', artFile );
  document.theForm.submit();
}

function shapeChange( qd, ShapeID ) {
  setOrAddElement( 'theForm', 'quarkDoc', qd );
  setOrAddElement( 'theForm', 'shapeID', ShapeID );
  setOrAddElement( 'theForm', 'recenter', 'true' );
  setOrAddElement( 'theForm', 'changeShape', '1' );
  document.theForm.submit();
}

function forceChangeColor() {
   setOrAddElement( 'theForm', 'showColor', '1' );
}

function imageUploadCancel() {
  $( '.spPanel' ).css( 'display', 'none' );
}

function imageUploadSubmit() {
  var imgUplQty = document.getElementById('Quantity').value;
  var imgUplT01posn = $('input:radio[name=T01posn]:checked').val();
  var imgStock = $('input:radio[name=stock]:checked').val();
  // imgStock is undefined when radio buttons are replaced with hidden input
  document.getElementById( 'sp_uploadImageMask' ).style.display = 'block';
  setOrAddElement( 'uploadFile', 'Quantity', imgUplQty );
  setOrAddElement( 'uploadFile', 'T01posn', imgUplT01posn );
  setOrAddElement( 'uploadFile', 'stock', imgStock );
  setOrAddElement( 'uploadFile', 'imageOption', 'A' );
  document.uploadFile.submit();
}

function imageChangeTo( imageFile ) {
  var imgUplQty = document.getElementById('Quantity').value;
  var imgUplT01posn = $('input:radio[name=T01posn]:checked').val();
  var imgStock = $('input:radio[name=stock]:checked').val();
  // imgStock is undefined when radio buttons are replaced with hidden input
  setOrAddElement( 'uploadFile', 'Quantity', imgUplQty );
  setOrAddElement( 'uploadFile', 'T01posn', imgUplT01posn );
  setOrAddElement( 'uploadFile', 'stock', imgStock );
  setOrAddElement( 'uploadFile', 'changeImage', imageFile );
  setOrAddElement( 'uploadFile', 'imageOption', 'A' );
  document.uploadFile.upload.value = "";
  document.uploadFile.submit();
}

function imageDelete( imageFile ) {
   setOrAddElement( 'uploadFile', 'deleteImage', imageFile );
   document.uploadFile.submit();
}

function addToBasketConfirm( saveValue ) {

   if ( saveValue == 'merchantSave' ) {
     setOrAddElement( 'theForm', 'saveChanges', 'true' );
	  setOrAddElement( 'theForm', 'merchantSave', 'true' );
	  document.theForm.submit();
   } else {
      //proceed through confirmation
	  if ( !checkTextLimits( allTextParams ) ) addToBasketCancel();

	   if ( document.theForm.Quantity.value != 0 ) {

		   var x = document.getElementById( "Quantity" );

		   xStr = x.options[x.selectedIndex].text;
		   xAr = xStr.split( ' ' );

		   qty = xAr[0];
		   amt = xAr[ xAr.length - 2];
		   //var shapeType = '';
		   var shapeSize = '';
		   var shapeName = '';

		   shapeSize = document.getElementsByName( 'confirmAddShapeSize' )[0].value;
		   shapeName = document.getElementsByName( 'confirmAddShapeName' )[0].value;

		   if ( shapeName.indexOf( '(without water)' ) > 0 ) {
			shapeName = 'bottled water labels <small>(without water)</small>';
		   }
		   else if ( shapeName.slice(-1) != 's' ){
			shapeName = shapeName + 's';
		   }

		   if ( document.getElementsByName( 'favorPack' )[0].value != '' ){
            if( document.getElementById( 'fpConfirmAmount' ) ){
               var fpShapeNameTxt = document.getElementsByName( 'fpShapeName' )[0].value;
               var fpConfirmAmountTxt = qty + ' ' + fpShapeNameTxt + 's' + ' &#8226; ' + amt;
               document.getElementById( 'fpConfirmAmount' ).innerHTML = fpConfirmAmountTxt;
               document.getElementById( 'fpBoxesQty' ).innerHTML = qty;
            }
            xStr = qty + ' ' + shapeName + ' &#8226; ' + shapeSize;
         }
		   else {
		      if ( shapeName.indexOf( '(without water)' ) > 0 ) {
		       xStr = qty + ' ' + shapeName + '<br />' + amt + ' &#8226; ' + shapeSize;
		      } else {
		       xStr = qty + ' ' + shapeName + ' &#8226; ' + amt + '<br />' + shapeSize;
		      }
		   }

		   confirmQTYStr = 'Your order is for ' + qty + ' ' + shapeName + '. ';

		   document.getElementById( 'confirmAmount' ).innerHTML     = xStr;
		   document.getElementById( 'sp_overlay' ).style.display    = 'block';
		   document.getElementById( 'sp_confirmAdd' ).style.display = 'block';

		   if ( document.getElementById( 'sp_confirmQTYmsg_amount' ) ){
		      document.getElementById( 'sp_confirmQTYmsg_amount' ).innerHTML = confirmQTYStr;
		   }
	      if ( typeof document.body.style.maxHeight === 'undefined' ) {
 			   document.getElementById( 'hideSelect' ).style.display = 'block';
 			}
			if ( document.theForm.saveValue ) {
			   document.theForm.saveValue.value = saveValue;
		   }
		} else {
			 alert('Please choose a quantity.');
		}
   }
}

function noImageNoAdd() {
  document.getElementById( 'sp_overlay' ).style.display = 'block';
  document.getElementById( 'sp_noImageNoAdd' ).style.display = 'block';
}

function noImageNoAddContinue() {
   document.getElementById( 'sp_overlay' ).style.display = 'none';
   document.getElementById( 'sp_noImageNoAdd' ).style.display = 'none';
   imageUpload('');
}

function noImageChoose() {
   $( 'input[name=imageOption]').val( 'B' );
   document.theForm.submit();
}

function addToBasketCancel() {
 if ( document.getElementById( 'layoutAccept' ) ) { document.getElementById( 'layoutAccept' ).checked = false; }
 if ( document.getElementById( 'prodAccept'   ) ) { document.getElementById( 'prodAccept'   ).checked = false; }
 $( '.spPanel' ).css( 'display', 'none' );
}

function addToBasketContinue() {
  var lay, pro, def, bgt;

  if ( document.getElementById( 'sp_confirmWarnLayout' ) ) document.getElementById( 'sp_confirmWarnLayout' ).innerHTML = '';
  if ( document.getElementById( 'sp_confirmWarnProd' ) ) document.getElementById( 'sp_confirmWarnProd' ).innerHTML = '';
  if ( document.getElementById( 'sp_confirmWarnDefault' ) ) document.getElementById( 'sp_confirmWarnDefault' ).innerHTML = '';
  if ( document.getElementById( 'sp_confirmWarnBT' ) ) document.getElementById( 'sp_confirmWarnBT' ).innerHTML = '';

  lay = document.getElementById( 'layoutAccept' ) ? document.getElementById( 'layoutAccept' ).checked : true;
  pro = document.getElementById( 'prodAccept' ) ? document.getElementById( 'prodAccept' ).checked : true;
  def = document.getElementById( 'defaultAccept' ) ? document.getElementById( 'defaultAccept' ).checked : true;
  bgt = document.getElementById( 'bigtextAccept' ) ? document.getElementById( 'bigtextAccept' ).checked : true;

  if ( ! ( lay && pro && def && bgt ) ) {
    document.getElementById( 'sp_confirmWarnMsg' ).innerHTML = 'Please check all boxes below to continue';
    if ( ! lay ) document.getElementById( 'sp_confirmWarnLayout' ).innerHTML = '>>>';
    if ( ! pro ) document.getElementById( 'sp_confirmWarnProd' ).innerHTML = '>>>';
    if ( ! def ) document.getElementById( 'sp_confirmWarnDefault' ).innerHTML = '>>>';
    if ( ! bgt ) document.getElementById( 'sp_confirmWarnBT' ).innerHTML = '>>>';
    return false;
	}
	saveValue = document.theForm.saveValue.value;
	if ( saveValue == 'save' ) {
		if ( document.theForm.saveChanges ) {
			document.theForm.removeChild( document.theForm.saveChanges );
		}
		myInput = document.createElement( 'input' );
		myInput.setAttribute( "name", saveValue );
		myInput.setAttribute( "type", "hidden" );
		document.theForm.appendChild( myInput );
    } else if ( saveValue == 'saveChanges' ) {
	    if ( document.theForm.save ) {
		    document.theForm.removeChild( document.theForm.save );
	    }
	    myInput = document.createElement( 'input' );
		myInput.setAttribute( "name", saveValue );
		myInput.setAttribute( "type", "hidden" );
		document.theForm.appendChild( myInput );
   } else if ( saveValue == 'add' ) {
      //probably do nothing
   } else {
	    //do nothing
   }

  if ( document.getElementById( 'instr_txtArea' ) && ( document.getElementById( 'instr_txtArea' ).value != '' ) ) {
     setOrAddElement( 'theForm', 'instructions', document.getElementById( 'instr_txtArea' ).value );
  }

	document.theForm.submit();
}

function basketCheckout() {
	myInput = document.createElement( 'input' );
	myInput.setAttribute( "name", "checkout" );
	myInput.setAttribute( "type", "hidden" );
	document.basketForm.appendChild( myInput );
	document.basketForm.PageContent.value = 15;
	document.basketForm.submit();
}

function checkContactForm() {
	var email_regex = new RegExp( "^[a-zA-Z0-9_+.]+@[a-zA-Z0-9_+.]+[.][a-zA-Z]{2,4}$" );

	 if ( document.contactForm.name.value == '' ) {
	     alert( 'Please enter a name!' );
	     document.contactForm.name.focus();
	     return false;
     }

     if ( ! email_regex.test( document.contactForm.email.value ) ) {
	     alert( 'Please enter a valid email address!' );
	     document.contactForm.email.focus();
         return false;
     }

     if ( document.contactForm.phone.value == '' ) {
	     alert( 'Please enter a phone number!' );
	     document.contactForm.phone.focus();
	     return false;
     }

     return true;
}

function checkJoinUsForm() {

	var email_regex = new RegExp( "^[a-zA-Z0-9_+.]+@[a-zA-Z0-9_+.]+[.][a-zA-Z]{2,4}$" );



	 if ( document.joinusform.company.value == '' ) {

	     alert( 'Please enter your company name' );

	     document.joinusform.company.focus();

	     return false;

     }


	 if ( document.joinusform.address1.value == '' ) {

	     alert( 'Please enter an address' );

	     document.joinusform.address1.focus();

	     return false;

     }


	 if ( document.joinusform.city.value == '' ) {

	     alert( 'Please enter a city' );

	     document.joinusform.city.focus();

	     return false;

     }


	 if ( document.joinusform.state.value == '' ) {

	     alert( 'Please select a state' );

	     document.joinusform.state.focus();

	     return false;

     }


	 if ( document.joinusform.zip.value == '' ) {

	     alert( 'Please enter a zip code' );

	     document.joinusform.zip.focus();

	     return false;

     }


	 if ( document.joinusform.website.value == '' ) {

	     alert( 'Please enter the URL to your website' );

	     document.joinusform.website.focus();

	     return false;

     }


	 if ( document.joinusform.contactFirstName.value == '' ) {

	     alert( 'Please enter a first name in the first name field' );

	     document.joinusform.contactFirstName.focus();

	     return false;

     }


	 if ( document.joinusform.contactLastName.value == '' ) {

	     alert( 'Please enter a last name in the first name field' );

	     document.joinusform.contactLastName.focus();

	     return false;

     }


	 if ( document.joinusform.phone.value == '' ) {

	     alert( 'Please enter your phone number' );

	     document.joinusform.phone.focus();

	     return false;

     }


     if ( ! email_regex.test( document.joinusform.email.value ) ) {

	     alert( 'Please enter a valid email address' );

	     document.joinusform.email.focus();

         return false;

     }

	 if ( document.joinusform.password1.value == '' ) {

	     alert( 'Please enter a password' );

	     document.joinusform.password1.focus();

	     return false;

     }

	 if ( document.joinusform.password2.value == '' ) {

	     alert( 'Please enter a confirmation password' );

	     document.joinusform.password2.focus();

	     return false;

     }

	 if ( document.joinusform.password1.value != document.joinusform.password2.value ) {

	     alert( 'Your password and confirmation password do not match' );

	     document.joinusform.password1.focus();

	     return false;

     }

	 if ( document.joinusform.terms.checked == false ) {

	     alert( 'You must read and agree to the terms and conditions before you may continue' );

	     document.joinusform.terms.focus();

	     return false;

     }

     var shiptype = '';
     for ( var i = 0; i < document.joinusform.shiptype.length; i++ ) {
	     if ( document.joinusform.shiptype[i].checked ) {
		     shiptype = document.joinusform.shiptype[i].value;
	     }
     }

     if ( shiptype == '' ) {

	     alert( 'You must select a shipping option' );

	     document.joinusform.shiptype[1].focus();

	     return false;
     }

     return true;

}

function openTOS() {
  document.getElementById( 'sp_uploadTerms' ).style.display = 'block';
  document.getElementById( 'sp_uploadImage' ).style.display.zIndex = 1;
  if( document.getElementById( 'sp_confirmAdd' ) ) { document.getElementById( 'sp_confirmAdd' ).style.zIndex = 1; }
}
function closeTOS() {
  document.getElementById( 'sp_uploadTerms' ).style.display = 'none';
  if( document.getElementById( 'sp_uploadImage' ) ) { document.getElementById( 'sp_uploadImage' ).style.zIndex = 999; }
  if( document.getElementById( 'sp_confirmAdd' ) ) { document.getElementById( 'sp_confirmAdd' ).style.zIndex = 999; }
}
function openIMAGETXT() {
  document.getElementById( 'sp_imagePrep' ).style.display = 'block';
  document.getElementById( 'sp_uploadImage' ).style.display = 'none';
}
function closeIMAGETXT() {
  document.getElementById( 'sp_imagePrep' ).style.display = 'none';
  document.getElementById( 'sp_uploadImage' ).style.display = 'block';
}

function setAltMonoCheckBox(){
  if( document.getElementById( 'mCheck' ) ){
   document.getElementById('mCheck').checked = 'true';
  }
}

function sp_confirmQTYmsg() {
 if( document.getElementById( 'sp_confirmQTYmsg' ) ){
  if( document.getElementById( 'layoutAccept' ).checked ){
   document.getElementById( 'sp_confirmQTYmsg' ).style.visibility = 'visible';}
  else {
   document.getElementById( 'sp_confirmQTYmsg' ).style.visibility = 'hidden';
  }
 }
}

function sp_confirmInstructions( newinstr ) {
   var instr = $('textarea[name="Instructions"]').val();
   var apprmsg = newinstr;
   var msgRE = new RegExp( apprmsg, 'i' );
   if ( ! msgRE.test( instr ) ){
    $('textarea[name="Instructions"]').val( apprmsg + '\n' + instr);
   };
}

function sp_qtySelectHTML( data ) {
   $( '#Quantity' ).html( data["HTML"] );
   $( '#priceEach' ).html( data["PRICEEACH"] );
   $( '#stockDescr' ).html( data["STOCKDESCR"] );
}

/* begin share link functions */
function storeSharedPreview( previewImageName, callback ) {
 var shareArgs = {};
 shareArgs[ "PREVIEWIMAGENAME" ] = previewImageName;
 shareArgs[ "PREVIEWIMAGEVERSION" ] = $( 'input[name=previewImageVersion]' ).val();
 $.post( '/ajax/storeSharedPreviewSP.cfm', shareArgs, callback, 'json' );
 }

function shareEmail( data ) {
  if( storePreviewAlert( data ) ) {
   changeParam( 'sp_shareEmail' );
  }
}

function storePreviewAlert( data ) {
 if( ! data["SUCCESS"] ) {
  sendMessage( data["STATUSMSG"] );
  return false;
 }
 else { return true; }
}

function shareEmailSend() {
 var json = {};
 $( '#shareEmailForm input' ).each( function(){
  json[ $( this ).attr( 'name' ) ] = $( this ).val();
 });
 json["seNote"] = $( '#seNote' ).val();
 json["sePreviewVersionID"] = $( 'input[name=previewImageVersion]' ).val();
 $.post( '/ajax/shareEmailSP.cfm', json, shareEmailAlert, 'json' );
}

function shareEmailAlert( data ) {
 $( '#shareEmailStatusERR' ).hide( 500 );
 $( '#shareEmailStatusOK' ).hide( 500 );
 if( data["STATUS"] == 'SENT' ) {
  $( '.seToggle' ).hide();
  $( '#shareEmailStatusOK' ).html( data["STATUSMSG"] );
  $( '#shareEmailStatusOK' ).show( 500 );
  $( '#seSendAgainBtns').show();
 }
 else {
  $( '#shareEmailStatusERR' ).html( data["STATUSMSG"] );
  $( '#shareEmailStatusERR' ).show( 500 );
 }
}

function shareEmailSendAgain() {
   $( 'input[name=seTo]' ).val('');
   $( '#shareEmailStatusERR' ).hide( 500 );
   $( '#shareEmailStatusOK' ).hide( 500 );
   $( '#seSendAgainBtns' ).hide( 500 );
   $( '.seToggle' ).show( 500 );
}

function shareFB( data ) {
 if( storePreviewAlert( data ) ) {
  var json = {};
  json["TYPE"] = 'F';
  json["SECTION"] = 'P';
  json["SHAPETYPE"] = $( 'input[name=seShapeType]' ).val();
  json["ITEMCODE"] = $( 'input[name=seItemCode]' ).val();
  json["NAVLINK"] = $( 'input[name=seNavLink]' ).val();
  json["PREVIEWVERSIONID"] = $( 'input[name=previewImageVersion]' ).val();
  $.post( '/ajax/shareH.cfm', json, shareFBcontinue, 'json' );
 }
 else {
   sendMessage( 'We\'re sorry, your preview image was not stored. Please click UPDATE TEXT and try again.' );
 }
}
function shareFBcontinue( data ) {
 if( data["STATUS"] != 'SUCCESS' ){
  sendMessage( 'We\'re sorry, your preview image was not stored. Please click UPDATE TEXT and try again.' );
 }
}

function openFBShare() {
 var previewversionID =  $( 'input[name=previewImageVersion]' ).val();
 if ( previewversionID != '' ) { 
  var fbShareURL = 'http://www.facebook.com/sharer/sharer.php?u=http://www.myownlabels.com/support/share.cfm?PreviewVersionID=' + previewversionID + '&Type=F';
  window.open( fbShareURL, 'winShareFBSP', 'status=1, height=500, width=650, resizable=0' );
 }
}
/* end share link functions */
