
/*
 * for the layer it tool
 */
var gender = currentCategory;

function doProductBundlePage(layerit_ids)
{
	if(gender == "womens"){
		dcsMultiTrack('DCS.dcsuri','/LayerToolBuyOutfitW.html','WT.ti','Womens:Tools:LayerIt:Buy:Outfit','DCSext.LayerTool','WomensBuyOutfit','WT.seg_2','WomensLayerItTool');
	} else {
		dcsMultiTrack('DCS.dcsuri','/LayerToolBuyOutfitM.html','WT.ti','Mens:Tools:LayerIt:Buy:Outfit','DCSext.LayerTool','MensBuyOutfit','WT.seg_2','MensLayerItTool');
	}
	var newLocation = '/web/browse/dynamic_bundle_page.jsp?mId='+layerit_ids.join(':');
	if(gender == "womens"){
		if(currentCategory) newLocation += '&catId='+currentCategory+'&DCSext.source=WomensLayerItTool';
	} else {
		if(currentCategory) newLocation += '&catId='+currentCategory+'&DCSext.source=MensLayerItTool';
	}
	window.location = newLocation;
}

function doBuyOutfit(layerit_ids)
{
	doProductBundlePage(layerit_ids);
}

function doSendToAFriend(layerit_ids)
{
	showEmailToFriend(layerit_ids.join(':'));
}

function doSendToAFriendTest()
{
	/*var ids = doGetCurrentOutfit();
	doSendToAFriend(ids.split(':'));*/
	doSendToAFriend('A14:A26:A46'.split(':'));
}

function showEmailToFriend(mId){
	hideEmailSuccess();
	$('#sentFriend').attr('src', '../emailtemplates/emailafriend/email_a_friend_layerit.jsp?mId='+mId+'&emailFriendUrl=email_a_friend_layerit.jsp');
	$('#friendBackground').removeClass('hidePhoneFriend');
	$('#friendBackground').addClass('showPhoneFriend');
	$('#sentFriend').removeClass('hidePhoneFriend');
	$('#sentFriend').addClass('showPhoneFriend');
	
	var newX = (document.body.clientWidth/2-document.getElementById('friendBackground').offsetWidth/2)+6;
	$('#friendBackground').css('left', newX+'px');
	$('#sentFriend').css('left', (newX+10)+'px');
}

function hideEmailToFriend(){
	$('#friendBackground').addClass('hidePhoneFriend');
	$('#friendBackground').removeClass('showPhoneFriend');
	$('#sentFriend').addClass('hidePhoneFriend');
	$('#sentFriend').removeClass('showPhoneFriend');
}

function showEmailSuccess(){
	hideEmailToFriend();
	$('#emailSuccess').addClass('showPhoneFriend');
	$('#emailSuccess').removeClass('hidePhoneFriend');
	$('#eSuccessContent').addClass('showPhoneFriend');
	$('#eSuccessContent').removeClass('hidePhoneFriend');
	
	var newX = (document.body.clientWidth/2-document.getElementById('emailSuccess').offsetWidth/2)+6;
	$('#emailSuccess').css('left', newX+'px');
	newX += 10;
	$('#eSuccessContent').css('left', newX+'px');
}
function hideEmailSuccess(){
	$('#emailSuccess').addClass('hidePhoneFriend');
	$('#emailSuccess').removeClass('showPhoneFriend');
	$('#eSuccessContent').addClass('hidePhoneFriend');
	$('#eSuccessContent').removeClass('showPhoneFriend');
}

function doSaveCurrentOutfit(layerit_ids)
{
	createCookie('layerit_currentOutfit', layerit_ids.join(':'), false);
}

function doGetCurrentOutfit()
{
	var cookieVal = readCookie('layerit_currentOutfit');
	/*if(cookieVal == null) return false;
	else return cookieVal.split(':');*/
	return cookieVal;
}

function doGetPredressBoolean()
{
	var predress = 'false';
	var cookieVal = readCookie('layerit_currentOutfit');
	if(cookieVal != null) predress = 'true';
	return predress;
}


/*
 * for the outfit page
 */

function doViewOutfit(outfit_id) {
	if(gender == "women"){
		dcsMultiTrack('DCS.dcsuri','/ShopByOutfitBuyW.html','WT.ti','Womens:ShopByOutfit:ViewandBuy','DCSext.ShopByOutfit','WomensViewandBuy','WT.seg_2','WomensShopByOutfit');
	}else {
		dcsMultiTrack('DCS.dcsuri','/ShopByOutfitBuyM.html','WT.ti','Mens:ShopByOutfit:ViewandBuy','DCSext.ShopByOutfit','MensViewandBuy','WT.seg_2','MensShopByOutfit');
	}
	var newLocation = '/web/browse/outfit_bundle_page.jsp?o='+outfit_id;
	if(gender == "women"){
		if(currentCategory) newLocation += '&catId='+currentCategory+'&DCS.ext.source=WomensShopByOutfit';
	}else {
		if(currentCategory) newLocation += '&catId='+currentCategory+'&DCSext.source=MensShopByOutfit';
	}
	window.location = newLocation;
}

function changeGender(toWhat) {	
	gender = toWhat;
}
/*
 * some utility functions for cookies
 * taken from http://www.quirksmode.org/js/cookies.html (free for any use)
 */
function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	var name = currentCategory+"_"+name
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = currentCategory+"_"+name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}
