var agt=navigator.userAgent.toLowerCase();
var is_major = parseInt(navigator.appVersion);
var is_minor = parseFloat(navigator.appVersion);
var is_nav  = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1) && (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1) && (agt.indexOf('webtv')==-1));

var is_nav4 = (is_nav && (is_major == 4));
var is_nav4up = (is_nav && (is_major >= 4));
var is_nav6 = (is_nav && (is_major == 5));
var is_nav6up = (is_nav && (is_major >= 5));
var is_ie   = (agt.indexOf("msie") != -1);
var is_ie3  = (is_ie && (is_major < 4));
var is_ie4  = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.0")==-1));
var is_ie4up  = (is_ie  && (is_major >= 4));
var is_ie5  = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.0")!=-1));
var is_ie5up  = (is_ie && !is_ie3 && !is_ie4);
var is_opera = (agt.indexOf("opera") != -1);
var is_opera4 = (is_opera && (is_major == 4));
var is_opera5 = (is_opera && (is_major == 5));
var is_opera5up = (is_opera && (is_major >= 5));

var is_domcom = ((is_nav6up)||(is_ie5up)||(is_opera5up))
var is_mac    = (agt.indexOf("mac")!=-1);
var is_mac68k = (is_mac && ((agt.indexOf("68k")!=-1) || (agt.indexOf("68000")!=-1)));
var is_macppc = (is_mac && ((agt.indexOf("ppc")!=-1) || (agt.indexOf("powerpc")!=-1)));

var _timeout	= 0;

function getElementById(_id) {

	var _el;

	if(is_domcom) {
		_el	= document.getElementById(_id);
	} else if(is_ie4) {
		_el	= document.all[_id];
	}

	return _el;
}

function _showMenu(_objID) {
	var _obj	= getElementById(_objID);
	if(_obj) {
		_obj.style.display	= 'block';
	}
}

function _hideMenu(_objID) {
	var _obj	= getElementById(_objID);
	if(_obj) {
		_obj.style.display	= 'none';
	}
}

/*************************************************
 *	shows element with id passed as parameter
 *************************************************/
function doOver(_id) {

	var _el	= getElementById(_id);
	if(_el) {
		if(_el.timer) {
			clearTimeout(_el.timer);
		}
		 _showMenu(_id);
	}
}

/*************************************************
 *	hides element with id passed as parameter
 *************************************************/

var time

function doOut(_id) {

	var _el	= getElementById(_id);

	if(_el) {
		var _timer	= setTimeout("_hideMenu('" + _id + "')", _timeout);
		_el.timer	= _timer;
	}
}


function clearForm(form) {
	document.getElementById('nameCard').value = "";
	document.getElementById('type').selectedIndex = 0;
	document.getElementById('date2').selectedIndex = 0;
	document.getElementById('date1').selectedIndex = 0;
	document.getElementById('number').value = "";
}


/* FILL SHIPPING ADDRES BEGIN */
function getValue(_id){
	return document.getElementById(_id).value;
}

function fillValue(_id, _value){
	document.getElementById(_id).value = _value;
	//document.getElementById(_id).disabled = true;
}

function enableEl(_id){
	document.getElementById(_id).disabled = false;
}

function fillShippingAddress(){

	if(document.getElementById('asBillingAddress').checked == true){
		fillValue('s_firstName', getValue('b_firstName'));
		fillValue('s_lastName', getValue('b_lastName'));
		fillValue('s_address', getValue('b_address'));
		fillValue('s_city', getValue('b_city'));
		fillValue('s_state', getValue('b_state'));
		fillValue('s_zipCode', getValue('b_zipCode'));
		fillValue('s_country', getValue('b_country'));
		//fillValue('s_email', getValue('b_email'));
	}
	else if(document.getElementById('asBillingAddress').checked == false){
		enableEl('s_firstName');
		enableEl('s_lastName');
		enableEl('s_address');
		enableEl('s_city');
		enableEl('s_state');
		enableEl('s_zipCode');
		enableEl('s_country');
		//enableEl('s_email');
	}
}


/* FILL SHIPPING ADDRES END */

function clearFieldsCheckout(value) {

    if(value == 1) {

        document.getElementById('b_firstName').value = '';
        document.getElementById('b_lastName').value = '';
        document.getElementById('b_address').value = '';
        document.getElementById('b_city').value = '';
        document.getElementById('b_state').value = '';
        document.getElementById('b_zipCode').value = '';
        document.getElementById('b_country').value = '';

    } else if(value == 2) {

        if(document.getElementById('asBillingAddress').checked == false) {

            document.getElementById('s_firstName').value = '';
            document.getElementById('s_lastName').value = '';
            document.getElementById('s_address').value = '';
            document.getElementById('s_city').value = '';
            document.getElementById('s_state').value = '';
            document.getElementById('s_zipCode').value = '';
            document.getElementById('s_country').value = '';
            document.getElementById('email').value = '';

        }

    } else if(value == 3) {

        document.getElementById('date1').value = '';
        document.getElementById('date2').value = '';
        document.getElementById('number').value = '';
        document.getElementById('nameCard').value = '';
        document.getElementById('CardNumber').value = '';

    }

}

// incrementing and decrementing quantity
var qty = new Array(100);
for (i=0;i<100;i++) qty[i]=0;

function qty_update(i,j)
{
	qty[j] = document.getElementById('qty_'+j).value;
	var v = parseInt(qty[j]);
	if (isNaN(v)) v=1;
	if (i==1) v++;
	else {
		v--;
		if (v <= 0) v=1;
	}
	return v;
}

function qty_validate(i,lang)
{
	var u = document.getElementById('qty_'+i).value;
	var v = parseInt(u);
	if (isNaN(v)) {
		if (lang == 'sk') alert('Chyba: Zadaná hodnota nie je číselná!');
		if (lang == 'en') alert('Error: Entered value is not a number!');
	}
	else {
		if (v < 0) {
			if (lang == 'sk') alert('Chyba: Zadaná hodnota je záporná!');
			if (lang == 'en') alert('Error: Entered value is negative!');
		}
		if (u != v) {
			if (lang == 'sk') alert('Chyba: Zadaná hodnota nie je celočíselná!');
			if (lang == 'en') alert('Error: Entered value is not a whole number!');
		}
	}
	//document.getElementById('id_qty_'+i).focus();
}

function visibility(type) {

    if(type == 1) {

        if( document.getElementById('accessories_tips').style.visibility == 'hidden' ) {

            document.getElementById('accessories_tips').style.visibility='visible';
            document.getElementById('accessories').style.visibility = 'visible';

        } else {

            if( document.getElementById('tips').style.visibility == 'visible' ) {

                document.getElementById('accessories_tips').style.visibility='visible';

                if( document.getElementById('accessories').style.visibility == 'visible' ) {
                    document.getElementById('accessories').style.visibility='hidden';
                } else {
                    document.getElementById('accessories').style.visibility='visible';
                }


            } else {
                document.getElementById('accessories_tips').style.visibility='hidden';
                document.getElementById('accessories').style.visibility = 'hidden';
            }


        }

    } else {

        if( document.getElementById('accessories_tips').style.visibility == 'hidden' ) {

            document.getElementById('accessories_tips').style.visibility='visible';
            document.getElementById('tips').style.visibility='visible';

        } else {

            if( document.getElementById('accessories').style.visibility == 'visible' ) {

                document.getElementById('accessories_tips').style.visibility='visible';

                if( document.getElementById('tips').style.visibility == 'visible' ) {
                    document.getElementById('tips').style.visibility='hidden';
                } else {
                    document.getElementById('tips').style.visibility='visible';
                }

            } else {
                document.getElementById('accessories_tips').style.visibility='hidden';
                document.getElementById('tips').style.visibility='hidden';
            }
        }

    }

}


/******************************** check credit card ************************************/
		// stopError() and the window.onerror code is to suppress any JavaScript errors that occur
		function stopError()
		{
			return true;
		}
		window.onerror = stopError;

		function CheckCard(obj)
		{
			if (ValidCardNumber( obj ) == false)
			{
				alert("Invalid Card Number");
				obj.focus();
			}
		}

		function CheckPaymentType()
		{
			document.frmPayment.trnCardOwner.disabled = false;
			document.frmPayment.trnCardNumber.disabled = false;
			document.frmPayment.trnExpMonth.disabled = false;
			document.frmPayment.trnExpYear.disabled = false;
		}

		function PositiveInteger(objName)
		{
			if (objName.value != "")
			{
				if (IsPosNumeric(objName.value) == false)
				{
					//objName.focus()
					//objName.select()
					return false
				}
				else
				{
					return true
				}
			}
			return true
		}





		function OnChangeShipSameAsOrd() {
			if (document.frmPayment.shipSameAsOrd.checked == true) {
				dControl = true
			}
			else {
				dControl = false
			}
			DisableControl(document.frmPayment.shipName, dControl)
			DisableControl(document.frmPayment.shipEmailAddress, dControl)
			DisableControl(document.frmPayment.shipPhoneNumber, dControl)
			DisableControl(document.frmPayment.shipAddress1, dControl)
			DisableControl(document.frmPayment.shipAddress2, dControl)
			DisableControl(document.frmPayment.shipCity, dControl)
			DisableControl(document.frmPayment.shipProvince, dControl)
			DisableControl(document.frmPayment.shipPostalCode, dControl)
			DisableControl(document.frmPayment.shipCountry, dControl)
		}

		function CheckAgree(){
			if (document.frmPayment.agreement.checked == true){
				document.frmPayment.submitButton.disabled = false;
			}else{
				document.frmPayment.submitButton.disabled = true;
			}
		}

		function addLoadEvent(func) {
  	var oldonload = window.onload;
  	if (typeof window.onload != 'function') {
    	window.onload = func;
  	} else {
    	window.onload = function() {
      	oldonload();
      	func();
    	}
  	}
}
if (parseInt(navigator.appVersion.charAt(0)) >= 4) {
  isNav4 = (navigator.appName == "Netscape") ? true : false;
  isIE4 = (navigator.appName.indexOf("Microsoft") != -1) ? true : false;
}
	function FormatDate(monthObj, dayObj, yearObj) {
			var oOption1 = new Option();
			//document.createElement("OPTION");
			var oOption2 = new Option();
			//document.createElement("OPTION");
			var oOption3 = new Option();
			//document.createElement("OPTION");
			monthIndex = monthObj.selectedIndex + 1
			//monthIndex = monthIndex + 1
			currentYear = yearObj.options[yearObj.selectedIndex].value
		if(isNav4)
		{
			if (monthIndex == 2) {
				//Month is Febuary
				dayObj.options[30] = null
				dayObj.options[29] = null
				if (currentYear % 4 != 0) {
					dayObj.options[28] = null
				}
				else {
					if (dayObj.options.length == 28) {
						oOption1.value = "29";
						oOption1.text = "29";
						dayObj.options[28] = oOption1
					}
				}
				if (dayObj.selectedIndex == 29 || dayObj.selectedIndex == 30) {dayObj.selectedIndex = 28}
			}
			else if (monthIndex == 4 || monthIndex == 6 || monthIndex == 9 || monthIndex == 11) {
				//30 days in the selected month
				if (dayObj.selectedIndex == 30) {dayObj.selectedIndex = 29}
				if (dayObj.options.length == 28) {
					oOption1.value = "29";
					oOption1.text = "29";
					dayObj.options[28] = oOption1;

				}
				if (dayObj.options.length == 29) {
					oOption2.value = "30";
					oOption2.text = "30";
					dayObj.options[29] = oOption2;
				}
				dayObj.options[30] = null
			}
			else {
				//31 days in the selected month
				if (dayObj.options.length == 28) {
					oOption1.text = "29";
					oOption1.value = "29";
					dayObj.options[28] = oOption1;
				}
				if (dayObj.options.length == 29) {
					oOption2.text = "30";
					oOption2.value = "30";
					dayObj.options[29] = oOption2;
				}
				if (dayObj.options.length == 30) {
					oOption3.text = "31";
					oOption3.value = "31";
					dayObj.options[30] = oOption3;

				}
			}
		}
		if(isIE4)
		{
			if (monthIndex == 2) {
				//Month is Febuary
				dayObj.options[30] = null
				dayObj.options[29] = null
				if (currentYear % 4 != 0) {
					dayObj.options[28] = null
				}
				else {
						if (dayObj.options.length == 28) {
						dayObj.options.add(oOption1, 28);
						oOption1.innerText = "29";
						oOption1.value = "29";
					}
				}
				if (dayObj.selectedIndex == 29 || dayObj.selectedIndex == 30) {dayObj.selectedIndex = 28}
			}
			else if (monthIndex == 4 || monthIndex == 6 || monthIndex == 9 || monthIndex == 11) {
				//30 days in the selected month
				if (dayObj.selectedIndex == 30) {dayObj.selectedIndex = 29}
				if (dayObj.options.length == 28) {
					dayObj.options.add(oOption1, 28);
					oOption1.innerText = "29";
					oOption1.value = "29";
				}
				if (dayObj.options.length == 29) {
					dayObj.options.add(oOption2, 29);
					oOption2.innerText = "30";
					oOption2.value = "30";
				}
				dayObj.options[30] = null
			}
			else {
				//31 days in the selected month
				if (dayObj.options.length == 28) {
					dayObj.options.add(oOption1, 28);
					oOption1.innerText = "29";
					oOption1.value = "29";
				}
				if (dayObj.options.length == 29) {
					dayObj.options.add(oOption2, 29);
					oOption2.innerText = "30";
					oOption2.value = "30";
				}
				if (dayObj.options.length == 30) {
					dayObj.options.add(oOption3, 30);
					oOption3.innerText = "31";
					oOption3.value = "31";
				}
			}
		}
	}
<!-- Host file must contain VBScript_print_text.asp -->
function ValidateEmailAddress (emailStr) {

	var emailPat=/^(.+)@(.+)$/
	var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
	var validChars="\[^\\s" + specialChars + "\]"
	var quotedUser="(\"[^\"]*\")"
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
	var atom=validChars + '+'
	var word="(" + atom + "|" + quotedUser + ")"
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")


	var matchArray=emailStr.match(emailPat)
	if (matchArray==null) {
		alert("Please enter a valid email address.")
		return false
	}
	var user=matchArray[1]
	var domain=matchArray[2]

	// See if "user" is valid
	if (user.match(userPat)==null) {
	    alert("Email address username is not valid.")
	    return false
	}

	/* if the e-mail address is at an IP address  */
	var IPArray=domain.match(ipDomainPat)
	if (IPArray!=null) {
		  for (var i=1;i<=4;i++) {
		    if (IPArray[i]>255) {
		        alert("Email address destination IP is invalid.")
			return false
		    }
	    }
	    return true
	}

	// Domain is symbolic name
	var domainArray=domain.match(domainPat)
	if (domainArray==null) {
		alert("Email address domain name doesn't seem to be valid.")
	    return false
	}

	/* Make sure that it ends in a three-letter word or a two-letter word, and that hostname preceding domain or country. */

	var atomPat=new RegExp(atom,"g")
	var domArr=domain.match(atomPat)
	var len=domArr.length
	if (domArr[domArr.length-1].length<2 ||
	    domArr[domArr.length-1].length>3) {
	   alert("Email address must end in a three-letter domain, or two letter country.")
	   return false
	}

	// Make sure there's a host name preceding the domain.
	if (len<2) {
	   var errStr="Email address is missing a hostname."
	   alert(errStr)
	   return false
	}

	// If we've gotten this far, everything's valid!
	return true;
	}

		function ValidCardNumber(objName) {

		    var ccnLength;
	   		var cPrefix2;
			var nString = "";
			var total = 0;
			var ccNumber = "";
			var i;

			//Don't bother checking if the length is 0
			if( objName.value.length == 0 ) return true;

			//Strip out all dash and space characters
			for (i = 0; i < objName.value.length; i++) {
				if (objName.value.charCodeAt(i) >= 48 && objName.value.charCodeAt(i) <= 57) {
					ccNumber = ccNumber + objName.value.charAt(i);
				}
				else if (objName.value.charCodeAt(i) != 45 && objName.value.charCodeAt(i) != 32) {
					return false;
				}
			}

			//Set variable to credit card length
			ccnLength = ccNumber.length;

		    //Check card number prefix and length
		    if (ccnLength >= 13) {
		        cPrefix2 = parseInt(ccNumber.charAt(0) + ccNumber.charAt(1));
		        cPrefix3 = parseInt(ccNumber.charAt(0) + ccNumber.charAt(1) + ccNumber.charAt(2));
		        cPrefix4 = parseInt(ccNumber.charAt(0) + ccNumber.charAt(1) + ccNumber.charAt(2) + ccNumber.charAt(3));
		        if (cPrefix2 > 49 && cPrefix2 < 56) { //Mastercard    ***** NOTE: Test mastercards can start with 50, valid cards cannot
		            if (ccnLength != 16) {
		                return false;
		            }
				} else if (ccNumber.charAt(0) == "4") {    //VISA
		            if (ccnLength != 16 && ccnLength != 13) {
		                return false;
		            }
				} else if (cPrefix2 == 34 || cPrefix2 == 37) { //AMEX
		            if (ccnLength != 15) {
		                return false;
		            }
				} else if ((cPrefix3 > 299 && cPrefix3 < 306) || cPrefix2 == 36 || cPrefix2 == 38) { //Diners Club/Carte Blanche
		            if (ccnLength != 14) {
		                return false;
		            }
				} else if (cPrefix4 == 6011) {  //Discover
		            if (ccnLength != 16) {
		                return false;
		            }
				} else if (cPrefix4 > 3527 && cPrefix4 < 3590) {  //JCB
		            if (ccnLength != 16) {
		                return false;
		            }
				} else if (ccNumber.charAt(0) == "6") {    //SEARS
		            if (ccnLength > 16) {
						return false;
					}
				} else {
					return false;
		        }

				if (ccNumber.charAt(0) != "6") { //SEARS
					//Perform MOD check
					for (i=1; i <= ccnLength; i++) {
				        if ((i % 2) == 0) {
				            nString = nString + (parseInt(ccNumber.charAt(ccnLength - i)) * 2);
						}
				        else {
				            nString = nString + ccNumber.charAt(ccnLength - i);
				        }
					}

				    for (i=0; i < nString.length; i++) {
				        total = total + parseInt(nString.charAt(i));
				    }

				    if (total % 10 != 0) {
				        return false;
					}
					else {
				        return true;
				    }
				} else {
					//SEARS Card - Do not perform MOD 10 check
					return true;
				}

			}
		    else {
		        return false;
		    }

		}
		function FormatAmount(obj) {
			//Purpose: to format a numberic value to currency formating, ie xxxxx.xx
			//		   Values are rounded up. ie. 45.105 = 45.11
			//Pre:	   obj is a textbox object
			//post:    sets obj.value = the formated currency

			var newValue = ""

			if (obj.value == "") {obj.value="0.00"; return}

			obj.value = MoneyChopValue(obj.value);
			if (obj.value < 0) {
				objValue = parseFloat(obj.value) - parseFloat('0.005');
			}
			else {
				objValue = parseFloat(obj.value) + parseFloat('0.005');
			}
			objValue = eval("'" + objValue + "'")
			if (objValue.length > 0) {
				if (objValue.charAt(0) == '.') {objValue = "0" + objValue}
			}
			for (x=0; x < objValue.length; x++) {
				if (objValue.charAt(x) == '.') {
					if (x == (objValue.length - 1)) {
						newValue = newValue + ".00"
					}
					else if (x == (objValue.length - 2)) {
						newValue = newValue + "." + objValue.charAt(x+1) + "0"
					}
					else {
						newValue = newValue + "." + objValue.charAt(x+1) + objValue.charAt(x+2)
					}
					obj.value = newValue
					return;
				}
				newValue = newValue + objValue.charAt(x)
			}
			obj.value = newValue + ".00"
		}

		function FormatAmountValue(value) {
			// Purpose: To format a monetary value.  Like above, except not an obj
			// Stephen McGrath
			this.value = value;
			FormatAmount(this);
			return this.value;
		}

		function MoneyChop(Obj) {
			// Purpose: See MoneyChopValue
			// Stephen McGrath
			Obj.value = MoneyChopValue(Obj.value);
		}

		reMoney = /^-?[0-9]*\.?[0-9]{0,4}/;
		function MoneyChopValue(value) {
			// Purpose: Chops numbers off to four decimal places to work around the
			//          JavaScript math errors.
			// Comments: Finds 0 or 1 '-' then any digits then 0 or 1 decimal points then
			//           up to four more digits.
			// Stephen McGrath
			value += "";
			return parseFloat(value.match(reMoney));
		}
	function IsNumeric(sNumber) {
		// Stephen McGrath
		var decimal = 0;
		sNumber += "";
		if (sNumber.length == 0) return false;
		for (x = 0; x < sNumber.length; x++) {
			if (!(sNumber.charCodeAt(x) >= 48 && sNumber.charCodeAt(x) <= 57)) {
				switch (sNumber.charAt(x)) {
					case ".":
						if (decimal++ != 0) return false;
						break;
					case "-":
						if (x > 0) return false;
						if (sNumber.length == 1) return false;
						break;
					default:
						return false;
				}
			}
		}
		return true;
	}


	function IsPosNumeric(sNumber) {
		// Stephen McGrath
		sNumber += "";
		return (sNumber.charAt(0) != "-" && IsNumeric(sNumber));
	}

	function RequireNumericOnly(editBox, defaultValue) {
		if( editBox.value != '' && !IsNumeric(editBox.value) ) {
			editBox.value = defaultValue;
			alert('Please enter only numeric values');
			editBox.focus();
		}
	}
			function DisableControl(objName, dControl) {
			if (dControl == true) {
				objName.disabled = true
				objName.style.background = "E5E5E5"
			}
			else {
				objName.disabled = false
				objName.style.background = "FFFFFF"
			}
		}

/******************************** check credit card ********************************************************/

function show_hide(_id){
	if (document.getElementById(_id).style.display=='block'){
		document.getElementById(_id).style.display='none';
	} else {
		document.getElementById(_id).style.display='block';
	}
}

function getProdNameByExternalID (item, product) {
    if(product) {
        document.getElementById(item).value=product;
    } else {
        document.getElementById(item).value='';
    }
}

function checkExpirationDate () {

    if( document.getElementById('month').value != '' && document.getElementById('year').value != '' ) {
        var d = new Date();
        var curr_date = d.getDate();
        var curr_month = d.getMonth();
        var curr_year = d.getFullYear();

        if( curr_year > document.getElementById('year').value ) {
            alert('Incorrect Expiration date.');
        } else if ( curr_year == document.getElementById('year').value ) {
            if( ((document.getElementById('month').value) - 1)  < curr_month ) {
                alert ('Incorrect Expiration date.');
            }
        }
    }

}


// Kopecky - 14.9.2007 CHECK EXIST Shipping adrees
function checkShippingAdress(){
        var countAllString = 0;
        countAllString = document.getElementById('CountallString').value;

        var formFields = "";

        formFields = document.getElementById('first_name').value + document.getElementById('last_name').value + document.getElementById('address').value + document.getElementById('state_name').value + document.getElementById('zip_code').value;
        formFields = formFields.toLowerCase();
        formFields = formFields.replace(' ','');
        formFields = formFields.replace('\n','');
      for(x=1;x<countAllString;x++){
            var item = document.getElementById('allString_'+x).value;
            if( formFields == item.value ){
                alert(item+'\n\n\n\n'+ formFields);
                return false;
            }
        }
    return false;
}

function showHideFunction() {
    var ele = document.getElementById("showHide");
    if(document.getElementById("typeInd").checked == true ) {
        ele.style.display = "none";
    } else {
        ele.style.display = "block";
    }
}

function showHideTaxExampt() {
    var ele = document.getElementById("showHideTaxExampt");
    if(document.getElementById("tax_exampt").value==1) {
        ele.style.display = "block";
    } else {
        ele.style.display = "none";
    }
}

function showHideReqCredit() {
    var ele = document.getElementById("showHideReqCredit");
    if(document.getElementById("credit").value==1) {
        ele.style.display = "block";
    } else {
        ele.style.display = "none";
    }
}

function stateProvince (response_target) {
    var http_request = false;
    var state = '';

    if( response_target == 'undefined' ) {
		var _responseTarget = 'response';
		var country = document.getElementById('country').value;
    } else {
    	var _responseTarget = response_target;
    	if (response_target == 'response_bill') {
			var country = document.getElementById('bill_country').value;
    	} else {
    		var country = document.getElementById('country').value;
    	}
    }
    var request = "country="+country+"&state="+state;

    if (window.XMLHttpRequest) {
        http_request = new XMLHttpRequest();
    } else if (window.ActiveXObject) {
        try {
          http_request = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (eror) {
          http_request = new ActiveXObject("Microsoft.XMLHTTP");
        }
    }

    http_request.onreadystatechange = function() { ajaxCompile(http_request, _responseTarget); };
    http_request.open('POST', 'state-province.php', true);
    http_request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    http_request.send(request);
}

function ajaxCompile(http_request, response_target) {
    if (http_request.readyState == 4) {
        if (http_request.status == 200) {
            var response = document.getElementById(response_target);
            response.innerHTML = http_request.responseText;
        } else {
            //alert('Chyba');
        }
    }
}

function fillValue(_id, _value){
	document.getElementById(_id).value = _value;
}

function enableEl(_id){
	document.getElementById(_id).disabled = false;
}

function getValue(_id){
	return document.getElementById(_id).value;
}

function same_as_shipp () {
	if(document.getElementById('bill_sane_as_shipp').checked == true){
		fillValue('bill_first_name', getValue('first_name'));
		fillValue('bill_last_name', getValue('last_name'));
		fillValue('bill_address', getValue('address'));
		fillValue('bill_phone_number', getValue('phone_number'));
		fillValue('bill_city', getValue('city'));
		fillValue('bill_state', getValue('state'));
		fillValue('bill_zip_code', getValue('zip_code'));
		fillValue('bill_country', getValue('country'));
		fillValue('bill_territory', getValue('territory'));
	} else if(document.getElementById('bill_sane_as_shipp').checked == false){
		enableEl('first_name');
		enableEl('last_name');
		enableEl('address');
		enableEl('phone_number');
		enableEl('city');
		enableEl('state');
		enableEl('zip_code');
		enableEl('country');
		enableEl('country');
	}
}

function stateProvince1 (state) {
    var http_request = false;
    var country = document.getElementById('country').value;
    var request = "country="+country+"&state="+state;

    if (window.XMLHttpRequest) {
        http_request = new XMLHttpRequest();
    } else if (window.ActiveXObject) {
        try {
          http_request = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (eror) {
          http_request = new ActiveXObject("Microsoft.XMLHTTP");
        }
    }

    http_request.onreadystatechange = function() { ajaxCompile1(http_request); };
    http_request.open('POST', 'state-province.php', true);
    http_request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    http_request.send(request);
}

function ajaxCompile1(http_request) {
    if (http_request.readyState == 4) {
        if (http_request.status == 200) {
            var response = document.getElementById("response");
            response.innerHTML = http_request.responseText;
        } else {
            //alert('Chyba');
        }
    }
}