///////////////////////////////////////////////////////////////////////////
//
// Start up
//
///////////////////////////////////////////////////////////////////////////

  addEvent(window, 'load', initPage);

  function initPage() {

    var o ;
    o = document.getElementById('page_content') ;
    var sideHeights = o.offsetHeight - 63 ;

    if (sideHeights < 300) {
      sideHeights = 300 ;
    }

    jQuery('#page_content_inner').css('height', sideHeights) ;
    jQuery('#navigation').css('height', sideHeights-60) ;
    jQuery('#right_navigation_inner').css('height', sideHeights+3) ;

    var settings = {
      tl: { radius: 8 },
      tr: { radius: 8 },
      bl: { radius: 8 },
      br: { radius: 8 },
      antiAlias: true
    }

    curvyCorners(settings, "#page_content");
    curvyCorners(settings, "#page_content_inner");


    var settings = {
      tl: { radius: 5 },
      tr: { radius: 5 },
      bl: { radius: 5 },
      br: { radius: 5 },
      antiAlias: true
    }

    curvyCorners(settings, "#udsl_logo");
    curvyCorners(settings, "div.rounded");
    curvyCorners(settings, "#page_header");
    curvyCorners(settings, "#navigation");
    curvyCorners(settings, "#navigation a");

    curvyCorners(settings, "#right_navigation_inner");
    curvyCorners(settings, "#right_navigation a");

    var settings = {
      tl: { radius: 4 },
      tr: { radius: 4 },
      bl: { radius: 0 },
      br: { radius: 0 },
      antiAlias: true
    }

    curvyCorners(settings, "#right_navigation h1");

    Cufon.replace('#page_top_pannel h1') ;
    Cufon.replace('#page_top_pannel h2') ;
    Cufon.replace('#page_top_pannel h3') ;
}



///////////////////////////////////////////////////////////////////////////
//
// AJAX
//
///////////////////////////////////////////////////////////////////////////



function registerMemberCallback(responce) {
  if (!processResponceErrors(responce, 'errorDiv')) { 
    doc = parseXML(unescape(responce)) ;

    var result;
    result = doc.getElementsByTagName('result') ;   
    result = result[0] ;

    var addDeliveryAddress ;
    addDeliveryAddress = result.getAttribute('adddelivery') ;
    var redirect ;
    redirect = result.getAttribute('redirect') ;

    if (addDeliveryAddress=='yes') {
      jQuery("#register_member").fadeOut();  
      jQuery("#delivery_address").fadeIn();  
    }
    else {
      if (redirect=="shop/paynow") {
        window.location = '/shop/paynow.html' ;
      }
      else {
        window.location.reload(true) ;      
      }
    }
  }
}

function loginCallback(responce) {
  if (!processResponceErrors(responce, 'loginErrorDiv')) { 
    doc = parseXML(unescape(responce)) ;

    var result;
    result = doc.getElementsByTagName('result') ;   
    result = result[0] ;

    var loggedin ;
    loggedin = result.getAttribute('loggedin') ;

    var redirect ;
    redirect = result.getAttribute('redirect') ;

    if (loggedin=='yes') {
      var o ;
      o = document.getElementById('loginErrorDiv') ;
      o.innerHTML = '&nbsp;' ;

      if (redirect=="shop/paynow") {
        window.location = '/shop/paynow.html' ;
      }
      else {
        window.location = '/members/' ;      
      }
    }
    else {
      var o ;
      o = document.getElementById('loginErrorDiv') ;
      o.innerHTML = '<b>Uknown Email Address and Password</b>' ;
    }
  }
}

var popupStatus = 0;

function contactusCallback(responce) {
  if (!processResponceErrors(responce, 'errorDiv')) {
    var o ;
    o = document.getElementById('errorDiv') ;
    o.innerHTML = 'Thank you for your Query.<br><br>We aim to answer all quiries within 48hours.' ;
  }
  if(popupStatus==0){
    $("#backgroundPopup").css({"opacity": "0.7" });
    $("#backgroundPopup").fadeIn("slow");
    $("#errorPopup").fadeIn("slow");
    popupStatus = 1;
  }
}

function closePopup(){
  if(popupStatus==1){
    $("#errorPopup").fadeOut("slow");
    $("#backgroundPopup").fadeOut("slow");
//    $("#backgroundPopup").css({"opacity": "0.7" });
    popupStatus = 0;
  }
}