function popupWindow(url) {
  window.open(url,'popupWindow','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,width=600,height=300,screenX=150,screenY=150,top=150,left=150')
}

function rowOverEffect(object) {
  if (object.className == 'moduleRow') object.className = 'moduleRowOver';
}

function rowOutEffect(object) {
  if (object.className == 'moduleRowOver') object.className = 'moduleRow';
}

function checkBox2(object) {
  document.account_notifications.elements[object].checked = !document.account_notifications.elements[object].checked;
}

function checkBox(object) {
  document.account_newsletter.elements[object].checked = !document.account_newsletter.elements[object].checked;
}

function show_gal(url, order, width, height) {
	window.open("recenze/index.php?img_folder="+url+"&first="+order,"foto","width="+width+",height="+height+",status=1,statusbar=1,toolbar=0,menubar=0,location=0,directories=0,resizable=1,scrollbars=0");
	return false;
}

function validate_review(frm) {
  var error = 0;
  var error_message = "Ve vyplnění formuláře byla nalezena chyba!\nProveďte prosím následující opravy:\n\n";


  if ((document.reviews.rating[0].checked) || (document.reviews.rating[1].checked) || (document.reviews.rating[2].checked) || (document.reviews.rating[3].checked) || (document.reviews.rating[4].checked)) {
  } else {
    error_message = error_message + "* není vybráno hodnocení recenze\n";
    error = 1;
  }

  if (error == 1) {
    alert(error_message);
    return false;
  } else {
    return true;
  }
}

function otevri_okno(url, width, height) {
	window.open("foto.php?img="+url,"foto","width="+width+",height="+height+",status=1,statusbar=1,toolbar=0,menubar=0,location=0,directories=0,resizable=1,scrollbars=0");
	return false;
}

// stripe tables
window.onload = init;

function init() {
	//stripeTableById('list');
	stripeAllTables();
}

function stripeTable(t) {
	var i, odd = true;
	for (i=0; i<t.rows.length; i++) {
		t.rows[i].className += odd ? ' odd' : ' even';
	 odd = !odd;
  }
}
	
function stripeTableById(id) {
	t = document.getElementById(id);
	if (t) stripeTable(t);
}

function stripeAllTables() {
	t = document.getElementsByTagName('TABLE');
	for (var i=0; i<t.length; i++) if (t[i].id=='list') stripeTable(t[i]);
}

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 validate_stock_form(frm) {

  if (frm.elements['stock_delivery_info'].checked == false && frm.elements['stock_contact_me'].checked == false && frm.elements['stock_make_reservation'].checked == false) {
    alert('Chyba, není vybrána žádná akce, kterou chcete učinit!');
		return false;
  }

	if(frm.elements['name'].value == '') {
		alert('Je nutné vyplnit pole JMÉNO, PŘIJMENÍ');
		frm.elements['name'].select();
		return false;
	}
	
	if(frm.elements['email'].value == '') {
		alert('Je nutné vyplnit pole EMAIL');
		frm.elements['email'].select();
		return false;
	}
	
	if(frm.elements['phone'].value == '') {
		alert('Je nutné vyplnit pole TELEFON');
		frm.elements['phone'].select();
		return false;
	}	
	
	if(frm.elements['quantity'].value == '') {
		alert('Je nutné vyplnit pole POTŘEBUJI');
		frm.elements['quantity'].select();
		return false;
	}	
	
	if(frm.elements['kod'].value == '') {
		alert('Je nutné vyplnit BEZPEČNOSTNÍ KÓD');
		frm.elements['kod'].select();
		return false;
	}	

	return true;
}


function validate_ask_seller_form(frm) {

	if(frm.elements['name'].value == '') {
		alert('Je nutno vyplnit pole JMENO');
		frm.elements['name'].select();
		return false;
	}
	
	if(frm.elements['email'].value == '') {
		alert('Je nutno vyplnit pole EMAIL');
		frm.elements['email'].select();
		return false;
	}
	
	if(frm.elements['enquiry'].value == '') {
		alert('Je nutné vyplnit DOTAZ');
		frm.elements['enquiry'].select();
		return false;
	}	
	
	if(frm.elements['kod'].value == '') {
		alert('Je nutné vyplnit BEZPECNOSTNI KOD');
		frm.elements['kod'].select();
		return false;
	}	

	return true;
}

function validate_discuss(frm) {

	if(frm.elements['name'].value == '') {
		alert('Je nutno vyplnit pole JMENO');
		frm.elements['name'].select();
		return false;
	}
	
	if(frm.elements['email'].value == '') {
		alert('Je nutno vyplnit pole EMAIL');
		frm.elements['email'].select();
		return false;
	}
	
	if(frm.elements['title'].value == '') {
		alert('Je nutno vyplnit pole NADPIS');
		frm.elements['title'].select();
		return false;
	}
	
	if(frm.elements['kod'].value == '') {
		alert('Je nutné vyplnit BEZPECNOSTNI KOD');
		frm.elements['kod'].select();
		return false;
	}	

	return true;
}

