function closeAllSubMenu(){
    
    if ( document.getElementById('menuMain') == null ) 
        return;
    var arrayDiv = document.getElementById('menuMain').getElementsByTagName('div');
	arrayLI = document.getElementById('menuMain').getElementsByTagName('li');
    for (i = 0; i < arrayDiv.length; i++)
        arrayDiv[i].style.visibility='hidden';
    for (i = 0; i < arrayLI.length; i++)
        if ( arrayLI[i].getElementsByTagName('div').length != 0 )
        arrayLI[i].className = 'none';
}
//-----------------------------------------------------------------------------
function searchDIV(nameDiv){
    var arrayDiv = document.getElementsByTagName('div');	
	i = 0;
	while( ( i < arrayDiv.length ) && ( arrayDiv[i].className != nameDiv ) ) 
	    i++;
	if (i != arrayDiv.length) 
	    return arrayDiv[i]
	else 
	    return null;
}    
//-----------------------------------------------------------------------------
function widthDIV(nameDiv){     
    return searchDIV(nameDiv).offsetWidth;
}
//-----------------------------------------------------------------------------
function searchCSSName( nameCSS ){
    rul = document.styleSheets[0].rules;
    i = 0;
if ( rul == null)
   return (null);
    while( ( i < rul.length ) && ( rul[i].selectorText != nameCSS ) ) 
        i++;
    if( ( i != rul.length ) && ( rul[i].selectorText == nameCSS ) ) 
        return( rul[i] );
    return( null );
}
//-----------------------------------------------------------------------------

function displaySubMenu(itemName, subName)
{		
		var classDisplay = document.getElementById(itemName).className;	

		closeAllSubMenu();		
		if (document.getElementById(itemName).className == 'lastItem') 
		    document.getElementById(itemName).className = classDisplay + ' chosen_lst';
		else 
		    document.getElementById(itemName).className = classDisplay + ' chosen';
		   
		if ( ( document.getElementById(subName).style.left == '' ) && (document.getElementById(searchDIV('menuMain').className) != null) ){			
            leftPosition_Submenu = ( document.getElementById(itemName).offsetLeft + document.getElementById(itemName).offsetWidth/2 ) - document.getElementById(subName).offsetWidth/2;
			widthMenu = widthDIV('menuMain');
			if ( ( leftPosition_Submenu + document.getElementById(subName).offsetWidth ) > widthMenu )
			    document.getElementById(subName).style.left = widthMenu-document.getElementById(subName).offsetWidth + 'px';
			else if ( leftPosition_Submenu < 0 ) 
			    document.getElementById(subName).style.left = 0 + 'px'
			else 
			    document.getElementById(subName).style.left = leftPosition_Submenu + 'px';
		}
		document.getElementById(subName).style.visibility = 'visible';
		if (( document.styleSheets )&&( (css = searchCSSName( '.subMenuMain_exp' ) ) !=  null) ) 
		    document.getElementById(subName).style.marginTop = css.style.marginTop;
}
//-----------------------------------------------------------------------------
function hideSubMenu(itemName, subName)
{ 
		var classHide = document.getElementById(itemName).className;
		var classLeft = classHide.substring(0, 5);
		var classRight = classHide.substring(6, 12);

    document.getElementById(subName).style.visibility='hidden';
    if (classRight == 'chosen') 
        document.getElementById(itemName).className = classLeft;
    else 
        document.getElementById(itemName).className = 'lastItem';
}
//-----------------------------------------------------------------------------
// special scripts for Cards&Gifts template
//-----------------------------------------------------------------------------
function bookmarkUrl(title, url){
  // IE
  if (document.all) {
     window.external.AddFavorite(url, title);
  } // Mozilla
  else if (window.sidebar){
     window.sidebar.addPanel(title, url, "")
  }
}           
//-----------------------------------------------------------------------------
function setCookie (name, value, lifespan, access_path) {
    var cookietext = name + "=" + escape(value)  
    if (lifespan != null) {  
        var today=new Date()     
        var expiredate = new Date()      
        expiredate.setTime(today.getTime() + 1000*60*60*24*lifespan)
        cookietext += "; expires=" + expiredate.toGMTString()
    }
    if (access_path != null) { 
      cookietext += "; PATH="+access_path 
    }
    document.cookie = cookietext   
    return null  
}
//-----------------------------------------------------------------------------
function setDatedCookie(name, value, expire, access_path) {
    var cookietext = name + "=" + escape(value) + ((expire == null) ? "" : ("; expires=" + expire.toGMTString()))
    if (access_path != null) { 
        cookietext += "; PATH="+access_path 
    }
    document.cookie = cookietext 
    return null        
}
//-----------------------------------------------------------------------------
function getCookie(Name) {
    var search = Name + "="                       
    var CookieString = document.cookie            
    var result = null                               
    if (CookieString.length > 0) {                
        offset = CookieString.indexOf(search)       
        if (offset != -1) {                         
            offset += search.length                   
            end = CookieString.indexOf(";", offset)   
            if (end == -1)                            
                end = CookieString.length               
            result = unescape(CookieString.substring(offset, end))         
        } 
    }
    return result                                
}
//-----------------------------------------------------------------------------
function deleteCookie(Name, Path) {
    setCookie(Name,"Deleted", -1, Path)
}
//-----------------------------------------------------------------------------        
var CATEGORY_COOKIE_NAME = 'openCategoryId';
function closeActiveCategory()
{
    vOpenCategory = getCookie(CATEGORY_COOKIE_NAME);
    closeCategory(vOpenCategory);
}
//-----------------------------------------------------------------------------        
function showActiveCategory()
{
    vOpenCategory = getCookie(CATEGORY_COOKIE_NAME);
    openCategory(vOpenCategory);
}
//-----------------------------------------------------------------------------        
function displayUL(categoryId, visibility, style, classname){
    if ( (categoryId != null) && (categoryId != 'null') ){
        categoryLI = document.getElementById(categoryId);
        subMenu = categoryLI.getElementsByTagName('ul')[0];
        if ( subMenu != null ){
            if(subMenu.style != null){
                subMenu.style.visibility=visibility;
                subMenu.style.display=style;
                categoryLI.className=classname;
            }
        }
    }
}
//-----------------------------------------------------------------------------        
function displayCategory(categoryId){
    vOpenCategory = getCookie(CATEGORY_COOKIE_NAME);
    if ( (vOpenCategory != null) && (vOpenCategory == categoryId) ){    
        deleteCookie(CATEGORY_COOKIE_NAME, '/');
    }
    else{        
        setCookie(CATEGORY_COOKIE_NAME, escape(categoryId), 10, '/');
    }
}
//-----------------------------------------------------------------------------        
function openCategory(categoryId){
    // Close previously open category (if any)
    closeActiveCategory();
    // Open new category
    displayUL(categoryId, 'visible','block','chosen');
    // Save open category reference in cookie
    setCookie(CATEGORY_COOKIE_NAME, escape(categoryId), 10, '/');
}
//-----------------------------------------------------------------------------        
function closeCategory(categoryId){
    if ( (categoryId != null) && (categoryId != 'null')){
        // delete cookie
        deleteCookie(CATEGORY_COOKIE_NAME, '/');
        // hide category LI
        displayUL(categoryId, 'hidden','none','');
    }
}
//-----------------------------------------------------------------------------
function alignBoxes(nameInterestingBox){
    arrayInterestingDiv = searchArrayInterestingDiv( nameInterestingBox );
	maxHeight = maxHeightBox(arrayInterestingDiv);	
	for ( i = 0; i < arrayInterestingDiv.length; i++ ){
		arrayStretchingBox = arrayInterestingDiv[i].getElementsByTagName('span');
		k = 0;
		while ( ( k < arrayStretchingBox.length ) && ( arrayStretchingBox[k].className != 'stretching' ) ) 
		    k++;
		if ( k != arrayStretchingBox.length ){
			arrayStretchingBox[k].style.height = arrayStretchingBox[k].offsetHeight + (maxHeight - arrayInterestingDiv[i].offsetHeight) + 'px';
			arrayStretchingBox[k].style.height = arrayStretchingBox[k].offsetHeight + (maxHeight - arrayInterestingDiv[i].offsetHeight) + 'px';
		}
	} 
}
//-----------------------------------------------------------------------------
function searchArrayInterestingDiv( nameInterestingBox ){
	var arrayDiv = document.getElementsByTagName('div');
	var k = 0;	
	for ( i = 0; i < arrayDiv.length; i++ )
	    if ( arrayDiv[i].className == nameInterestingBox ) 
	        k++;
	arrayInterestingDiv = new Array(k);
	k = 0;
	for ( i = 0; i < arrayDiv.length; i++ )
	    if ( arrayDiv[i].className == nameInterestingBox ){
		    arrayInterestingDiv[k] = arrayDiv[i];
		    k++;
	    }
	
	return arrayInterestingDiv;
}
//-----------------------------------------------------------------------------
function maxHeightBox(arrayBox){
	maxHeightDiv = arrayBox[0];
	for ( i = 1; i < arrayBox.length; i++ )
	    if ( arrayBox[i].offsetHeight > maxHeightDiv.offsetHeight ) 
	        maxHeightDiv = arrayBox[i];
	return maxHeightDiv.offsetHeight;
}
//-----------------------------------------------------------------------------
var marqueewidth="100px"
if (navigator.appName == "Microsoft Internet Explorer"){
    var marqueespeed=1
}
else
{
    var marqueespeed=2
}
var copyspeed=marqueespeed
var cross_marquee, ns_marquee
//-----------------------------------------------------------------------------
function InitSlideShow(){
    var widthSlideLine = 0;
    var maxHeightSlide = 0;
    if (document.getElementById("iemarquee")){
        cross_marquee=document.getElementById("iemarquee");
        arraySlide = cross_marquee.getElementsByTagName('div');
        for ( i = 0; i < arraySlide.length; i++ ){
            widthSlideLine = widthSlideLine +arraySlide[i].offsetWidth;
            if ( arraySlide[i].offsetHeight > maxHeightSlide ){
                maxHeightSlide = arraySlide[i].offsetHeight;
            }
        }
    cross_marquee.style.width = widthSlideLine+"px";
    screenDiv = searchDIV("screen");
    screenDiv.style.height = maxHeightSlide + "px";
    maskDiv = searchDIV("mask");
    maskDiv.style.height = maxHeightSlide + "px";
    controlPanelDiv     = searchDIV("controlPanel");
    controlPanelDiv.style.marginTop = maxHeightSlide/2 - 20 + "px";
    cross_marquee.style.left=parseInt(marqueewidth)+8+"px";
    startpoint = parseInt(cross_marquee.style.left);
    endpoint = cross_marquee.offsetWidth;
    ScrollStart();      
    }
}
//-----------------------------------------------------------------------------
function ScrollStart(){
    lefttime=window.setInterval("scrollmarquee()",20);  
}
//-----------------------------------------------------------------------------
function ScrollStop(){
	copyspeed = 0;
}
//-----------------------------------------------------------------------------
function ScrollLeft(){
	copyspeed = marqueespeed + 4;
}
//-----------------------------------------------------------------------------
function ScrollRight(){
	copyspeed = marqueespeed - 6;
}
//-----------------------------------------------------------------------------
function ScrollNormalMode(){
	copyspeed = marqueespeed;
}
//-----------------------------------------------------------------------------
function scrollmarquee(){
    if ( (parseInt(cross_marquee.style.left)<(endpoint*(-1))) && (copyspeed > 0) )	
        cross_marquee.style.left=parseInt(marqueewidth)+8+"px"
    else if ( (parseInt(cross_marquee.style.left)>(startpoint+8)) && (copyspeed < 0) )
        cross_marquee.style.left=-endpoint+"px"
    else{
        cross_marquee.style.left=parseInt(cross_marquee.style.left)-copyspeed+"px";
    }
}
//-----------------------------------------------------------------------------
function ChangeStatus(linkImage){
	var image = linkImage.getElementsByTagName('img')[0];
	path = image.src;
	if ( path.lastIndexOf('hover') == -1 )
	    image.src = path.substring(0, path.length-4)+'_hover.png';
	else
	    image.src = path.substring(0, path.lastIndexOf('_hover'))+'.png';
}
//-----------------------------------------------------------------------------
function ChangeWidthBigPart(){
    rightBox = searchDIV('smallPart2');
    mainBox = searchDIV('bigPart');
    middleBox = searchDIV('middlePart');
    if ( ( rightBox == null ) && ( middleBox != null ) ){
        if (document.location.href.indexOf('http') != -1 ){    
            middleBox.style.backgroundImage='url(/img/pink_line.png)';
        }
        else{
            middleBox.style.backgroundImage='url(img/pink_line.png)';
        }
        middleBox.style.backgroundRepeat="repeat-y";
    }
    if ( ( rightBox == null ) && ( mainBox != null ) ) 
        mainBox.style.width='762px';
}
//-----------------------------------------------------------------------------
// Declaring valid date character, minimum year and maximum year
var dtCh= "/";
function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}
//-----------------------------------------------------------------------------
function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}
//-----------------------------------------------------------------------------
function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
//-----------------------------------------------------------------------------
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}
//-----------------------------------------------------------------------------
function isDate(dtStr){
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strDay=dtStr.substring(0,pos1)
	var strMonth=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
    
    current_date = new Date();
    current_day =  current_date.getDate();
	current_month =  current_date.getMonth()+1;
	current_year =  current_date.getYear();
    if (current_year < 1000) 
        current_year +=1900;
    
    var minYear=current_year;
    var maxYear=current_year + 25;
    var current_date_formatted = current_day + "/" + current_month + "/" + current_year;
    var maxDate = "31/12/" + maxYear;
  
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) 
	    strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) 
	    strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++){
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
		alert("Please enter date using format dd/mm/yyyy.")
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		alert("Please enter valid month.")
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		alert("Please enter valid day.")
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		alert("Please enter valid year between "+ minYear +" and "+maxYear+".")
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		alert("Please enter valid date.")
		return false
	}
	if ( current_year > year ){
		alert("Please enter valid date between "+current_date_formatted+" and "+maxDate+".")
		return false
	}
	if ( current_year == year ){
		if ( current_month > month ){
		alert("Please enter valid date between "+current_date_formatted+" and "+maxDate+".")
		return false
		}
		if ( current_month == month ){
			if ( current_day > day ){
			alert("Please enter valid date between "+current_date_formatted+" and "+maxDate+".")
			return false
			}
		}
	}
	return true
}
//-----------------------------------------------------------------------------
//need rewrite to support on all used browsers
function GetElementById(id){
    var oElement = null;
    try
    {
         oElement = document.getElementById( id);
    }
    catch(e){
        oElement = null;
    }
    return oElement
}
//-----------------------------------------------------------------------------
function ConcatEventName(){
    var eventName1 = GetElementById("eventName1");
    var eventName2 = GetElementById("eventName2");
    var eventName3 = GetElementById("eventName3");
	var eventName4 = GetElementById("eventName4");
    var eventName5 = GetElementById("eventName5");
    var title = GetElementById("title");
      
    if( eventName1 == null || eventName2 == null || eventName3 == null || eventName4 == null || eventName5 == null || title == null){
        alert("Please contact site administrator.");
        return false;
    }   
    title.value = eventName1.value + ";" + eventName2.value + ";" + eventName3.value + ";" + eventName4.value + ";" + eventName5.value;
}
//-----------------------------------------------------------------------------
function ConcatDate(){
    var date1 = GetElementById("date1");
    var date2 = GetElementById("date2");
    var date3 = GetElementById("date3");
	var date4 = GetElementById("date4");
    var date5 = GetElementById("date5");
    var comments = GetElementById("comments");
      
    if( date1 == null || date2 == null || date3 == null || date4 == null || date5 == null || comments == null){
        alert("Please contact site administrator.");
        return false;
    }   
      
    comments.value = date1.value + ";" + date2.value + ";" + date3.value + ";" + date4.value + ";" + date5.value;
}
//-----------------------------------------------------------------------------
function ValidateForm(){
    try{  
        var userName = GetElementById("name");
        var email = GetElementById("email");
        var eventName = GetElementById("title");
        var date1 = GetElementById("date1");
        var date2 = GetElementById("date2");
        var date3 = GetElementById("date3");
	    var date4 = GetElementById("date4");
        var date5 = GetElementById("date5");
        var eventName1 = GetElementById("eventName1");
        var eventName2 = GetElementById("eventName2");
        var eventName3 = GetElementById("eventName3");
        var eventName4 = GetElementById("eventName4");
        var eventName5 = GetElementById("eventName5");
        if( eventName1 == null || eventName2 == null || eventName3 == null || eventName4 == null || eventName5 == null 
            || userName == null || email == null || eventName == null 
            || date1 == null || date2 == null || date3 == null || date4 == null || date5 == null)
        {
            alert("Please contact site administrator.");
            return false;
        }
        if ( userName.value=="" ){
            userName.focus();
            alert("Please enter name.");
		    return false;
		}
        if (email.value=="" ||
            email.value.indexOf('@') < 1 ||
            email.value.indexOf('@') == email.value.length - 1 ||
	 	    email.value.lastIndexOf('@') != email.value.indexOf('@') ||
	        email.value.indexOf('.') < 1 ||
	        email.value.indexOf('.') == email.value.length - 1 ||
	   	    email.value.lastIndexOf('.') < email.value.indexOf('@'))
	   	{
   	        email.focus();
            alert("Please enter valid e-mail address.");
  	        return false;
        }
        if (eventName1.value==""){
            eventName1.focus();
            alert("Please enter event name.");
            return false;
        }
        if (date1.value==""){
            date1.focus();
            alert("Please enter valid date for "+eventName1.value+" event.");
            return false;
        }
        if (date2.value=="" && eventName2.value!=""){
            date2.focus();
            alert("Please enter valid date for "+eventName2.value+" event.");
            return false;
        }
        if (date2.value!="" && eventName2.value==""){
            eventName2.focus();
            alert("Please enter event name for "+date2.value+" date.");
            return false;
        }
        if (date3.value=="" && eventName3.value!=""){
            date3.focus();
            alert("Please enter valid date for "+eventName3.value+" event.");
            return false;
        }
        if (date3.value!="" && eventName3.value==""){
            eventName3.focus();
            alert("Please enter event name for "+date3.value+" date.");
            return false;
        }
        if (date4.value=="" && eventName4.value!=""){
            date4.focus();
            alert("Please enter valid date for "+eventName4.value+" event.");
            return false;
        }
        if (date4.value!="" && eventName4.value==""){
            eventName4.focus();
            alert("Please enter event name for "+date4.value+" date.");
            return false;
        }
        if (date5.value=="" && eventName5.value!=""){
            date5.focus();
            alert("Please enter valid date for "+eventName5.value+" event.");
            return false;
        }
        if (date5.value!="" && eventName5.value==""){
            eventName5.focus();
            alert("Please enter event name for "+date5.value+" date.");
            return false;
        }
        if(date1.value != "" &&  isDate(date1.value)==false){
		    date1.focus()
		    return false;
	    }
	    if(date2.value != "" && isDate(date2.value)==false){
		    date2.focus()
		    return false;
	    }
	    if(date3.value != "" && isDate(date3.value)==false){
		    date3.focus()
		    return false;
		}
	    if(date4.value != "" && isDate(date4.value)==false){
		    date4.focus()
		    return false;
	    }
	    if(date5.value != "" && isDate(date5.value)==false){
		    date5.focus()
		    return false;
	    }
        ConcatEventName();
        ConcatDate();
        return true;
    }
    catch(e){
        alert(e.message);
    }
    return false;
}
//-----------------------------------------------------------------------------
function openAdditionalImagesWindow(url, maxImageWidth, maxImageHeight) {    
    window.open (url, "moreImagesWindow","location=0,resizable=1,status=1,scrollbars=1,width="+maxImageWidth+",height="+maxImageHeight); 
    }
//-----------------------------------------------------------------------------
function createLinkAndGo( url, pageAlias )
{
    var splittedUrl = url.split(",")
    var baseUrl = splittedUrl[0];    
    var sortDirection;
	if ( document.getElementById("psfoa").checked )
	{
		sortDirection = 'a';
	}
	else
	{
		sortDirection = 'd';
	}
	
	var productsPerPage = document.getElementById("productRPP").value;
	var brandId =  document.getElementById("pffv").value;
	var sortBy = document.getElementById("psf").value;
	var addition="";
	
	var newURL = baseUrl + "," + "1" + "," + productsPerPage + "," + sortBy + "," + sortDirection;
	
	if ( pageAlias != 'brands' )
	{
	    newURL = newURL + "," + 4 + "," + 31;
	    var addition;
	    if (brandId != "")
	    {
    	    addition = "," + brandId;
	    }    
	}	
	window.location = newURL + addition;
	return false;
}
//-----------------------------------------------------------------------------
function CheckIfCookiesEnabledInBrowser(){
    var cookieEnabled=(navigator.cookieEnabled)? true : false;

    if (typeof navigator.cookieEnabled=="undefined" && !cookieEnabled){ 
        document.cookie="testcookie";
        cookieEnabled=(document.cookie.indexOf("testcookie")!=-1)? true : false;
    }

    if (!cookieEnabled){
        alert("We have detected that cookies are disabled in your browser. Please enable cookies in your browser settings for the shopping cart to function properly.");
    }
}
//-----------------------------------------------------------------------------
var options = new Array();
var secondPriceOptions = new Array();
//-----------------------------------------------------------------------------
function select_onchange(selectedElementId) 
{
	var selectedElement = GetElementById(selectedElementId);
    var selectedItem = selectedElement.options[ selectedElement.selectedIndex ];
	options[selectedElementId] = selectedItem.getAttribute( "normalizedPrice" );	
	var normalizedPriceSecond = selectedItem.getAttribute( "normalizedPriceSecond" );
	if (normalizedPriceSecond != null){
	    secondPriceOptions[selectedElementId] = normalizedPriceSecond;
	}  	
	else
	{
	    secondPriceOptions[selectedElementId] = 0;
	}
	GetPrice();
}
//-----------------------------------------------------------------------------
function check_onclick(checkElementId)
{	
	var checkElement = GetElementById(checkElementId);
	var checkValue = checkElement.checked;
	if(checkValue == true)
	{
	  var normalizedPriceSecond = checkElement.getAttribute( "normalizedPriceSecond" );
	    if (normalizedPriceSecond != null){
	        secondPriceOptions[checkElementId] = normalizedPriceSecond;
	  }  	
	  else
	  {
	        secondPriceOptions[checkElementId] = 0;
	  }
      options[checkElementId] = checkElement.getAttribute( "normalizedPrice" );	
	   
	}
	else
	{
		options[checkElementId] = 0;
		secondPriceOptions[checkElementId] = 0;
	}
	GetPrice();
}
//-----------------------------------------------------------------------------
function GetPrice()
{
	var formattedPriceElement1 = GetElementById("formattedPrice1");
	var formattedPriceElement2 = GetElementById("formattedPrice2");
	var formattedPriceElement3 = GetElementById("formattedPrice3");
	
	
	if(formattedPriceElement1 == null && formattedPriceElement2 == null && formattedPriceElement3 == null)
	{
	    
	    return;
	}
	
	var formattedPriceElement = 0;
	var hiddenPrice = 0;
	if(formattedPriceElement1 != null)
	{
	       formattedPriceElement = formattedPriceElement1;
	    var hiddenPrice =  GetElementById("priceValue");
	}
	if(formattedPriceElement2 != null)
	{
	    formattedPriceElement = formattedPriceElement2;
	    var hiddenPrice =  GetElementById("priceWTaxValue");
	}
	if(formattedPriceElement3 != null)
	{
	    GetPriceBoth();
	    return;
	}
	
	
	var oldProductPrice = formattedPriceElement.innerHTML;
	var pricePrefix = GetPricePrefix(oldProductPrice);
	var optionsPrice = 0;
	var result;
	for (var i in options)
	{
	    result = parseFloat( options[i]);
	    if (!isNaN(result))
	    {
		optionsPrice +=	parseFloat( options[i]);
	}
	}

	 var priseSuffixsStringElement = GetElementById("priceSuffixString");
  	var suffixString = priseSuffixsStringElement.value;	
  	var decimalSeparatorElement = GetElementById("decimalSeparator");
  	var decimalSeparator =  decimalSeparatorElement.value;
  	var groupingSeparatorElement = GetElementById("groupingSeparator");
  	var groupingSeparator =  groupingSeparatorElement.value;  
  	var newPrice = formatCurrency(  (optionsPrice + parseFloat(hiddenPrice.value)), decimalSeparator , groupingSeparator);
  	formattedPriceElement.innerHTML = pricePrefix + " " + newPrice + suffixString ;
}
//-----------------------------------------------------------------------------
 function GetPriceBoth()
 {
	var formattedPriceElement = GetElementById("formattedPrice3");

	var hiddenPrice =  GetElementById("priceValue");
	var hiddenPriceWTax =  GetElementById("priceWTaxValue");
	
	var oldProductPrice = formattedPriceElement.innerHTML;
	var pricePrefix = GetPricePrefix(oldProductPrice);
	var optionsPrice = 0;
	var secondOptionsPrice = 0;
	var result;
	for (var i in options)
	{
	    result = parseFloat( options[i]);
	    if (!isNaN(result))
	    {
		optionsPrice +=	parseFloat( options[i]);
	}
	}
	for (var i in secondPriceOptions)
	{
	    result = parseFloat( options[i]);
	    if (!isNaN(result))
	    {
		secondOptionsPrice += parseFloat( secondPriceOptions[i]);
	}
	}
  	var priseSuffixsStringElement = GetElementById("priceSuffixString");
  	var suffixString = priseSuffixsStringElement.value;
	
  	var decimalSeparatorElement = GetElementById("decimalSeparator");
  	var decimalSeparator =  decimalSeparatorElement.value;

  	var groupingSeparatorElement = GetElementById("groupingSeparator");
  	var groupingSeparator =  groupingSeparatorElement.value;

	var newPrice = formatCurrency(  (optionsPrice + parseFloat(hiddenPrice.value)), decimalSeparator , groupingSeparator);
	var newPriceWTax = formatCurrency(  (secondOptionsPrice + parseFloat(hiddenPriceWTax.value)), decimalSeparator , groupingSeparator);
 
 	formattedPriceElement.innerHTML = pricePrefix + " " + newPrice + ", " + pricePrefix + " " + newPriceWTax + "&#160;&#160;&#160;" + suffixString ;
 }
//-----------------------------------------------------------------------------
function formatCurrency(num, decimalSep, groupingSep) 
{
      num = num.toString().replace(/\$|\,/g,'');
      if(isNaN(num))
      num = "0";
      sign = (num == (num = Math.abs(num)));
      num = Math.floor(num*100+0.50000000001);
      cents = num%100;      
      num = Math.floor(num/100).toString();
      if(cents<10)
      cents = "0" + cents;


      for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
      num = num.substring(0,num.length-(4*i+3))+groupingSep+
       num.substring(num.length-(4*i+3));
      return (((sign)?'':'-') + num + decimalSep + cents);
}
//-----------------------------------------------------------------------------
function GetPricePrefix(price)
{
	if( price.length == 0)
	{
		return "";
	}
	var pref = "";
	for (var i=0; i < price.length ; i++) 
	{
		var ch = price.charAt(i);
		if(ch == " ")
		{
			return pref;		
		}
		pref +=  ch;
	} 	
	
	return price.charAt(i);
}
//-----------------------------------------------------------------------------
function GetElementById(id)
{
 	var oElement = null;
  	try
  	{
     		oElement = document.getElementById( id);
  	}
	catch(e)
  	{
     		oElement = null;
  	}
  	return oElement
}
//-----------------------------------------------------------------------------
