var reallyMove;
var selectDelivery;

function Buttons(){
    inputs = document.getElementsByTagName('input');
    for(i = 0; i < inputs.length; i++){
        if(inputs[i].type != 'image')
        inputs[i].className='input';
        if(inputs[i].type == 'submit')
        inputs[i].className='button';
    }
}
function Init(){
    Buttons();
    /**
    * wy³±czamy autocomplete zeby nie kolidowac z hintami ajaxowymi
    * _i_ zachowac zgodnosc z xhtml
    */
    var s = document.getElementById('search_query_words');
	 if (s)
    s.setAttribute("autocomplete", "off");
}

function imageScale(sender, max_size) {
    p=0;
    if (sender.width > max_size) {
        p = (max_size / sender.width);
    }
    else {
        if (sender.height > max_size) {
            p = (max_size / sender.height);
        }
    }
    if(p > 0) {
        sender.width = p * sender.width;
    }
}


function searchOver (what) {
    document.getElementById(what).className = 'HintHighlight';
    showHints();
}
function searchOut (what) {
    document.getElementById(what).className = 'HintUnHighlight';
}
function searchDown (str) {
    document.getElementById('search_query_words').value = str;
}
var timeout=1000;
var oldQuery='';
function hintMe() {
    query=document.getElementById('search_query_words').value;
    /*hint.className='searchDivHidden';*/
    document.getElementById('searchHint').style.visibility='visible';
    if (query != oldQuery) {
        oldQuery=query;
        if (query && query.length>3) {
            window.setTimeout('xajax_searchHints(query);',timeout);
        } else {
            hideHints();
        }
    }
}
function showHints() {
    query=document.getElementById('search_query_words').value;
    if (query && query.length>3) {
        hint=document.getElementById('searchHint');
        if (hint.style.visibility!='visible') hint.style.visibility='visible';
    }
}
function hideHints() {
    hint=document.getElementById('searchHint');
    hint.style.visibility='hidden';
}
function auto_off() {
	if (s)
    alert(s.toString);
}

function hide_list(list)
{
    list.style.display='none';
}

function show_list(list)
{
    list.style.display='block';
}

function visible(list)
{
    if ((list.style.display=='block') || list.style.display=='')
    return true;

    return false;
}

function _$(id)
{
    return document.getElementById(id);
}

function ShowBox(id, ms, timer) {
    var timer=(timer==null) ? 0 : timer;
    var objref=document.getElementById(id);

    var scrOfX = 0, scrOfY = 0;
    if( typeof( window.pageYOffset ) == 'number' ) {
        //Netscape
        scrOfY = window.pageYOffset;
        scrOfX = window.pageXOffset;
    } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
        //DOM
        scrOfY = document.body.scrollTop;
        scrOfX = document.body.scrollLeft;
    } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
        //IE6
        scrOfY = document.documentElement.scrollTop;
        scrOfX = document.documentElement.scrollLeft;
    }
    //  wysrodkowanie w pionie
    var topBoxOffset=scrOfY+(screen.availHeight/3)-(objref.offsetHeight/2);
    //	wysrodkowanie w poziomie
    var leftBoxOffset=scrOfX+(screen.availWidth/2)-(objref.offsetWidth/2);

    objref.style.top=topBoxOffset+"px";
    objref.style.left=leftBoxOffset+"px";
    if (timer < ms) {
        objref.style.display="block";
        timer+=10;
        setTimeout("ShowBox('"+id+"',"+ms+","+timer+")",1);
    } else {

        objref.style.display="none";

    }
}

function zagielCheckOrderValue(value, message) {
    if (value < 100) {
        window.alert(message);
        return false;
    } else {
        return true;
    }
}

function zagielProductCalcLink(shopNo, value, message) {

    if (zagielCheckOrderValue(value, message)) {
        window.open('https://www.zagiel.com.pl/kalkulator/index_smart.php?action=getklientdet_si_rata&shopNo='+shopNo+'&goodsValue='+value,'Policz_rate','width=630,height=500,directories=no,location=no,menubar=no,resizable=yes,scrollbars=yes,status=no,toolbar=no');
    }
}
function fieldCheck(val1){
	var regx=new RegExp('^[0-9a-zA-Z±¡¿¯¼¬êÊæÆ¶¦ñÑ³£óÓ -_.:@&]+$');
	
	if (!val1.match(regx)){

		if (arguments.length>1 &&arguments[1]!==undefined && arguments[1].length>0){
			alert("Please remove non-english characters from field: \n"+arguments[1]+"\n\nPlease remove them before you continue");
		}
		else{
			alert("You have non-english characters in one of fields.\nPlease remove them before you continue");
		}	
		return false;
	}	
	return true;
}
$().ready(function(){
/*
$(".currency-selector select.currency-select").change(function(){
var rl=$(this).val();

$(".currency-selector span[rel="+rl+"]").addClass("selected").siblings("span").removeClass("selected");
});*/
/*
	$("form input[type=text],form textarea").change(function(){
	 //	var t=/\b([0-9a-zA-Z¡¯Æ£ÊÑÓ±¿æ³óñ .-_@())])/ig;
		var t=/[^\x00-\x80±¡¯¿¬¼Ææ¦¶ÑñÓó£³Êê]+/ig;

		var re = new RegExp(t);
		var t2=$(this).val();
		var ee=re.exec(t2);
		if (ee!=null&&ee!=t2)
			alert(ee+ "\n"+ t2);
	}
	);
*/

	if (document.getElementById('fbBox')!=null){
		var script3 = document.createElement("script");
		script3.type="text/javascript";
		script3.async=true;
		script3.src = "https://connect.facebook.net/en_US/all.js#xfbml=1"; 
		document.getElementById('fbBox').appendChild(script3);
		
		var hconfig = {    
		 over:	function(){	$("#fbBox").animate({"left":0}); }, // function = onMouseOver callback (REQUIRED)    
		 timeout: 400, // number = milliseconds delay before onMouseOut    
		 out: 	function(){ $("#fbBox").animate({"left":"-206px"}); } // function = onMouseOut callback (REQUIRED)    
		};

		$("#fbBox").append('<fb:like-box href="http://www.facebook.com/pages/medicalbookspl/234782466538407" width="190" height="370" show_faces="true" stream="false" header="true"></fb:like-box>').hoverIntent(hconfig);
		
	}
	$("#select-delivery-type input:radio").click(function(){
	 //	alert;
	 if (($(this).attr("id")=="delivery-two" && confirm(reallyMove)) || ($(this).attr("id")=="delivery-one"))
	  		$(this).closest("form").submit();
	});
	
	if ( ($.browser.msie ==true )  && parseInt($.browser.version) < 8){
		$("body").append('<div id="ie-fix"></div>');
		$("#menu-top-links").appendTo($("#ie-fix"));
		$("#menu-top-gray-links").css({"margin-top":"29px"});
	}
	
  //	if (checkForm==true){
		$("#dataForm input[type=text]").change(function(){
			fieldCheck($(this).val(),$(this).attr('rel'));
		});
		$("#dataForm").submit(function(){
			var ret=true;
			$("#dataForm input[type=text]").each(function(i){
				//alert($(this).attr("name"));
				
				if (	$(this).val().length>0 && 
						fieldCheck($(this).val(),$(this).attr('rel'))==false
					){
					ret=false;
				}				
			});
			return ret;
		});
		
		//platnosci.pl
		
		$("form[name=payform] input[name=js]").val(1);
  //	}
});
