/*
  $Id: general.js,v 1.1.1.1 2004/11/26 17:41:45 sam Exp $
  Script Connector? CastleKart, Open Source E-Commerce Solutions
  http://www.scriptconnector.org/
  Copyright (c) 2004-2005 Script Connector? Corporation
  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;
    }
  }


  function view()
  {
    var pos_x;
    var pos_y;
    w=800;
    h=600;
    pos_x = (screen.width - w+18)/2;
    pos_y = (screen.height - h+75)/2;

    window.open("./compare.php","Porównywarka", "width="+(w+90)+",pozx=300,height="+(h+80)+",resizable=yes,scrollbars=yes,menubar=no,status=0,toolbar=0,left="+pos_x+",top="+pos_y);
  }


	
	
  function delete_compare(products_id) {


        jQuery.ajax ({
           url: "jquery_functions.php",
           data: "action=remove_2compare&pid="+products_id,
           dataType: "html",
           type: "get",
           success: function() {
		jQuery("#comparator").load("./compare_box.php");
           }
        });

  }


  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;
}

//loader dla fotki głównej
function showImages() {
document.getElementById('loader-image').style.display='none';
document.getElementById('turnon_foto').style.display='none';
}

function openCatPart(elem) {
var element = elem;
if(document.getElementById(element).style.display == "none") {
    document.getElementById(element).style.display = "block";
    document.getElementById(element+'_st').src = "./images/grafika/str_down.png";
}
else {
    document.getElementById(element).style.display = "none";
    document.getElementById(element+'_st').src = "./images/grafika/st_right.png";
}
}


jQuery.noConflict();

jQuery(document).ready(function() {


// 	if(document.all && (/msie 6./i).test(navigator.appVersion) && window.ActiveXObject) {
// 
// 	  alert("Przeglądarka której używasz nie wyświetla poprawnie tej strony. Uaktualnij wersję przegladarki lub zmień na inną.");
// 
// 	}

//alert(Math.round(100.1227234*Math.pow(10,3))/Math.pow(10,3));
	var highlights = jQuery('#listingGallOpen');
	var highlights_in = jQuery('#help_open');
	lang_id = document.getElementById('lang').value;

			if(lang_id == 1)
			  w = 120;
			else
			  w = 90;
	
		jQuery('#listingGallView').mouseover(function() {

			jQuery(highlights).stop(true).animate({
				opacity: 1,
				width: '241px',
				height: '402px'
			}, 500);

			jQuery("#products_info_name_cube").css('overflow', 'visible');
			jQuery("#products_info_cube").css('overflow', 'visible');
			jQuery("#products_info_cube").css('height', 'auto');
			jQuery("#products_info_cube").show();
		}).mouseout(function(){

			jQuery("#products_info_name_cube").css('overflow', 'visible');
			jQuery("#products_info_cube").css('overflow', 'hidden');
			//jQuery("#products_info_cube").hide();
			jQuery(highlights).stop().animate({
				opacity: 1,
				width: (width_take<w?w:width_take)+'px',
				height: '87px'
			}, 500);
			jQuery("#products_info_cube").css('height', '40');
		});

	
		jQuery('#help_open').mouseover(function() {
			jQuery(highlights).stop(true).animate({
				opacity: 1,
				width: '241px',
				height: '402px'
			}, 500);
			jQuery("#products_info_name_cube").css('overflow', 'visible');
			jQuery("#products_info_cube").css('overflow', 'visible');
			jQuery("#products_info_cube").css('height', 'auto');
			jQuery("#products_info_cube").show();
		}).mouseout(function(){
			jQuery("#products_info_name_cube").css('overflow', 'visible');
			jQuery("#products_info_cube").css('overflow', 'hidden');
			//jQuery("#products_info_cube").hide();
			jQuery(highlights).stop().animate({
				opacity: 1,
				width: (width_take<w?w:width_take)+'px',
				height: '87px'
			}, 500);
			jQuery("#products_info_cube").css('height', '40');
		});

//linijka slide

/*
		jQuery('#linijka').mouseover(function() {
			window.open("./compare.php","Porównywarka", "width="+(w+90)+",pozx=300,height="+(h+80)+",resizable=yes,scrollbars=yes,menubar=no,status=0,toolbar=0,left="+pos_x+",top="+pos_y);
		}).mouseout(function(){
			jQuery("#linijka_show").hide("slide", { direction: "up" }, 500);
		}); */

// ruchome menu
	var _ona = jQuery('#mLista_ona');
	var _on = jQuery('#mLista_on');
	var _bag = jQuery('#mLista_bag');
	var _akc = jQuery('#mLista_akc');
	
		jQuery('#ul_ona').mouseover(function() {
			var img_dlugosc = document.getElementById("_ona").offsetWidth;
			var ul_dlugosc = document.getElementById("ul_ona").offsetWidth;


			var ods = ((ul_dlugosc-img_dlugosc)/2);

			//document.getElementById("div_linka_ona").style.left = ods;	
			document.getElementById("div_linka_ona_ab").style.display = "block";			
			document.getElementById("mLista_ona").style.display = "block";
			document.getElementById("line_white_ona").style.width = img_dlugosc;	
			document.getElementById("line_white_ona").style.height = 1;			
			//jQuery(_ona).show("slide", { direction: "up" }, 200);
		}).mouseout(function(){
			document.getElementById("div_linka_ona_ab").style.display = "none";			
			document.getElementById("mLista_ona").style.display = "none";
			document.getElementById("line_white_ona").style.width = 0;			
			document.getElementById("line_white_ona").style.height = 0;			
		});

		jQuery('#ul_on').mouseover(function() {
			var img_dlugosc = document.getElementById("_on").offsetWidth;
			var ul_dlugosc = document.getElementById("ul_on").offsetWidth;


			var ods = ((ul_dlugosc-img_dlugosc)/2);

			//document.getElementById("div_linka_on").style.left = ods;			
			document.getElementById("div_linka_on_ab").style.display = "block";			
			document.getElementById("mLista_on").style.display = "block";
			document.getElementById("line_white_on").style.width = img_dlugosc;	
			document.getElementById("line_white_on").style.height = 1;
			//jQuery(_on).show("slide", { direction: "up" }, 200);
		}).mouseout(function(){
			document.getElementById("div_linka_on_ab").style.display = "none";			
			document.getElementById("mLista_on").style.display = "none";
			document.getElementById("line_white_on").style.width = 0;			
			document.getElementById("line_white_on").style.height = 0;			
		});

		jQuery('#ul_bag').mouseover(function() {
			var img_dlugosc = document.getElementById("_bag").offsetWidth;
			var ul_dlugosc = document.getElementById("ul_bag").offsetWidth;


			var ods = ((ul_dlugosc-img_dlugosc)/2);

			//document.getElementById("div_linka_bag").style.left = ods;	
			document.getElementById("div_linka_bag_ab").style.display = "block";				
			document.getElementById("mLista_bag").style.display = "block";
			document.getElementById("line_white_bag").style.width = img_dlugosc;
			document.getElementById("line_white_bag").style.height = 1;				
			//jQuery(_bag).show("slide", { direction: "up" }, 200);
		}).mouseout(function(){
			document.getElementById("div_linka_bag_ab").style.display = "none";		
			document.getElementById("mLista_bag").style.display = "none";
			document.getElementById("line_white_bag").style.width = 0;			
			document.getElementById("line_white_bag").style.height = 0;			
		});

		jQuery('#ul_akc').mouseover(function() {
			var img_dlugosc = document.getElementById("_akc").offsetWidth;
			var ul_dlugosc = document.getElementById("ul_akc").offsetWidth;


			var ods = ((ul_dlugosc-img_dlugosc)/2);

			//document.getElementById("div_linka_akc").style.left = ods;	
			document.getElementById("div_linka_akc_ab").style.display = "block";			
			document.getElementById("mLista_akc").style.display = "block";
			document.getElementById("line_white_akc").style.width = img_dlugosc;		
			document.getElementById("line_white_akc").style.height = 1;				
			//jQuery(_akc).show("slide", { direction: "up" }, 200);
		}).mouseout(function(){
			document.getElementById("div_linka_akc_ab").style.display = "none";			
			document.getElementById("mLista_akc").style.display = "none";
			document.getElementById("line_white_akc").style.width = 0;			
			document.getElementById("line_white_akc").style.height = 0;				
		});


		jQuery('#link2netarch').mouseover(function() {
					document.getElementById("link2netarch").style.borderBottomWidth = 1;
					document.getElementById("link2netarch").style.borderBottomColor = '#A9A8A6';
					document.getElementById("link2netarch").style.borderBottomStyle = 'solid';					
		}).mouseout(function() {
					document.getElementById("link2netarch").style.borderBottomWidth = 1;
					document.getElementById("link2netarch").style.borderBottomColor = 'white';
					document.getElementById("link2netarch").style.borderBottomStyle = 'solid';		
		});


		jQuery('#link2mercato').mouseover(function() {
					document.getElementById("link2mercato").style.borderBottomWidth = 1;
					document.getElementById("link2mercato").style.borderBottomColor = '#A9A8A6';
					document.getElementById("link2mercato").style.borderBottomStyle = 'solid';					
		}).mouseout(function() {
					document.getElementById("link2mercato").style.borderBottomWidth = 1;
					document.getElementById("link2mercato").style.borderBottomColor = 'white';
					document.getElementById("link2mercato").style.borderBottomStyle = 'solid';		
		});


		jQuery('#link2blok').mouseover(function() {
					document.getElementById("link2blok").style.borderBottomWidth = 1;
					document.getElementById("link2blok").style.borderBottomColor = '#A9A8A6';
					document.getElementById("link2blok").style.borderBottomStyle = 'solid';					
		}).mouseout(function() {
					document.getElementById("link2blok").style.borderBottomWidth = 1;
					document.getElementById("link2blok").style.borderBottomColor = 'white';
					document.getElementById("link2blok").style.borderBottomStyle = 'solid';		
		});		


		jQuery('#a_drukuj').mouseover(function() {
					document.getElementById("div_drukuj").style.display = "block";
					var dl_d = document.getElementById("obraz_dr").offsetWidth;
					document.getElementById("print_line").style.width = (dl_d - 17);
					document.getElementById("print_line").style.height = 1;				
		}).mouseout(function() {
					document.getElementById("print_line").style.width = 0;
					document.getElementById("print_line").style.height = 0;	
					document.getElementById("div_drukuj").style.display = "none";						
		});	
		
		
		

	//  document.body.onmouseover = testIn;





// 	var _on = jQuery('#_on');
// 	var _bag = jQuery('#_bag');
// 	var _akc = jQuery('#_akc');


});


function firstCheckForm() {
var price_from = document.getElementById("price_from").value;
var price_to = document.getElementById("price_to").value;

var new_pfrom = price_from.match('\\.');
var new_pto = price_to.match('\\.');


if(!new_pfrom && !new_pto) {
  if(price_from >= price_to) {
    alert("Cena od nie może być wieksza niż cena do.");
    return false
  }
  else
    return true;

}
else {
  alert("Zastosuj , zamiast . w polu cena.")
  return false;
}
}

function okok(coss, all) {
  for(i = 0; i<all; i++) {
    if(i == coss)
    document.getElementById('ph_'+i).style.display = "block";
    else
    document.getElementById('ph_'+i).style.display = "none";
  }
}


  function view2(id)
  {
    var pos_x;
    var pos_y;
    w=260;
    h=320;
    pos_x = (screen.width - w+18)/2;
    pos_y = (screen.height - h+75)/2;

    window.open("./sizes_table.php?products_id="+id,"Rozmiary", "width="+(w+90)+",pozx=300,height="+(h+80)+",resizable=yes,scrollbars=yes,menubar=no,status=0,toolbar=0,left="+pos_x+",top="+pos_y);
  }


  function view_static_page(file_name)
  {
    var pos_x;
    var pos_y;
    w=360;
    h=420;
    pos_x = (screen.width - w)/2;
    pos_y = (screen.height - h)/2;

    window.open("./static_page_mini.php?filename="+file_name,file_name, "width="+(w+90)+",pozx=100,height="+(h+80)+",resizable=yes,scrollbars=yes,menubar=no,status=0,toolbar=0,left="+pos_x+",top="+pos_y);
  }

