	/**
	*
	*  Base64 encode / decode
	*  <a href="http://www.webtoolkit.info/" title="http://www.webtoolkit.info/" class="liexternal">http://www.webtoolkit.info/</a>
	*
	**/
	  
	var Base64 = {
	  
	    // private property
	    _keyStr : "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",
	  
	    // public method for encoding
	    encode : function (input) {
	        var output = "";
	        var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
	        var i = 0;
	  
	        input = Base64._utf8_encode(input);
	  
	        while (i < input.length) {
	  
	            chr1 = input.charCodeAt(i++);
	            chr2 = input.charCodeAt(i++);
	            chr3 = input.charCodeAt(i++);
	  
	            enc1 = chr1 >> 2;
	            enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
	            enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
	            enc4 = chr3 & 63;
	  
	            if (isNaN(chr2)) {
	                enc3 = enc4 = 64;
	            } else if (isNaN(chr3)) {
	                enc4 = 64;
	            }
	  
	            output = output +
	            this._keyStr.charAt(enc1) + this._keyStr.charAt(enc2) +
	            this._keyStr.charAt(enc3) + this._keyStr.charAt(enc4);
	  
	        }
	  
	        return output;
	    },
	  
	    // public method for decoding
	    decode : function (input) {
	        var output = "";
	        var chr1, chr2, chr3;
	        var enc1, enc2, enc3, enc4;
	        var i = 0;
	  
	        input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
	  
	        while (i < input.length) {
	  
	            enc1 = this._keyStr.indexOf(input.charAt(i++));
	            enc2 = this._keyStr.indexOf(input.charAt(i++));
	            enc3 = this._keyStr.indexOf(input.charAt(i++));
	            enc4 = this._keyStr.indexOf(input.charAt(i++));
	  
	            chr1 = (enc1 << 2) | (enc2 >> 4);
	            chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
	            chr3 = ((enc3 & 3) << 6) | enc4;
	  
	            output = output + String.fromCharCode(chr1);
	  
	            if (enc3 != 64) {
	                output = output + String.fromCharCode(chr2);
	            }
	            if (enc4 != 64) {
	                output = output + String.fromCharCode(chr3);
	            }
	  
	        }
	  
	        output = Base64._utf8_decode(output);
	  
	        return output;
	  
	    },
	  
	    // private method for UTF-8 encoding
	    _utf8_encode : function (string) {
	        string = string.replace(/\r\n/g,"\n");
	        var utftext = "";
	  
	        for (var n = 0; n < string.length; n++) {
	  
	            var c = string.charCodeAt(n);
	  
	            if (c < 128) {
	                utftext += String.fromCharCode(c);
	            }
	            else if((c > 127) && (c < 2048)) {
	                utftext += String.fromCharCode((c >> 6) | 192);
	                utftext += String.fromCharCode((c & 63) | 128);
	            }
	            else {
	                utftext += String.fromCharCode((c >> 12) | 224);
	                utftext += String.fromCharCode(((c >> 6) & 63) | 128);
	                utftext += String.fromCharCode((c & 63) | 128);
	            }
	  
	        }
	  
	        return utftext;
	    },
	  
	    // private method for UTF-8 decoding
	    _utf8_decode : function (utftext) {
	        var string = "";
	        var i = 0;
	        var c = c1 = c2 = 0;
	  
	        while ( i < utftext.length ) {
	  
	            c = utftext.charCodeAt(i);
	  
	            if (c < 128) {
	                string += String.fromCharCode(c);
	                i++;
	            }
	            else if((c > 191) && (c < 224)) {
	                c2 = utftext.charCodeAt(i+1);
	                string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
	                i += 2;
	            }
	            else {
	                c2 = utftext.charCodeAt(i+1);
	                c3 = utftext.charCodeAt(i+2);
	                string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
	                i += 3;
	            }
	  
	        }
	  
	        return string;
	    }
	  
	}
	
/*
  $Id: general.js,v 1.11 2009/01/31 11:33:16 yura Exp $

  osCommerce, Open Source E-Commerce Solutions
  http://www.oscommerce.com

  Copyright (c) 2003 osCommerce

  Released under the GNU General Public License
*/

function SetFocus(TargetFormName) {
  var target = 0;
  if (TargetFormName != "") {
    for (i=0; i<document.forms.length; i++) {
      if (document.forms[i].name == TargetFormName) {
        target = i;
        break;
      }
    }
  }

  var TargetForm = document.forms[target];

  for (i=0; i<TargetForm.length; i++) {
    if ( (TargetForm.elements[i].type != "image") && (TargetForm.elements[i].type != "hidden") && (TargetForm.elements[i].type != "reset") && (TargetForm.elements[i].type != "submit") ) {
      TargetForm.elements[i].focus();

      if ( (TargetForm.elements[i].type == "text") || (TargetForm.elements[i].type == "password") ) {
        TargetForm.elements[i].select();
      }

      break;
    }
  }
}

function RemoveFormatString(TargetElement, FormatString) {
  if (TargetElement.value == FormatString) {
    TargetElement.value = "";
  }

  TargetElement.select();
}

function CheckDateRange(from, to) {
  if (Date.parse(from.value) <= Date.parse(to.value)) {
    return true;
  } else {
    return false;
  }
}

function IsValidDate(DateToCheck, FormatString) {
  var strDateToCheck;
  var strDateToCheckArray;
  var strFormatArray;
  var strFormatString;
  var strDay;
  var strMonth;
  var strYear;
  var intday;
  var intMonth;
  var intYear;
  var intDateSeparatorIdx = -1;
  var intFormatSeparatorIdx = -1;
  var strSeparatorArray = new Array("-"," ","/",".");
  var strMonthArray = new Array("jan","feb","mar","apr","may","jun","jul","aug","sep","oct","nov","dec");
  var intDaysArray = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);

  strDateToCheck = DateToCheck.toLowerCase();
  strFormatString = FormatString.toLowerCase();

  if (strDateToCheck.length != strFormatString.length) {
    return false;
  }

  for (i=0; i<strSeparatorArray.length; i++) {
    if (strFormatString.indexOf(strSeparatorArray[i]) != -1) {
      intFormatSeparatorIdx = i;
      break;
    }
  }

  for (i=0; i<strSeparatorArray.length; i++) {
    if (strDateToCheck.indexOf(strSeparatorArray[i]) != -1) {
      intDateSeparatorIdx = i;
      break;
    }
  }

  if (intDateSeparatorIdx != intFormatSeparatorIdx) {
    return false;
  }

  if (intDateSeparatorIdx != -1) {
    strFormatArray = strFormatString.split(strSeparatorArray[intFormatSeparatorIdx]);
    if (strFormatArray.length != 3) {
      return false;
    }

    strDateToCheckArray = strDateToCheck.split(strSeparatorArray[intDateSeparatorIdx]);
    if (strDateToCheckArray.length != 3) {
      return false;
    }

    for (i=0; i<strFormatArray.length; i++) {
      if (strFormatArray[i] == 'mm' || strFormatArray[i] == 'mmm') {
        strMonth = strDateToCheckArray[i];
      }

      if (strFormatArray[i] == 'dd') {
        strDay = strDateToCheckArray[i];
      }

      if (strFormatArray[i] == 'yyyy') {
        strYear = strDateToCheckArray[i];
      }
    }
  } else {
    if (FormatString.length > 7) {
      if (strFormatString.indexOf('mmm') == -1) {
        strMonth = strDateToCheck.substring(strFormatString.indexOf('mm'), 2);
      } else {
        strMonth = strDateToCheck.substring(strFormatString.indexOf('mmm'), 3);
      }

      strDay = strDateToCheck.substring(strFormatString.indexOf('dd'), 2);
      strYear = strDateToCheck.substring(strFormatString.indexOf('yyyy'), 2);
    } else {
      return false;
    }
  }

  if (strYear.length != 4) {
    return false;
  }

  intday = parseInt(strDay, 10);
  if (isNaN(intday)) {
    return false;
  }
  if (intday < 1) {
    return false;
  }

  intMonth = parseInt(strMonth, 10);
  if (isNaN(intMonth)) {
    for (i=0; i<strMonthArray.length; i++) {
      if (strMonth == strMonthArray[i]) {
        intMonth = i+1;
        break;
      }
    }
    if (isNaN(intMonth)) {
      return false;
    }
  }
  if (intMonth > 12 || intMonth < 1) {
    return false;
  }

  intYear = parseInt(strYear, 10);
  if (isNaN(intYear)) {
    return false;
  }
  if (IsLeapYear(intYear) == true) {
    intDaysArray[1] = 29;
  }

  if (intday > intDaysArray[intMonth - 1]) {
    return false;
  }

  return true;
}

function IsLeapYear(intYear) {
  if (intYear % 100 == 0) {
    if (intYear % 400 == 0) {
      return true;
    }
  } else {
    if ((intYear % 4) == 0) {
      return true;
    }
  }

  return false;
}

function popupWindow(url) {
  newwindow=window.open(url,'popupWindow','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,copyhistory=no,width=450,height=280,screenX=150,screenY=150,top=150,left=150')
  if (window.focus) newwindow.focus();
}

	function ValidateShop(form)
	{
		//check if the entered name is valid
		if (form.shop_code.value.length < 1)
		{
			error('Поле не должно быть пустым');
			return false;
		}
		else
		{
			error('');
			return true;
		}
	}

	function error(message)
	{
		//var error_message = document.getElementById('error_message');
		var error_messages = document.getElementsByName('error_message');
		for (var i = 0; i < error_messages.length; i++) {
			error_messages[i].innerHTML = message;
		}
	}

	function printpage() {
		window.print();
	}

//Expand - collapse functions
function showHide(elementID) {
    var desc = null;

    if (document.getElementById) {
      desc = document.getElementById("cnt_desc_" + elementID);
    } else if (document.all) {
      desc = document.all["cnt_desc_" + elementID];
    } else if (document.layers) {
      desc = document.layers["cnt_desc_" + elementID];
    }

    if (desc) {
      if (desc.style.display == 'none') {
        expand(elementID);
      } else {
        collapse(elementID);
      }
    }
  }

  function expand(elementID) {
    var cnt = null;
    var desc = null;
    var icon = null;

    if (document.getElementById) {
      cnt = document.getElementById("cnt_" + elementID);
      desc = document.getElementById("cnt_desc_" + elementID);
      icon = document.getElementById("cnt_icon_" + elementID);
    } else if (document.all) {
      cnt = document.all["cnt_" + elementID];
      desc = document.all["cnt_desc_" + elementID];
      icon = document.all["cnt_icon_" + elementID];
    } else if (document.layers) {
      cnt = document.layers["cnt_" + elementID];
      desc = document.layers["cnt_desc_" + elementID];
      icon = document.layers["cnt_icon_" + elementID];
    }

    if (desc.style.display == 'none') {
      /* cnt.style.backgroundColor = '#FFFAF3';
      cnt.style.border = '1px dotted #000000';
      cnt.style.padding = '5px';
      cnt.style.marginBottom = '5px'; */
      desc.style.display = 'block';
      icon.src = "images/icon_minus.gif"
    }
  }

  function collapse(elementID) {
    var cnt = null;
    var desc = null;
    var icon = null;

    if (document.getElementById) {
      cnt = document.getElementById("cnt_" + elementID);
      desc = document.getElementById("cnt_desc_" + elementID);
      icon = document.getElementById("cnt_icon_" + elementID);
    } else if (document.all) {
      cnt = document.all["cnt_" + elementID];
      desc = document.all["cnt_desc_" + elementID];
      icon = document.all["cnt_icon_" + elementID];
    } else if (document.layers) {
      cnt = document.layers["cnt_" + elementID];
      desc = document.layers["cnt_desc_" + elementID];
      icon = document.layers["cnt_icon_" + elementID];
    }

    if (desc.style.display != 'none') {
      /* cnt.style.backgroundColor = '';
      cnt.style.border = '';
      cnt.style.padding = '';
      cnt.style.marginBottom = ''; */
      desc.style.display = 'none';
      icon.src = "images/icon_plus.gif"
    }
  }

  function expandAll() {
    var cnt = null;

    if (document.body.getElementsByTagName) {
      cnt = document.body.getElementsByTagName('DIV');
    } else if (document.body.all) {
      cnt = document.body.all.tags('DIV');
    }

    if (cnt) {
      for (var i=0; i<cnt.length; i++) {
        if (cnt[i].id.substring(0, 4) == 'cnt_') {
          if (cnt[i].id.substring(0, 5) != 'cnt_d') {
            expand(cnt[i].id.substring(4));
          }
        }
      }
    }
  }

  function collapseAll() {
    var cnt = null;

    if (document.body.getElementsByTagName) {
      cnt = document.body.getElementsByTagName('DIV');
    } else if (document.body.all) {
      cnt = document.body.all.tags('DIV');
    }

    if (cnt) {
      for (var i=0; i<cnt.length; i++) {
        if (cnt[i].id.substring(0, 4) == 'cnt_') {
          if (cnt[i].id.substring(0, 5) != 'cnt_d') {
            collapse(cnt[i].id.substring(4));
          }
        }
      }
    }
  }
  
  
//Reviews Expand - collapse functions
function reviews_showHide(elementID) {
    var desc = null;

    if (document.getElementById) {
      desc = document.getElementById("reviews_desc_" + elementID);
    } else if (document.all) {
      desc = document.all["reviews_desc_" + elementID];
    } else if (document.layers) {
      desc = document.layers["reviews_desc_" + elementID];
    }

    if (desc) {
      if (desc.style.display == 'none') {
        reviews_expand(elementID);
      } else {
        reviews_collapse(elementID);
      }
    }
  }

  function reviews_expand(elementID) {
    var cnt = null;
    var desc = null;
    var icon = null;

    if (document.getElementById) {
      cnt = document.getElementById("reviews_" + elementID);
      desc = document.getElementById("reviews_desc_" + elementID);
      icon = document.getElementById("reviews_icon_" + elementID);
    } else if (document.all) {
      cnt = document.all["reviews_" + elementID];
      desc = document.all["reviews_desc_" + elementID];
      icon = document.all["reviews_icon_" + elementID];
    } else if (document.layers) {
      cnt = document.layers["reviews_" + elementID];
      desc = document.layers["reviews_desc_" + elementID];
      icon = document.layers["reviews_icon_" + elementID];
    }

    if (desc.style.display == 'none') {
      /* cnt.style.backgroundColor = '#FFFAF3';
      cnt.style.border = '1px dotted #000000';
      cnt.style.padding = '5px';
      cnt.style.marginBottom = '5px'; */
      desc.style.display = 'block';
      icon.src = "images/icon_minus.gif"
    }
  }

  function reviews_collapse(elementID) {
    var cnt = null;
    var desc = null;
    var icon = null;

    if (document.getElementById) {
      cnt = document.getElementById("reviews_" + elementID);
      desc = document.getElementById("reviews_desc_" + elementID);
      icon = document.getElementById("reviews_icon_" + elementID);
    } else if (document.all) {
      cnt = document.all["reviews_" + elementID];
      desc = document.all["reviews_desc_" + elementID];
      icon = document.all["reviews_icon_" + elementID];
    } else if (document.layers) {
      cnt = document.layers["reviews_" + elementID];
      desc = document.layers["reviews_desc_" + elementID];
      icon = document.layers["reviews_icon_" + elementID];
    }

    if (desc.style.display != 'none') {
      /* cnt.style.backgroundColor = '';
      cnt.style.border = '';
      cnt.style.padding = '';
      cnt.style.marginBottom = ''; */
      desc.style.display = 'none';
      icon.src = "images/icon_plus.gif"
    }
  }

  function reviews_expandAll() {
    var cnt = null;

    if (document.body.getElementsByTagName) {
      cnt = document.body.getElementsByTagName('DIV');
    } else if (document.body.all) {
      cnt = document.body.all.tags('DIV');
    }

    if (cnt) {
      for (var i=0; i<cnt.length; i++) {
		if (cnt[i].id.substring(0, 8) == 'reviews_') {
          if (cnt[i].id.substring(0, 9) != 'reviews_d') {
            reviews_expand(cnt[i].id.substring(8));
          }
        }
      }
    }
  }

  function reviews_collapseAll() {
    var cnt = null;

    if (document.body.getElementsByTagName) {
      cnt = document.body.getElementsByTagName('DIV');
    } else if (document.body.all) {
      cnt = document.body.all.tags('DIV');
    }

    if (cnt) {
      for (var i=0; i<cnt.length; i++) {
        if (cnt[i].id.substring(0, 8) == 'reviews_') {
          if (cnt[i].id.substring(0, 9) != 'reviews_d') {
            reviews_collapse(cnt[i].id.substring(8));
          }
        }
      }
    }
  }
  
  /**
   *
   * @access public
   * @return void
   **/
  function ShowTable(){
   	var showDiv = document.getElementById('tableBlock')
  	var hideDiv = document.getElementById('rollBlock')
  	var showLink = document.getElementById('tableLink')
  	var hideLink = document.getElementById('rollLink')
  	if(ShowHideTableRoll(showDiv, hideDiv, showLink, hideLink))
  	{
		showDiv.style.marginTop = '-20px';
		createCookie('showTableRoll', 'table', 7); //we save cookie for 7 days
	}

  }
  function ShowRoll(){
   	var hideDiv = document.getElementById('tableBlock')
  	var showDiv = document.getElementById('rollBlock')
  	var hideLink = document.getElementById('tableLink')
  	var showLink = document.getElementById('rollLink')
  	if(ShowHideTableRoll(showDiv, hideDiv, showLink, hideLink))
  		createCookie('showTableRoll', 'roll', 7); //we save cookie for 7 days
  }

  function ShowHideTableRoll(showDiv, hideDiv, showLink, hideLink){

	if ( showDiv != null && hideDiv != null && showLink != null && hideLink != null ) {
		showDiv.style.display = 'block';
  		showLink.disabled = true;

		hideDiv.style.display = 'none';
		hideLink.disabled = false;
		return true;
	}
  	return false;

  }

  /**
   *
   * @access public
   * @return void
   **/
  function tableRollInit(){
  	var cookie = readCookie('showTableRoll');
  	if ( cookie == 'table' ) {
		  ShowTable();
  	}
  	else if ( cookie == 'roll' ) {
		  ShowRoll();
  	}
  	else {
  		ShowRoll();
  	}
  }
//EOF expand-collapse functions
//Cookie functions
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 = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = 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);
}


function gallery(url) {
	window.open(url, 'Галерея','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,width=800,height=600,screenX=150,screenY=150,top=150,left=150')
}


function InitEmail() {
	Telligent_Modal.Configure('loading.htm',['CommonModal'],['CommonModalTitle'],['CommonModalClose'],['CommonModalContent'],['CommonModalFooter'],['CommonModalResize'],['CommonModalMask'],100000);
}

function SendEmail(customers_id, subject) {
	Telligent_Modal.Open('sendEmail.php?id='+customers_id+'&subject='+subject, 665, 450, MessageSent);
	/*
	var divs = document.getElementsByTagName('DIV');
	for (var i=0; i<divs.length;i++)
	{
		if (divs[i].className == 'CommonModalContent') {
			var iframe = divs[i].getElementsByTagName('IFRAME')[0];
			
			iframe.onload=function() {
				var doc = iframe.contentWindow.document;
				var status = doc.getElementById('status');
				if (status != null) {
					if ( status.value == 'sent' ) {
						Telligent_Modal.Close(true);
					} 
					else if (status.value != 'skip') {
						alert(status.value);
					}
				}
				
			};
			
			
			break;
		}
	}
	*/
}

function SendWrongInfo(cShop) {
	Telligent_Modal.Open('sendWrongInfo.php?cShop='+cShop+'&referer='+Base64.encode(document.location.href), 665, 500, MessageSent);	
}

function SendShopOwnerEmail(cShop, subject) {
	Telligent_Modal.Open('sendShopOwnerEmail.php?cShop='+cShop+'&subject='+subject, 665, 500, MessageSent);
}

function SendHelpEmail(subject) {
	Telligent_Modal.Open('sendHelpEmail.php?subject='+subject, 665, 500, MessageSent);
}

function _seLoaded(){

}
function MessageSent(res){
	if (res){alert('Сообщение успешно отправлено.');}
}

function frame_resize() {
	var frame = parent.document.getElementById( "gallery_frame");  
	if (frame != null) {
		var framedoc = frame.contentWindow.document;
		frame.height = framedoc.body.scrollHeight; //offsetHeight
	}
}

function TrimString(sInString){
	sInString = sInString.replace(/ /g, ' ');
	return sInString.replace(/(^\s+)|(\s+$)/g, "");
}

function QuoteString(sInString){
	//[a-zA-Zа-яА-Я\-_ \s0-9]+
	reg=/".+"/
	if (reg.test(sInString))
		return sInString;
	else
		return '"'+sInString+'"';
}

function GetWindowWidth() {
  var myWidth = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
  } else if( document.documentElement && ( document.documentElement.clientWidth ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
  } else if( document.body && ( document.body.clientWidth) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
  }
  return myWidth;
}
function ShowSideBlocks(minWidth) {
	var side_blocks = document.getElementById("side_blocks");
	if (side_blocks != null) {
		side_blocks.style.display = (GetWindowWidth() < minWidth) ? 'none' : 'block';
	}
}
