// JavaScript Document

/* menu tabbing */
var tabArray = ['sizing','moreinfo','productreviews','press','askaquestion','collection','designer'];

function selectTab(divName){
	
	for(var i=0;i<tabArray.length;i++){
		if(document.getElementById('tab_'+tabArray[i])){
			document.getElementById('tab_'+tabArray[i]).className='non_selected';
			document.getElementById('product_menu_'+tabArray[i]).style.display='none';
		}
	}
	document.getElementById('tab_'+divName).className = "selected";
	document.getElementById('product_menu_'+divName).style.display='block';

	return false;
}

/* ask a question */
function askQuestion(){
	
	
	var failure = function(t){alert('Error: Unable to your question.  Please contact Customer Service directly ');}
	var success = function(t) {
		if (t.responseXML.documentElement.getElementsByTagName('Error')[0]){ 
			alert("Error: " + t.responseXML.documentElement.getElementsByTagName('Error')[0].firstChild.data);
			return;
		}
		else if (t.responseXML.documentElement.getElementsByTagName('Completed')[0]){ 	
			document.getElementById('ask_a_question_form').innerHTML = "Thank you.  We have sent your question to our Customer Service.  If you do not see a response from us within 2 business days, please check you spam folder as our reply email may have been mistakenly filtered as spam.";
		
		}
	}

	if (document.getElementById('question_name').value == '') {alert('Please enter in your name');return false;}
	if (document.getElementById('question_email').value == '') {alert('Please enter in your email');return false;}
	if (document.getElementById('question_text').value == '') {alert('Please enter in your question');return false;}
	if (!isEmail(document.getElementById('question_email').value)) {alert('Your email seems to have an invalid format');return false;}

	
	var url = "windowAskAQuestion.cfm";
	var pid = document.getElementById('question_pid').value;	
	var name = document.getElementById('question_name').value;	
	var email = document.getElementById('question_email').value;
	var question = document.getElementById('question_text').value;
	var pars = "email=" + email + "&name=" + name + "&question=" + question + "&pid=" + pid + "&format=xml";

	var myAjax = new Ajax.Request(
        url,
        {method: 'post', parameters: pars, onSuccess: success, onFailure: failure}
	);
}

/* view Enlarge */
var currentOpenPhoto;

function openEnlargeView(fileName, photoId){

	currentOpenPhoto = photoId;
	document.getElementById('enlarge_photo_src').src = 'images/photos/' + fileName;
	document.getElementById('photo_title_'+photoId).className = "photo_title_selected";
	document.getElementById('photo_caption_'+photoId).style.display = "block";
	document.getElementById('photo_enlarge').style.visibility='visible';	
	Drag.init(document.getElementById("photo_enlarge"),document.getElementById("photo_enlarge"));

	if(document.documentElement.scrollTop)
		document.getElementById('photo_enlarge').style.top = document.documentElement.scrollTop + "px";
	else
		document.getElementById('photo_enlarge').style.top = "40px";


}

function closeEnlargeView(){
	
	document.getElementById('photo_caption_'+currentOpenPhoto).style.display='none';
	document.getElementById('photo_title_'+currentOpenPhoto).className = '';
	document.getElementById('photo_enlarge').style.visibility='hidden';
	document.getElementById('enlarge_photo_src').src = '';
	Drag.end();

}

function selectPhoto(fileName, photoId){
	
	document.getElementById('enlarge_photo_src').src = 'images/photos/' + fileName;
	document.getElementById('photo_caption_'+currentOpenPhoto).style.display='none';
	document.getElementById('photo_title_'+currentOpenPhoto).className = '';
	document.getElementById('photo_caption_'+photoId).style.display='block';
	document.getElementById('photo_title_'+photoId).className = 'photo_title_selected';
	currentOpenPhoto = photoId;

}

function showItemSize(obj){
	
	elementArray = $$('.item_size_display');
	if(obj.checked){
		for(i=0;i<elementArray.length;i++)
			elementArray[i].style.display="";
	}
	else{
		for(i=0;i<elementArray.length;i++)
			elementArray[i].style.display="none";
	}
}
	
function fbs_click(){
	
	u=location.href;
	t=document.title;
	window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'&t='+encodeURIComponent(t),'sharer','toolbar=0,status=0,width=626,height=436');
	return false;

}	