/*
  $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 nOnloadActions() {
	document.getElementById('left_column_table').style.height=(document.getElementById('left_column').offsetHeight + 'px');
}

function askForName() {
	var askBlock = document.createElement("DIV");
	askBlock.className = 'ask_container';
	document.getElementById('site_container').appendChild(askBlock);
	document.getElementById('ask_subcontainer').style.display='block';
	document.getElementById('ask_input').focus();
}

function choose_tab(number) {
	document.getElementById('cr_pInfo_tab_1').className='cr_pInfo_tab_disabled';
	document.getElementById('cr_pInfo_tab_2').className='cr_pInfo_tab_disabled';
	document.getElementById('cr_pInfo_tab_3').className='cr_pInfo_tab_disabled';

	document.getElementById('cr_pInfo_tab_content_1').style.display='none';
	document.getElementById('cr_pInfo_tab_content_2').style.display='none';
	document.getElementById('cr_pInfo_tab_content_3').style.display='none';

	document.getElementById('cr_pInfo_tab_' + number).className='cr_pInfo_tab_enabled';
	document.getElementById('cr_pInfo_tab_content_' + number).style.display='block';
}

function cr_reload_image(image_number) {
	// hide all
	var image_counter = 0;
	while (document.getElementById('cr_pInfo_image_' + image_counter) != null) {
		document.getElementById('cr_pInfo_image_' + image_counter).style.display='none';
		image_counter++;
	}

	// display one
	document.getElementById('cr_pInfo_image_' + image_number).style.display='inline';
}

function display_conditions() {
	window.open ("http://demon.netarch.eu/cocoroco/conditions?popup", "conditions","status=0,toolbar=0,location=0,menubar=0,directories=0,resizable=1,scrollbars=1,height=400,width=450,top=200,left=300");
}

function refresh_payment_methods() {
	var shipping_value = document.getElementById('shipping_val').value;
	var payment_select = document.getElementById('payment_val');

	payment_select.options.length = 0;

	if (shipping_value == 'flat_flat') {
		var newOption = document.createElement("OPTION");
		newOption.text = document.getElementById('hidden_payment_cod').innerHTML;
		newOption.value = 'cod';
		payment_select.options[payment_select.options.length] = new Option(newOption.text,newOption.value);  
	}
	else {
		var newOption = document.createElement("OPTION");
		newOption.text = document.getElementById('hidden_payment_moneyorder').innerHTML;
		newOption.value = 'moneyorder';
		payment_select.options[payment_select.options.length] = new Option(newOption.text,newOption.value);  

		newOption = document.createElement("OPTION");
		newOption.text = document.getElementById('hidden_payment_platnosci').innerHTML;
		newOption.value = 'platnosci';
		payment_select.options[payment_select.options.length] = new Option(newOption.text,newOption.value);  

		newOption = document.createElement("OPTION");
		newOption.text = document.getElementById('hidden_payment_platnosci2').innerHTML;
		newOption.value = 'platnosci2';
		payment_select.options[payment_select.options.length] = new Option(newOption.text,newOption.value);  
	}
}


function highliht_on(element) {
	element.className='menu_cell_hover';
}

function highliht_off(element) {
	element.className='';
}

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 updateCartForm() {
	var payment = document.getElementById('payment_val').value;
	var methods = document.getElementById('shipping_val').value;;
// 	alert (payment);
	var customer_default_address_id = document.getElementById('customer_default_address_id').value;
	var customer_id = document.getElementById('customer_id').value;
	var cartID = document.getElementById('cartid').value;

	var url = 'checkout_shipping.php?payment='+payment+'&methods='+methods+'&customer_default_address_id='+customer_default_address_id+'&customer_id='+customer_id+'&cartID='+cartID;
	document.location=url;
}

function show_hide_pass() {
	var a = document.getElementById('new_password').style.display;
	
	if (a=='none') {
		document.getElementById('new_password').style.display='table-row';
	} else {
		if (document.getElementById('new_password_input') != null) document.getElementById('new_password_input').value='';
		if (document.getElementById('new_password_input_2') != null) document.getElementById('new_password_input_2').value='';
		document.getElementById('new_password').style.display='none';
	}
	
}

