{
var CONST_Contents 		      = '';
var CONST_arrImages		      = [];
var CONST_blnHasDimension   = false;
var CONST_intMenuTop        = 274;
var CONST_intMenuHeight     = 400;
var CONST_blnBrowserIE      = (navigator.appName == 'Microsoft Internet Explorer');

}

function Clicked_Menu(p_strLocation){
  if (p_strLocation == '') p_strLocation = 'home.asp';
  window.setTimeout("document.getElementById('ifrmContents').src = '" + unescape(p_strLocation) + "'", 1);
}

function onBodyRightClick() {
  //disabled right onclick on website
  //alert(event.button)
  //if (event.button!=0) return; 
}

function onIframeLoad(){
  document.getElementById('divContents').innerHTML = document.getElementById('ifrmContents').contentWindow.document.body.innerHTML;
  window.setTimeout("document.getElementById('tblMenu').style.height = (document.getElementById('tblContents').scrollHeight > CONST_intMenuHeight) ? document.getElementById('tblContents').scrollHeight + 5 : CONST_intMenuHeight;", 10);
  document.getElementById('divMenu').style.top = CONST_intMenuTop;
  self.top.scroll(0,0);
}
  
function Trim(szStr, bShowChars) 
 {
   var ichar, icount;
   var szTrimmed = new String (szStr);

   if (bShowChars) 
   {
     ichar = szTrimmed.length - 1;
     icount = -1;
     while (ichar > icount)
     {
       alert (ichar + " of " + szTrimmed.length + "\n'" + szTrimmed.charCodeAt (ichar) + "'");
       --ichar;
     }
   }
    
   ichar = szTrimmed.length - 1;
   icount = -1;
   while (((szTrimmed.charAt (ichar) == ' ') ||
         (szTrimmed.charCodeAt (ichar) == 13) ||
         (szTrimmed.charCodeAt (ichar) == 10)) &&
         (ichar > icount))
   {
      --ichar;
   }
   if (ichar != (szTrimmed.length - 1))
   {
     szTrimmed = szTrimmed.substring (0, ichar);
   }
    
   ichar = 0;
   icount = szTrimmed.length - 1;
   while (((szTrimmed.charAt (ichar) == ' ') ||
         (szTrimmed.charCodeAt (ichar) == 13) ||
         (szTrimmed.charCodeAt (ichar) == 10)) && 
         (ichar < icount))
   {
     ++ichar;
   }
   if (ichar != 0)
   {
     szTrimmed = szTrimmed.substr (ichar - 1);
   }
    
   return szTrimmed;
}

function AllowedChars (szAllowed, szToCheck)
{
  var bOK = true;
  var i, j, ch;

  for (var i = 0;  i < szToCheck.length;  i++)
  {
    ch = szToCheck.charAt(i);
   
    for (var j = 0;  j < szAllowed.length;  j++)
    {
      if (ch == szAllowed.charAt(j))
      {
        break;
      }
    }
    
    if (j == szAllowed.length)
    {
      bOK = false;
      break;
    }
  }
  
  return (bOK);
}

function MoveMenu(p_objMenu) {
  if(parseInt(document.getElementById('tblMenu').style.height) < parseInt(document.getElementById('tblContents').scrollHeight)) document.getElementById('tblMenu').style.height = (document.getElementById('tblContents').scrollHeight > CONST_intMenuHeight) ? document.getElementById('tblContents').scrollHeight : CONST_intMenuHeight;
  if (CONST_intMenuTop + parseInt(window.document.body.scrollTop) < parseInt(document.getElementById('tblContents').clientHeight)) p_objMenu.style.top = CONST_intMenuTop + parseInt(window.document.body.scrollTop);
}

function ShowHide(p_objToMove, p_objButton, p_strShowText, p_strHideText) {
  if (p_objToMove.style.display == 'none') {
    p_objToMove.style.display = 'block';
    p_objButton.value = p_strShowText;
  }
  else {
    p_objToMove.style.display = 'none';
    p_objButton.value = p_strHideText;
  }
}

function SelectProduct(p_strProductId) {
  this.document.frmShop.action = this.document.location + '?productname=' + p_strProductId;
  document.frmShop.submit();
  //document.getElementById('ifrmContents').src = document.getElementById('ifrmContents').src + '?productname=' + p_strProductId;
}

function GetAccessories(p_objDimension){
  var objElements = document.getElementsByTagName('input');
  CONST_blnHasDimension = true;
  for (var i = 0;  i < objElements.length;  i++) {
    if(objElements[i].type == 'checkbox'){
      //if(objElements[i].additional == 'true') {
        objElements[i].checked = false;
        document.getElementById(objElements[i].id).style.display = 'none';
        if (p_objDimension.value.indexOf(objElements[i].title) > -1) {
          //objElements[i].checked = true;
          document.getElementById(objElements[i].id).style.display = 'block';
        }
      //}
    }
  }
}

function GetColours(p_objActivForm, strDisabledForms){
  var objDisabledForms = strDisabledForms.split(',');

  for (var i = 0; i < objDisabledForms.length; i++) {
    if (document.getElementById(objDisabledForms[i].toUpperCase() + '_colours')) document.getElementById(objDisabledForms[i].toUpperCase() + '_colours').style.display = 'none';
  }
  if (document.getElementById(p_objActivForm.id + '_colours')) document.getElementById(p_objActivForm.id + '_colours').style.display = 'block';
}

function GetColourCode(p_strColorCode, p_strColorName, p_strColorDescription){
  document.frmShop.ColourCode.value = p_strColorCode;
  document.frmShop.ColourName.value = p_strColorName;
  document.frmShop.ColourDescription.value = p_strColorDescription;
}

function AddItem(p_strAction, p_strLocation) {
  if ((!CONST_blnHasDimension || document.frmShop.ColourName.value == '') && document.getElementById('dimention')) {
    alert('Please select an item or colour.')
    return false;  
  }

  document.frmShop.SubmitAction.value = p_strAction;
  document.frmShop.action = p_strLocation; 
  document.frmShop.submit();
}

function ChangeHeightParent(p_intHeight) {
  try {
      this.top.document.getElementById('ShopContainer').style.height = p_intHeight;
      top.document.getElementById('tblMenu').style.height = ((p_intHeight < 370) ? 370 : p_intHeight);
;
  } catch (objExecption) {}
}

function SubmitForm(p_strSubmitAction) {
  if (p_strSubmitAction == "") return;

  switch(p_strSubmitAction)
  {
    case 'Register' : if(!IsAlphaNumeric ('str_First_name', 'first name',true)) return;
                      if(!IsAlphaNumeric ('str_Last_name', 'last name',true)) return;
                      if(!IsEmail ('str_Email',true)) return;
                      if(!IsAlphaNumeric ('str_Website', 'website address',false)) return;
                      if(!IsAlphaNumeric ('str_Password', 'password',true)) return;
                      if(!IsAlphaNumeric ('str_Password_confirm', 'password confirmation',true)) return;
                      if(document.getElementById('str_Password').value != document.getElementById('str_Password_confirm').value) {
                          alert('Your password and password confirmation entries are different')
                          document.getElementById('str_Password').focus();
                          return false;
                      }
                      if(!IsAlphaNumeric ('str_Address_line_1', 'first address entry',true)) return;
                      if(!IsAlphaNumeric ('str_Address_line_2', 'second address entry',false)) return;
                      if(!IsAlphaNumeric ('str_Address_line_3', 'third address entry',false)) return;
                      if(!IsAlphaNumeric ('str_Town_or_city', 'town or city',true)) return;
                      if(!IsAlphaNumeric ('str_Postal_code', 'postal code',true)) return;
                      if(!IsAlphaNumeric ('str_Country', 'country',false)) return;
                      if((!IsNumeric ('str_Home_Telno', 'any phone number',false)) || (!IsNumeric ('str_Work_Telno', 'any phone number',false)) || (!IsNumeric ('str_Cellno', 'any phone number',false))) return;
                      if(!document.getElementById('blnTerms').checked) {
                          alert('You hace not accepted the terms and conditions. Please read them and if you agree to the terms and conditions, tick the box.')
                          document.getElementById('blnTerms').focus();
                          return false;
                      }
                      break;
      
    case 'Payment'  : break;
                      
    case 'SendQuote' : if(!IsEmail ('str_Email',true)) return;
                      if(!IsEmail ('str_Email_Confirm',true)) return;
                      if(!IsAlphaNumeric ('str_ClientType', 'type of client',true)) return;
                      if(!IsAlphaNumeric ('str_Province', 'province',true)) return;
                      if(document.getElementById('str_Province').value == 'other' && !IsAlphaNumeric ('str_OtherRegion', 'other region or country',true)) return;
                      
                      if(document.getElementById('str_Email').value != document.getElementById('str_Email_Confirm').value) {
                        alert('Your email entries are different. Please make sure you have entered your email addresses correctly.')
                        document.getElementById('str_Email').focus();
                        return false;
                      }
                      document.getElementById('EmailBody').value = unescape('<b>Client is:</b> ' + document.getElementById('str_ClientType').value + '<p/>' + '<b>Province:</b> ' + document.getElementById('str_Province').value + '<p/>' + (document.getElementById('str_OtherRegion').value != '' ? '<b>Other region/country:</b> ' + document.getElementById('str_OtherRegion').value + '<p/>' : '') + document.getElementById('QuoteTable').innerHTML);
                      //alert(document.getElementById('QuoteTable').innerHTML)
                      break;
                                            
    default         : if(!IsEmail ('str_Username',true)) return;
                      if(!IsAlphaNumeric ('str_PSW', 'password',true)) return;
                      break;
    }
   
  document.getElementById('SubmitAction').value = p_strSubmitAction;
  document.frmLogin.submit();
}

function LogOut(p_strLocation) {
  if (confirm('Are you sure you want to log out?')) {
    if (document.getElementById('SubmitAction')) document.getElementById('SubmitAction').value == '';
    document.location = p_strLocation + '?SubmitAction=LogOut';
  }
}

function initImage(p_strImageSrc) {
  image = document.getElementById('thephoto');
  image.src = p_strImageSrc;
  imageholder = document.getElementById('photoholder');
  imageholder.style.top = parseInt(document.getElementById('divMenu').style.top) - 150;
  imageholder.style.left = 600;
  setOpacity(imageholder, 0);
  imageholder.style.visibility = 'visible';
  imageholder.style.display = 'block';
  fadeIn('photoholder',0);
}

function setOpacity(obj, opacity) {
  opacity = (opacity == 100)?99.999:opacity;
  
  // IE/Win
  obj.style.filter = "alpha(opacity:"+opacity+")";
  
  // Safari<1.2, Konqueror
  obj.style.KHTMLOpacity = opacity/100;
  
  // Older Mozilla and Firefox
  obj.style.MozOpacity = opacity/100;
  
  // Safari 1.2, newer Firefox and Mozilla, CSS3
  obj.style.opacity = opacity/100;
}

function fadeIn(objId,opacity) {
  if (document.getElementById) {
    obj = document.getElementById(objId);
    if (opacity <= 100) {
      setOpacity(obj, opacity);
      opacity += 5;
      window.setTimeout("fadeIn('"+objId+"',"+opacity+")", 100);
    }
  }
}

function SwitchLanguage(p_strLanguage, p_objLanguage) {
    var objLanguageCode = document.getElementById('Language');
    
    //if (objLanguageCode.value == p_strLanguage) p_objLanguage.disabled = true ; return;
    objLanguageCode.value = p_strLanguage; 
    frmHome.submit();
}

function onRegionChange(objRegion) {
    if (objRegion.value == 'other') {
        if (CONST_blnBrowserIE) {
            document.getElementById('tr_OtherRegion').style.display = 'block';
        }
        else {
            document.getElementById('tr_OtherRegion').style.visibility = 'visible';
        }
    }
    else {
        if (CONST_blnBrowserIE) {
            document.getElementById('tr_OtherRegion').style.display = 'none';
        }
        else {
            document.getElementById('tr_OtherRegion').style.visibility = 'collapse';
        }
        document.getElementById('str_OtherRegion').value = '';
    }
}

function onRegionLoad() {
    if (CONST_blnBrowserIE) {
        document.getElementById('tr_OtherRegion').style.display = 'none';
    }
    else {
        document.getElementById('tr_OtherRegion').style.visibility = 'collapse';
      }
    }
    
function showPreviews(p_ObjImage, p_ImgPreview, p_PrevDescription, p_ProductID) {
  document.getElementById('imgPreview').src = p_ImgPreview; 
  GetColours(p_ObjImage,'no,mini,maxi,classico,quadro,delta,colado,cottage,trend_column,trend_round');
  document.getElementById('txtPreview').innerHTML = 'Preview for ' + p_PrevDescription;
  
  if (document.getElementById('imgGallery').style.display == 'block') {
    document.getElementById('imgGallery').style.display = 'none';
    document.getElementById('gallery_' + p_ProductID + '_1').style.display = 'block';
  }
}