
var loc=String(window.location);$(document).ready(function(){showLikePhrase();$("#submitcomment").click(function(){if($("#comment").val()){getFBLoginStatus();}
else{alert("Please add a comment");}});$("#fblike").click(function(){likeProd();});$("#submit_account").click(function(){createNewAcct();});$('#username').blur(function(){if($('#username').val()){doesUsernameExist();}});$('#confirm').blur(function(){if(!passMatch()){$("#password_msg").html("Please confirm your password correctly.");}
else{$("#password_msg").html("");}});$('#email').blur(function(){if($('#email').val()){if(!isValidEmail($('#email').val())){$("#email_msg").html("Please enter a valid email address");}
else{doesEmailExist();}}});$("#loggedinFB").click(function(){fillInFields();});});window.fbAsyncInit=function(){if(loc.search(/dev/i)!=-1){FB.init({appId:'cb820f3d16fbe59069bdd59cbf0195a6',status:true,cookie:true,xfbml:true});}
else{FB.init({appId:'1caff1cd98992d76723eff6b8cc06704',status:true,cookie:true,xfbml:true});}
showLastComment();FB.Event.subscribe('auth.login',function(response){if(loc.search(/accounts/i)!=-1){fillInFields();}});if(loc.search(/accounts/i)!=-1){FB.getLoginStatus(function(response){hideBothButtons();if(response.session){$("#createfbacctbutton").show();}
else{$("#fbloginbutton").show();}});}};(function(){var e=document.createElement('script');e.type='text/javascript';e.src=document.location.protocol+'//connect.facebook.net/en_US/all.js';e.async=true;document.getElementById('fb-root').appendChild(e);}());function fillInFields(){FB.api('/me',function(response){clearMsgs();$("#username").val(response.first_name);$("#email").val(response.email);$("#password_section").hide();$("#fb_uid").val(response.id);hideBothButtons();});}
function hideBothButtons(){$("#createfbacctbutton").hide();$("#fbloginbutton").hide();}
function showLastComment(){$.post(dev+"fb_callback.php",{getLastComments:1,pid:$("#pid").val()},function(data){if(data.msg=="success"){var all_comments="";for(i=0;i<data.comments.length;i++){all_comments=all_comments
+"<div style=\"margin-top:10px;padding-left:10px;\" class=\"showcomment\">"
+"<p><b style=\"display:none;\" id='comment"+i+"'>"
+getFirstName(data.comments[i]['uid'],i)
+"</b> says<br />"
+data.comments[i]['comment']
+"</p><div class=\"clear\"></div></div>";}
$("#showallcomments").html(all_comments);}},"json");}
function getFirstName(uid,count){FB.api('/'+uid,function(response){$("#comment"+count).html(response.first_name)
$("#comment"+count).show();});}
function submitToDB(){FB.api('/me',function(response){$.post(dev+"fb_callback.php",{submit_comment:1,uid:response.id,comment:$("#comment").val(),pid:$("#pid").val()},function(data){if(data.msg!="success"){alert("Oops -- sorry!  We did not receive your comment.  Please try submitting again");}
else{showLastComment();clearInputs();}},"json");});}
function clearInputs(){$("#comment").val("");$('#share').attr('checked',false);}
function submitContent(){submitToDB();if($('#share').attr('checked')){var plink=""+window.location;postToWall("Designer: "+$('#designer').html()
+", Available at "+$(".popup strong").text(),plink,"http://static.shinyorb.com/"+$("#smallimg").val());}}
function getFBLoginStatus(){FB.getLoginStatus(function(response){if(response.session){$("#fbbutton").hide();submitContent();}
else{_gaq.push(['_trackEvent','productPage','/product/fbloginshow']);$("#fbbutton").show();promptFBLogin();}});}
function promptFBLogin(){FB.Event.subscribe('auth.login',function(response){_gaq.push(['_trackEvent','productPage','/product/fblogincomplete']);$("#fbbutton").hide();submitContent();});}
function postToWall(details,plink,pimg){FB.api('/me',function(response){username=response.first_name+" likes this dress.  Can you find a better one?";plink=plink+"?h="+response.id;FB.api('/me/feed','post',{message:$("#comment").val(),name:username,caption:"www.shinyorb.com",description:(details),link:plink,picture:pimg},function(response){if(!response||response.error){alert('Oops -- sorry!  This dress could not be shared on Facebook');}
else{clearInputs();}});});}
function likeProd(){if(getCookie("loveit")){if(!alreadyLovedIt($("#pid").val())){addToLoveIt($("#pid").val());}}
else{addToLoveIt($("#pid").val());}}
function addToLoveIt(pid){$.post(dev+"fb_callback.php",{fblike:1,pid:pid},function(data){if(data.msg!="success"){alert("Oops -- sorry!  We did not receive your like.  Please try again.");}
else{showLikesProd();setCookie("loveit",getCookie("loveit")+","+pid,1)}},"json");}
function showLikesProd(){if($("#nfans").html()){var newcount=$("#nfans").html()*1+1*1;$("#nfans").html(newcount);}
else{$("#nfans").html('1');}
showLikePhrase();}
function showLikePhrase(){if($("#nfans").html()){if($("#nfans").html()!=0){if($("#nfans").html()==1){$("#lotslikephrase").hide();$("#onelikephrase").show();}
else{$("#onelikephrase").hide();$("#lotslikephrase").show();}}}}
function doesUsernameExist(){$.post("account_create.php",{username_exists:1,username:$("#username").val()},function(data){if(data.username_exists){$("#username_msg").html("This username has been taken.");}
else{$("#username_msg").html("");}},"json");}
function passMatch(){if($("#password").val()==$("#confirm").val()){return 1;}
return 0;}
function clearMsgs(){$("#username_msg").html("");$("#email_msg").html("");$("#password_msg").html("");}
function createNewAcct(){if($("#fb_uid").val()){createFBAcct();}
else{createEmailAcct();}}
function createFBAcct(){if(($("#username").val())&&($("#email").val())){$.post("account_create.php",{new_account:1,username:$("#username").val(),email:$("#email").val(),uid:$("#fb_uid").val(),account_type:"fb"},function(data){if(data.error){$("#submit_msg").html(data.msg);}
else{alert("login");}},"json");}
else{alert("Please make sure all fields are filled in.");}}
function createEmailAcct(){if(($("#username").val())&&($("#email").val())&&($("#password").val())&&($("#confirm").val())){if((passMatch())&&(isValidEmail($('#email').val()))){$.post("account_create.php",{new_account:1,username:$("#username").val(),email:$("#email").val(),pass:$("#password").val(),account_type:"email"},function(data){if(data.error){$("#submit_msg").html(data.msg);}
else{alert("login");}},"json");}
else{alert("Please confirm your password correctly.");}}
else{alert("Please make sure all fields are filled in.");}}
function sendLoginInfo(){}
