﻿// JScript File

function ProductsListingFithHeight(){
    
    var maxHeight=0;
    
    var oThumbCells = $('.ProductsListingThumbnailCell')
    oThumbCells.each(function(idx,oItem){
        if(maxHeight<$(oItem).height()) maxHeight=$(oItem).height()
    })    
    oThumbCells.each(function(idx,oItem){
        $(oItem).height(maxHeight)
    })
    
    maxHeight=0;
    var oInfoCells = $('.ProductsListingProductInfo')
    oInfoCells.each(function(idx,oItem){
        if(maxHeight<$(oItem).height()) maxHeight=$(oItem).height()
    })
    oInfoCells.each(function(idx,oItem){
        $(oItem).height(maxHeight)
    })    
}

function ShowAlbum(sAlbumId){
    //Tracking
    var sAction = "Albums.aspx"
    var sData = 'trackalbumid=' + sAlbumId
        
        $.ajax({
				method:'get', 
				url:sAction, 
				data:sData,
				cache: false,
				beforeSend:function(){				    
				},
				complete:function(){					
				},
				success:function(sHTML){                    
				}
        })
    //Show album
    $('#bmvAlbum' + sAlbumId + '').mbGallery({maskBgnd:'#666', maskOpacity:.8});
}

////////////////////////////////////////////////////////
//Survey
////////////////////////////////////////////////////////
function SubmitSurvey(ModuleSurveyID, sAction, NoOptionMessage, ThankMessage){
	var sSurveyId = '#BmvSurvey' + ModuleSurveyID
	var oCheckedOptions=$(sSurveyId + ' input:checked')
	
	if(! oCheckedOptions.length){
	    if(jQuery.trim(NoOptionMessage)!='') alert(NoOptionMessage)
		return false
	}
	
	var sIds = oCheckedOptions.serialize()
	while(sIds.indexOf(oCheckedOptions[0].name + '=')>=0){
		sIds=sIds.replace(oCheckedOptions[0].name + '=','')
	}
	while(sIds.indexOf('&')>=0){
		sIds=sIds.replace('&',',')
	}
	
	$.ajax({
		method		:'get',
		url			:sAction,
		data		:'ModuleSurveyID=' + ModuleSurveyID + '&option=' + sIds,
		beforeSend	:function(){			
		},
		complete	:function(){
		},
		success		:function(sResult){
			var oResultContainer = $(sSurveyId + ' .Result-Container')			
			oResultContainer.html(sResult)
			ShowResult(ModuleSurveyID)
			if(jQuery.trim(ThankMessage)!='') alert(ThankMessage)
		}
	})
}

function ShowSurvey(ModuleSurveyID){
	var sSurveyId = '#BmvSurvey' + ModuleSurveyID
	var btnResult = $(sSurveyId + ' .bmv-Suervey-result-button')
	var oOptionContainer = $(sSurveyId + ' .Option-Container')
	var oResultContainer = $(sSurveyId + ' .Result-Container')
	oResultContainer.css('display','none')
	oOptionContainer.css('display','block')
	btnResult.show()
}

function ShowResult(ModuleSurveyID){
	var sSurveyId = '#BmvSurvey' + ModuleSurveyID
	var btnResult = $(sSurveyId + ' .bmv-Suervey-result-button')
	var oOptionContainer = $('#BmvSurvey' + ModuleSurveyID + ' .Option-Container')
	var oResultContainer = $('#BmvSurvey' + ModuleSurveyID + ' .Result-Container')
	oResultContainer.css('display','block')
	oOptionContainer.css('display','none')
	btnResult.hide()
}
	
function CreateSurvey(ModuleSurveyID,sAction,NoOptionMessage,ThankMessage){    
	var sSurveyId = '#BmvSurvey' + ModuleSurveyID
	var oSurvey = $(sSurveyId)
	if(oSurvey){
		var oOptions = oSurvey.find(':input')
		oOptions.attr('name','BmvSurveyOption' + ModuleSurveyID)
		
		var btnSubmit = $(sSurveyId + ' .bmv-Suervey-submit-button')
		var btnResult = $(sSurveyId + ' .bmv-Suervey-result-button')
		
		var oOptionContainer = $(sSurveyId + ' .Option-Container')
		var oResultContainer = $(sSurveyId + ' .Result-Container')
	
		//Setup submit button		
		if(btnSubmit){
			btnSubmit.click(function(){
				var bShowingResult = (oResultContainer.css("display")=='block')
				if(bShowingResult){
					ShowSurvey(ModuleSurveyID)
				}
				else{
					SubmitSurvey(ModuleSurveyID,sAction,NoOptionMessage,ThankMessage)
				}
				
				return false
			})
		}
		
		//Setup result button
		if(btnResult){
			btnResult.click(function(){
				ShowResult(ModuleSurveyID)				
				return false
				
			})
		}
	
	}	
}
////////////////////////////////////////////////////////
//End of Survey
////////////////////////////////////////////////////////

$(document).ready(function(){
    //$(document).pngFix();
    
    $('a img').attr('border','0')

})
