//////////////////////////////////////////////////////////////////
// check for empty fields
function checkLoginForm(){
var message = "One or more fields were left blank";

var username = document.getElementById("username");
var password = document.getElementById("password");

if( password.value == "" ){ alert(message); return false;}
if( username.value == "" ){ alert(message); return false;}

return true;
}

//////////////////////////////////////////////////////////////////
// check for empty fields
function checkRegistrationForm(){
var message = "One or more fields were left blank";

var password = document.getElementById("register_password");
var email = document.getElementById("register_email");
//var imagetext = document.getElementById("imagetext");
//var termsagree = document.getElementById("termsagree");

if( password.value == "" ){ alert(message); return false;}
if( email.value == "" ){ alert(message); return false;}
//if( imagetext.value == "" ){ alert(message); return false;}
//if( termsagree.checked == false ){ alert(message); return false;}

return true;
}


//////////////////////////////////////////////////////////////////
// check for empty fields
/*
function checkRegistrationForm(){
var message = "One or more fields were left blank";

var username = document.getElementById("username");
var password = document.getElementById("password");
var firstname = document.getElementById("firstname");
var lastname = document.getElementById("lastname");
var email = document.getElementById("email");
var subject = document.getElementById("subject");
var imagetext = document.getElementById("imagetext");
var termsagree = document.getElementById("termsagree");

if( password.value == "" ){ alert(message); return false;}
if( username.value == "" ){ alert(message); return false;}
if( firstname.value == "" ){ alert(message); return false;}
if( lastname.value == "" ){ alert(message); return false;}
if( email.value == "" ){ alert(message); return false;}
if( subject.value == "" ){ alert(message); return false;}
if( imagetext.value == "" ){ alert(message); return false;}
if( termsagree.checked == false ){ alert(message); return false;}

return true;
}
*/


//////////////////////////////////////////////////////////////////
//  parameter is id#
function friend_optionsVisible(menu_name){
document.getElementById(menu_name).style.visibility="visible";


//document.getElementById('friend_photo').style.color="white";
//document.getElementById('friend_photo').style.backgroundColor="black";
}
//////////////////////////////////////////////////////////////////
//  parameter is id# 
function friend_optionsHide(menu_name){
document.getElementById(menu_name).style.visibility="hidden";


//document.getElementById('friend_photo').style.color="black";
//document.getElementById('friend_photo').style.backgroundColor="white";
}



//////////////////////////////////////////////////////////////////
//  parameter is id#
function folder_highlight(folder_name){
document.getElementById(folder_name).style.color="white";
document.getElementById(folder_name).style.backgroundColor="black";
}
//////////////////////////////////////////////////////////////////
//  parameter is id# 
function folder_normal(folder_name){
document.getElementById(folder_name).style.color="black";
document.getElementById(folder_name).style.backgroundColor="white";
}



//background_highlight(\'product_name\', \'color\')
//////////////////////////////////////////////////////////////////
//  parameter is id#, color
function background_highlight(element_id, color){
//document.getElementById(element_id).style.color=color;
document.getElementById(element_id).style.backgroundColor=color;
}
//////////////////////////////////////////////////////////////////
//  parameter is id# , color
function background_highlight_off(element_id, color){
//document.getElementById(element_id).style.color=color;
document.getElementById(element_id).style.backgroundColor=color;
}



//border_highlight(\'product_container\', \'color\');
//////////////////////////////////////////////////////////////////
//  parameter is id#, color
function border_highlight(element_id, color){
//document.getElementById(element_id).style.color=color;
document.getElementById(element_id).style.borderColor=color;
}
//////////////////////////////////////////////////////////////////
//  parameter is id# , color
function border_highlight_off(element_id, color){
//document.getElementById(element_id).style.color=color;
document.getElementById(element_id).style.borderColor=color;
}



//////////////////////////////////////////////////////////////////
function cart_button_hover(target_element, pictureURL){
// show hover version of button
  document.getElementById(target_element).src = pictureURL;
}
//////////////////////////////////////////////////////////////////
function cart_button_regular(target_element, pictureURL){
// make button regular
  document.getElementById(target_element).src = pictureURL;
}




//////////////////////////////////////////////////////////////////
function wishlist_button_hover(target_element, pictureURL){
// show hover version of button
  document.getElementById(target_element).src = pictureURL;
}
//////////////////////////////////////////////////////////////////
function wishlist_button_regular(target_element, pictureURL){
// make button regular
  document.getElementById(target_element).src = pictureURL;
}



//////////////////////////////////////////////////////////////////
//  parameter is id#
function product_popup_show(element_id){
document.getElementById(element_id).style.visibility="visible";
//document.getElementById(element_id).style.display="block";
//document.getElementByClassName('f').style.zIndex="0";
}
//////////////////////////////////////////////////////////////////
//  parameter is id#
function product_popup_hide(element_id){
document.getElementById(element_id).style.visibility="hidden";
//document.getElementById(element_id).style.display="none";
//document.getElementByClassName('f').style.zIndex="1";
}



//////////////////////////////////////////////////////////////////
//  parameter is id#
function storeSortOptionsVisible(menu_name, options_name){
document.getElementById(menu_name).style.visibility="visible";

document.getElementById(options_name).style.paddingBottom="35px";
//document.getElementById(options_name).style.zIndex="10000";
document.getElementById(options_name).style.color="#555555";
document.getElementById(options_name).style.backgroundColor="#eeeeee";

document.getElementById(options_name).style.border="solid 1px #aaaaaa";
}
//////////////////////////////////////////////////////////////////
//  parameter is id# 
function storeSortOptionsHide(menu_name, options_name){
document.getElementById(menu_name).style.visibility="hidden";

document.getElementById(options_name).style.paddingBottom="5px";
//document.getElementById(options_name).style.zIndex="0";
document.getElementById(options_name).style.color="#555555";
document.getElementById(options_name).style.backgroundColor="white";

document.getElementById(options_name).style.border="solid 1px white";
}



//////////////////////////////////////////////////////////////////
// parameter is id# 
function menuVisible(menu, number){
var main_menu_name = menu + number;
var sub_menu_name = menu + "_" + number;

// color green #99ff44

document.getElementById(main_menu_name).style.backgroundColor="white";
document.getElementById(main_menu_name).style.color="black";
document.getElementById(main_menu_name).style.textDecoration="none";
document.getElementById(main_menu_name).style.paddingBottom="15px";

document.getElementById(main_menu_name).style.borderTopColor="black";
document.getElementById(main_menu_name).style.borderTopStyle="solid";
document.getElementById(main_menu_name).style.borderTopWidth="2px";

//document.getElementById(main_menu_name).style.borderLeftColor="black";
//document.getElementById(main_menu_name).style.borderLeftStyle="solid";
//document.getElementById(main_menu_name).style.borderLeftWidth="2px";

document.getElementById(main_menu_name).style.borderRightColor="white";
document.getElementById(main_menu_name).style.borderRightStyle="solid";
document.getElementById(main_menu_name).style.borderRightWidth="0px";

document.getElementById(sub_menu_name).style.visibility="visible";
}
//////////////////////////////////////////////////////////////////
//parameter is id# 
function menuHide(menu, number){
var main_menu_name = menu + number;
var sub_menu_name = menu + "_" + number;

document.getElementById(main_menu_name).style.backgroundColor="black";
document.getElementById(main_menu_name).style.color="white";
document.getElementById(main_menu_name).style.textDecoration="none";
document.getElementById(main_menu_name).style.paddingBottom="1px";

document.getElementById(main_menu_name).style.borderTopColor="";
document.getElementById(main_menu_name).style.borderTopStyle="solid";
document.getElementById(main_menu_name).style.borderTopWidth="2px";

//document.getElementById(main_menu_name).style.borderLeftColor="";
//document.getElementById(main_menu_name).style.borderLeftStyle="solid";
//document.getElementById(main_menu_name).style.borderLeftWidth="2px";

document.getElementById(main_menu_name).style.borderRightColor="white";
document.getElementById(main_menu_name).style.borderRightStyle="solid";
document.getElementById(main_menu_name).style.borderRightWidth="0px";

document.getElementById(sub_menu_name).style.visibility="hidden";
}



//////////////////////////////////////////////////////////////////
function showLargeView(elementToShow){
// check if this part is needed
if( document.getElementById('large_view') != null ){
  var pictureURL = document.getElementById('large_view').getAttribute('src');
  document.getElementById('giant_view').src = pictureURL;
}
// make the large version visible 
document.getElementById(elementToShow).style.display = "block";
//document.getElementById(elementToShow).style.zIndex = "";
}
//////////////////////////////////////////////////////////////////
function hideLargeView(elementToHide){
// make the large version hidden
document.getElementById(elementToHide).style.display = "none"
//document.getElementById(elementToHide).style.zIndex = "1";
}


//////////////////////////////////////////////////////////////////
function switchImage(sourceURL, destinationElement){
// takes a url and an element's id
document.getElementById(destinationElement).src = sourceURL;

MojoZoom.makeZoomable( document.getElementById(destinationElement), sourceURL ); 
}


//////////////////////////////////////////////////////////////////
function delay(millis){
var date = new Date();
var curDate = null;
do{
curDate = new Date(); 
}
while(curDate-date < millis);
}
//////////////////////////////////////////////////////////////////
var notPosted = true;
function newPost(box){
if(notPosted){
//notPosted = false; 
box.value=""; }
}
//////////////////////////////////////////////////////////////////







//////
//////
//////

function update_cart_item_quantity( stocknumber, price, user_name ){

	var ajaxRequest2;  // variable to hold ajax request
	
	try{
	    // Opera 8.0+, Firefox, Safari
	    ajaxRequest2 = new XMLHttpRequest();
	}catch(e){
	    // Internet Explorer Browsers
	    try{
	       ajaxRequest2 = new ActiveXObject("Msxml2.XMLHTTP");
	    }catch(e){
		try{
		   ajaxRequest2 = new ActiveXObject("Microsoft.XMLHTTP");
		}catch(e){
	           // Something went wrong
		   alert("Your browser does not support Ajax.");
		   return false;
		}
	    }
	}

	// Create a function that will receive data sent from the server
	ajaxRequest2.onreadystatechange = function(){
		if(ajaxRequest2.readyState == 4){

                      document.getElementById('cart_total').innerHTML = ajaxRequest2.responseText;

		}
	}

                // get quantity from the document
                 var sel = document.getElementById('quantity_'+stocknumber);
                var quantity = sel.options[sel.selectedIndex].value;

                 // here update stock item total
                   document.getElementById('item_total_price_'+stocknumber).innerHTML = (price*quantity).toFixed(2);

        ajaxRequest2.open("GET", "http://www.couturecravings.com/update_cart_item_quantity.php/?stocknumber="+stocknumber+"&user_name="+user_name+"&quantity="+quantity, true);
	ajaxRequest2.send(null);
}





//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
function load_products_set( number_items_per_set, page_number ){
	var ajaxRequest;  // variable to hold ajax request
	try{
	    // Opera 8.0+, Firefox, Safari
	    ajaxRequest = new XMLHttpRequest();
	}catch(e){
	    // Internet Explorer Browsers
	    try{
	       ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
	    }catch(e){
		try{
		   ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
		}catch(e){
	           // Something went wrong
		   alert("Your browser does not support Ajax.");
		   return false;
		}
	    }
	}
	// Create a function that will receive data sent from the server
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4){

                   // change the products being shown to new set
                    document.getElementById('product_loading_area').innerHTML = ajaxRequest.responseText;

		}
	}

             var parameters = "number_items_per_set="+number_items_per_set+"&page_number="+page_number; 

             ajaxRequest.open("POST", "http://www.couturecravings.com/load_products_set.php", true);
             ajaxRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	     ajaxRequest.send(parameters);
}


//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
function add_blog_comment( blog_reply_to_number ){
	var ajaxRequest;  // variable to hold ajax request
	try{
	    // Opera 8.0+, Firefox, Safari
	    ajaxRequest = new XMLHttpRequest();
	}catch(e){
	    // Internet Explorer Browsers
	    try{
	       ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
	    }catch(e){
		try{
		   ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
		}catch(e){
	           // Something went wrong
		   alert("Your browser does not support Ajax.");
		   return false;
		}
	    }
	}
	// Create a function that will receive data sent from the server
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4){

                 // also need to add this current comment to comments visible in this blogs comment section
             document.getElementById('blog_comments_container_'+blog_reply_to_number).innerHTML = ajaxRequest.responseText;

		}
	}

          // test the simple math input 
            var addition = encodeURIComponent(document.getElementById('blog_comment_test_'+blog_reply_to_number).value);

          // 
            var security_code = encodeURIComponent(document.getElementById('ytiruces_edoc_'+blog_reply_to_number).value);

         if( addition == security_code ){
              var message = encodeURIComponent(document.getElementById('blog_comment_'+blog_reply_to_number).value);
              var name = encodeURIComponent(document.getElementById('blog_comment_name_'+blog_reply_to_number).value);
              var parameters = "name="+name+"&message="+message+"&blog_reply_to_number="+blog_reply_to_number; 

                 // here should change text area value to "" nothing
                   document.getElementById('blog_comment_'+blog_reply_to_number).value = "";

                 // also give confirmation that comment was added, 
                 // maybe just have an existing box (that says comment added )made visible
                   document.getElementById('blog_comment_confirmation_'+blog_reply_to_number).style.display = "block";

                 // also comment form area is made hidden
                   document.getElementById('blog_comment_form_container_'+blog_reply_to_number).style.display = "none";
                 // also comment test fail area is made hidden
                 document.getElementById('blog_comment_test_fail_'+blog_reply_to_number).style.display = "none";

             ajaxRequest.open("POST", "http://www.couturecravings.com/add_blog_comment.php", true);
             ajaxRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	     ajaxRequest.send(parameters);

         }else{
             document.getElementById('blog_comment_test_fail_'+blog_reply_to_number).style.display = "block";
         }
}


//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
function add_cart_item( stocknumber, user_name ){
	var ajaxRequest;  // variable to hold ajax request
	
	try{
	    // Opera 8.0+, Firefox, Safari
	    ajaxRequest = new XMLHttpRequest();
	}catch(e){
	    // Internet Explorer Browsers
	    try{
	       ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
	    }catch(e){
		try{
		   ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
		}catch(e){
	           // Something went wrong
		   alert("Your browser does not support Ajax.");
		   return false;
		}
	    }
	}

	// Create a function that will receive data sent from the server
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4){

	               document.getElementById('add_item_button_'+stocknumber+'_1').src =
                           "http://www.couturecravings.com/my_account/photos/view_photos/tate/saved/in_cart.gif";
	               document.getElementById('add_item_button_'+stocknumber+'_1').style.cursor = "auto";


	               document.getElementById('add_item_button_'+stocknumber+'_2').src =
                           "http://www.couturecravings.com/my_account/photos/view_photos/tate/saved/in_cart.gif";
	               document.getElementById('add_item_button_'+stocknumber+'_2').style.cursor = "auto";

                         var ajaxDisplay = document.getElementById('item_add_confirmation_'+stocknumber+'_1');
			 ajaxDisplay.innerHTML = ajaxRequest.responseText;

                         var ajaxDisplay = document.getElementById('item_add_confirmation_'+stocknumber+'_2');
			 ajaxDisplay.innerHTML = ajaxRequest.responseText;
		}
	}

       // get quantity from document
       var sel = document.getElementById('quantity_'+stocknumber);
       var quantity = sel.options[sel.selectedIndex].value;

        ajaxRequest.open("GET", "http://www.couturecravings.com/add_cart_item.php/?do=update_cart&stocknumber="+stocknumber+"&user_name="+user_name+"&quantity="+quantity, true);
	ajaxRequest.send(null);

}

//////
//////
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
function add_wishlist_item( stocknumber, user_name ){
	var ajaxRequest;  // variable to hold ajax request
	
	try{
	    // Opera 8.0+, Firefox, Safari
	    ajaxRequest = new XMLHttpRequest();
	}catch(e){
	    // Internet Explorer Browsers
	    try{
	       ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
	    }catch(e){
		try{
		   ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
		}catch(e){
	           // Something went wrong
		   alert("Your browser does not support Ajax.");
		   return false;
		}
	    }
	}

	// Create a function that will receive data sent from the server
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4){

	               document.getElementById('wishlist_add_item_button_'+stocknumber+'_1').src =
                           "http://www.couturecravings.com/my_account/photos/view_photos/tate/saved/in_cart.gif";
	               document.getElementById('wishlist_add_item_button_'+stocknumber+'_1').style.cursor = "auto";

	               document.getElementById('wishlist_add_item_button_'+stocknumber+'_2').src =
                           "http://www.couturecravings.com/my_account/photos/view_photos/tate/saved/in_cart.gif";
	               document.getElementById('wishlist_add_item_button_'+stocknumber+'_2').style.cursor = "auto";

                         var ajaxDisplay = document.getElementById('wishlist_item_add_confirmation_'+stocknumber+'_1');
			 ajaxDisplay.innerHTML = ajaxRequest.responseText;

                         var ajaxDisplay = document.getElementById('wishlist_item_add_confirmation_'+stocknumber+'_2');
			 ajaxDisplay.innerHTML = ajaxRequest.responseText;
		}
	}

/*
// will wishlist need quantity?
       // get quantity from document
       var sel = document.getElementById('wishlist_quantity_'+stocknumber);
       var quantity = sel.options[sel.selectedIndex].value;
*/
var quantity = 1;

        ajaxRequest.open("GET", "http://www.couturecravings.com/add_wishlist_item.php/?do=update_wishlist&stocknumber="+stocknumber+"&user_name="+user_name+"&quantity="+quantity, true);
	ajaxRequest.send(null);

}

//////
//////
//////


function update_num_cart_items( stocknumber, user_name ){

	var ajaxRequest2;  // variable to hold ajax request
	
	try{
	    // Opera 8.0+, Firefox, Safari
	    ajaxRequest2 = new XMLHttpRequest();
	}catch(e){
	    // Internet Explorer Browsers
	    try{
	       ajaxRequest2 = new ActiveXObject("Msxml2.XMLHTTP");
	    }catch(e){
		try{
		   ajaxRequest2 = new ActiveXObject("Microsoft.XMLHTTP");
		}catch(e){
	           // Something went wrong
		   alert("Your browser does not support Ajax.");
		   return false;
		}
	    }
	}

	// Create a function that will receive data sent from the server
	ajaxRequest2.onreadystatechange = function(){
		if(ajaxRequest2.readyState == 4){

                         var ajaxDisplay2 = document.getElementById('number_cart_items');
			 ajaxDisplay2.innerHTML = ajaxRequest2.responseText;

                      // var updateNumberCartItems = document.getElementById('number_cart_items');
                     //  updateNumberCartItems.innerHTML = parseInt(number_cart_items) + 1; 

		}
	}

        ajaxRequest2.open("GET", "http://www.couturecravings.com/add_cart_item.php/?do=get_num_cart_items&stocknumber="+stocknumber+"&user_name="+user_name, true);
	ajaxRequest2.send(null);
}



//////////////////////////////////////////////////////////////////

