function syncSelection(sourceId, targetId) {
	var
		source = document.getElementById(sourceId),
		target = document.getElementById(targetId);
	if ((source.selectedIndex != 0) && (target.selectedIndex == 0))
		target.selectedIndex = source.selectedIndex;
}

function showDetails(param) {
  var
    width = 500,
    height = 500,
    left = (screen.availWidth - width) / 2,
    top = (screen.availHeight - height) / 2;
  window.open("http://www.globel-cars.com/PopupDetails.aspx?mode=cargroup&" + param, null, "height=" + height + ",width=" + width + ",top=" + top + ",left=" + left + ",status=yes,toolbar=no,menubar=no,location=no,scrollbars=yes");
}    

function showAGB(param) {
  var
    width = 500,
    height = 500,
    left = (screen.availWidth - width) / 2,
    top = (screen.availHeight - height) / 2;
  window.open("http://www.globel-cars.com/PopupAGB.aspx?" + param, null, "height=" + height + ",width=" + width + ",top=" + top + ",left=" + left + ",status=yes,toolbar=no,menubar=no,location=no,scrollbars=yes");
}    

function showProvider(param) {
  var
    width = 500,
    height = 500,
    left = (screen.availWidth - width) / 2,
    top = (screen.availHeight - height) / 2;
  window.open("http://www.globel-cars.com/PopupProvider.aspx?mode=cargroup&" + param, null, "height=" + height + ",width=" + width + ",top=" + top + ",left=" + left + ",status=yes,toolbar=no,menubar=no,location=no,scrollbars=yes");
}

function showCODE(param) {
  var
    width = 550,
    height = 450,
    left = (screen.availWidth - width) / 2,
    top = (screen.availHeight - height) / 2;
  window.open("http://www.globel-cars.com/PopupCVV.aspx?" + param, null, "height=" + height + ",width=" + width + ",top=" + top + ",left=" + left + ",status=yes,toolbar=no,menubar=no,location=no,scrollbars=yes");
}   

function showINSURANCE(param) {
  var
    width = 400,
    height = 200,
    left = (screen.availWidth - width) / 2,
    top = (screen.availHeight - height) / 2;
  window.open("http://www.globel-cars.com/PopupInsurance.aspx?" + param, null, "height=" + height + ",width=" + width + ",top=" + top + ",left=" + left + ",status=yes,toolbar=no,menubar=no,location=no,scrollbars=no");
} 

function moveHint(e) {
	var x, y, hint;
  if (document.all) {
    x = window.event.x; 
    y = window.event.y; 
    if (document.documentElement && typeof(document.documentElement.scrollLeft) != 'undefined') { 
      x += document.documentElement.scrollLeft; 
      y += document.documentElement.scrollTop; 
    } else {
      if (document.body && typeof(document.body.scrollLeft) != 'undefined') { 
          x += document.body.scrollLeft; 
          y += document.body.scrollTop; 
      } 
    } 
  } else
    if (document.layers || document.getElementById) { 
      x = e.pageX; 
      y = e.pageY; 
  }
	hint = document.getElementById('hint');
	hint.style.left = (x + 16) + "px";
	hint.style.top = (y + 16) + "px";
}

function showHint(msg) {
	var hint;
	hint = document.getElementById('hint');
	hint.innerHTML = msg;
	hint.style.display = "block";
}

function hideHint() {
	var hint = document.getElementById('hint');
	hint.style.display = "none";
}

function showHideCreditCardData() {
  var insuranceElement = document.getElementById('ucReservation_cbInsurance');
  if (insuranceElement == null)
    insuranceElement = document.getElementById('ctl00_cphMain_ucReservation_cbInsurance');
  var paymentElement = document.getElementById('ucReservation_ddlPaymentType');
  if (paymentElement == null)
    paymentElement = document.getElementById('ctl00_cphMain_ucReservation_ddlPaymentType');
  var insurance = insuranceElement != null ? insuranceElement.checked : false;
  var payment = paymentElement != null ? paymentElement.options[paymentElement.selectedIndex].value : '1';
  var display = (insurance && ((payment != '8') && (payment != '16'))) || payment == '2' || payment == '4' ? '' : 'none';
  var elementIDs = ['trCreditCardType', 'trCreditCardExpire', 'trCreditCardHolder', 'trCreditCardNumber', 'trCreditCardVerificationCode'];
  var element;  
  for (var i = 0; i < elementIDs.length; i++) {
    if ((element = document.getElementById('ucReservation_' + elementIDs[i])) != null)
      element.style.display = display;
    if ((element = document.getElementById('ctl00_cphMain_ucReservation_' + elementIDs[i])) != null)
      element.style.display = display;
  }
}

function hideSubmitBtn() {
	var buttonLine = document.getElementById('buttonline');
	var inProgressLine = document.getElementById('inprogressline');
	inProgressLine.style.display = "";
	buttonLine.style.display = "none";
}

function showWaitingPage() {
	var waitContainter = document.getElementById('wait');
	var mainContainer = document.getElementById('main');
	waitContainter.style.display = "";
	mainContainer.style.display = "none";
}

function showWaitingPage2() {
	var waitContainter = document.getElementById('waitreservation');
	var mainContainer = document.getElementById('main');
	waitContainter.style.display = "";
	mainContainer.style.display = "none";
}

function filterOfferList() {
  var text = '';
  var ddl = document.getElementById('ucReservation$ucOfferList$ddlProvider');
  if (ddl == null)
    ddl = document.getElementById('ctl00_cphMain_ucReservation_ucOfferList_ddlProvider');
  var provider = ddl.options[ddl.selectedIndex].value + '-';
  ddl = document.getElementById('ucReservation_ucOfferList_ddlCarCategory');
  if (ddl == null)
    ddl = document.getElementById('ctl00_cphMain_ucReservation_ucOfferList_ddlCarCategory');
  var carCategory = '-' + ddl.options[ddl.selectedIndex].value + '-';
  var uniqueCarCodes = '';
	var table = document.getElementById('offer_content_list');
	for (var row = 1; row < table.rows.length; row++) {
	  var code = table.rows[row].cells[0].innerHTML;
    var visible = ((provider == '0-') || (provider == '00-') || (code.indexOf(provider) == 0)) && ((carCategory == '-0-') || (code.indexOf(carCategory) > 0))
    if (visible && (provider == '00-')) {
      var carCode = code.substring(code.lastIndexOf('#'), code.length);
      visible = uniqueCarCodes.indexOf(carCode) == -1;
      if (visible)
        uniqueCarCodes += carCode;
    }
	  if (visible)
	    table.rows[row].style.display = "";
	  else
	    table.rows[row].style.display = "none";
	}
}
