var ua        = navigator.userAgent.toLowerCase(); 

var is_pc_ie  = ( (ua.indexOf('msie') != -1 ) && ( ua.indexOf('win') != -1 ) && ( ua.indexOf('opera') == -1 ) && ( ua.indexOf('webtv') == -1 ) );
var wi = undefined;
function resetIEbasket(sm){
        if(is_pc_ie){
                setFlashBasket(sm)
        }
}
function setFlashBasket(argument){
	if(is_pc_ie){
		xajax.$('navigation').setVariable("basketQuote",argument);
	}else{
        
		if(xajax.$("connection")) xajax.$("connection").innerHTML = "<embed src='/_swf/connect.swf' flashVars='param="+argument+"' width='0' height='0' type='application/x-shockwave-flash'></embed>";;
	}
}
function addOption(selectId,txt,val) {
	var objOption = new Option(txt,val);
	xajax.$(selectId).options.add(objOption);
}
function submitSubscryptionForm() {
	xajax_processSubscryptionForm(xajax.getFormValues("subscryptionForm"));
	xajax.$('newsletter').disabled=true;
	xajax.$('newsletter').value="czekaj...";
	return false;
}
function getCategoriesOption() {
	xajax.$('categorie').disabled=true;
	xajax.$('size').disabled=true;
	xajax_addCategories(xajax.getFormValues("searchForm"));
	return false;
}
function getSizesOption() {
	xajax.$('size').disabled=true;
	xajax_addSizes(xajax.getFormValues("searchForm"));
	return false;
}
function submitSearch(){
	var x=xajax.$("searchForm");
	var ch = false;
	for(i=0;i<x.chbx.length;i++){
		if(x.chbx[i].checked)ch = true;
	}
	/*if(!ch){
		alert("Nie zaznaczono żadnych elementów do wyszukania.");
		return false;
	}*/
	x.submit();
}
function openwin(l, w, h, t, o) {
	t = "width="+w+",height="+h+",scrollbars="+((t=='tak'||t==1)?"yes":"no")+",resizable=no,toolbar=no,userbar=no,location=no,status=no,menubar=no,screenX=100,screenY=100";
    
	if(o == undefined)
		o = "new_window";
	eval(o+'=open("'+l+'", "'+o+'", t)');
	if(eval(o)!=null) try{ eval(o+'.focus();'); } catch(e){};
}
function opentableofsizes(){
	openwin("html/table.html", 750, 430, 1);
}
 
function openRequestWindow(idprod){
	openwin("?pro=request&id="+idprod, 750, 430, 1);
}


function opencardstatus(){
	openwin("status.php", 750, 430, 1);
}
function openInfoOld(info,height){
	if(height==undefined)height=100;
	var infohtml = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" lang="en_US" xml:lang="en_US"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>Milena - informacja</title><link href="../../_css/style.css" rel="stylesheet" type="text/css"></head><body><center><table width="200px;"><tr><td align="left"><b><p id="info" style="margin-bottom:0;font-size: 9pt; font-family: tahoma;color:#AAAAAA;">Informacja:</p></b></td></tr><tr><td align="center"><p id="info" style="font-size: 9pt; font-family: tahoma; color: #FFFFFF;">'+info+'</p></td></tr><tr><td align="center"><br/><input type="image" src="../../_img/ok.jpg" border="none" onClick="window.close();"></td></tr></table></center></body></html>';
	wi = window.open("","info", "width=250,height="+height+",scrollbars=no,resizable=no,toolbar=no,userbar=no,location=no,status=no,menubar=no,screenX=100,screenY=100");
	wi.document.write(infohtml);
	return true;
}
function openInfo(info,height){
        var tablt = info.split("&nbsp;");
        info = '';
        for(var cn=0;cn<tablt.length;cn++)info+=tablt[cn]+" ";
        tablt = info.split("<br/>");
        var info='';
        for(var cn=0;cn<tablt.length;cn++)info+=tablt[cn]+"\n";
        tablt = info.split("<br>");
        var info='';
        for(var cn=0;cn<tablt.length;cn++)info+=tablt[cn]+"\n";
        //alert(info);
	dodano.style.visibility="visible";
	document.getElementById("dodano").innerHTML = info;
	setTimeout("dodano.style.visibility='hidden'",8000);
}
function openBasketInfo(info,sum){
	setFlashBasket(sum);
	openInfo(info);
}
function closeInfo(){
	if(wi!=undefined)wi.close();
}
function sendMethodEquation(arg){
	closeInfo();
	var quot = arg.split("#");
	quot = quot[1];
	var sum = xajax.$('basketquote').innerHTML
	sum = (sum*100)+(quot*100);
	sum = Math.round(sum)/100;
	sum = sum.toString()
	sum = sum.split('.');
	if(sum[1]==undefined)sum[1]="00";
	else 	if(sum[1].length==1)sum[1] += "0";
	sum = sum.join('.');
	xajax.$('quote').innerHTML = sum;
}
function checkFieldsAndSend(){
	
	closeInfo();
	var info1 = "Zaznacz odpowiadającą Ci opcję wysylki i ponownie wciśnij przycisk ponizej.";
	var info2 = "Zaznacz odpowiadającą Ci formę płatności. i ponownie wciśnij przycisk ponizej.";
	var form = xajax.$('formSpalsh');
	var gate = xajax.$('gate');
	var sid = '';
	for(i=0;i<form.sid.length;i++){
		if(form.sid[i].checked){
			info1 = '';
			sid = form.sid[i].value.split('#');
			sid = sid[0];
		}
	}
	if(form.sid.checked)
	{
		info1 = '';
		sid = form.sid.value.split('#');
		sid = sid[0];
	
	}


	if(info1=='') 
	{
	form.submit();
	return true;
	}
		
		
	
	openInfo(info1+"<br>"+info2,130);
	return false
}
function showImage(pic){
Sopen="look.php?pic=" + pic;
xlook=window.open(Sopen,'milena','dependent=1,directories=0,titlebar=no,height=145,width=130,location=0,menubar=0,resizable=1,scrollbars=1,status=0,titlebar=0,toolbar=0')
}
function multiply(arg,mu_id,result_id){
	var mu = xajax.$(mu_id).innerHTML;
	mu = (arg*100)*(mu*1);
	mu = Math.round(mu)/100;
	mu = mu.toString()
	mu = mu.split('.');
	if(mu[1]==undefined)mu[1]="00";
	else 	if(mu[1].length==1)mu[1] += "0";
	mu = mu.join('.');
	xajax.$(result_id).innerHTML = mu;
	sumBasket();
}
function sumBasket() {
	var sum = 0;
	for(x=1;x<=basketnumrow;x++){
		sum += xajax.$('mul'+x).innerHTML*1;
	}
	sum =  Math.round(sum*100)/100;
	sum = sum.toString()
	sum = sum.split('.');
	if(sum[1]==undefined)sum[1]="00";
	else 	if(sum[1].length==1)sum[1] += "0";
	sum = sum.join('.');
	xajax.$('basketquote').innerHTML = sum;
	xajax.$('netto_basketquote').innerHTML = Math.round(sum*100*0.8197)/100;
	setFlashBasket(sum+" zł");
}
function checkLoginForm(){
	var form = xajax.$('loginForm');
	var ok = true;
	if(form.password.value==''){
		ok = false;
		alertStyle(form.password);
	}
	if(form.login.value=='' || !Reg(form.login.value,"^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$")){
		ok = false;
		alertStyle(form.login);
	}
	return ok;
}
function checkRegisterForm(){
	var form = xajax.$('registerForm');
	var ok = true;
	if(form.name.value=='' || form.name.value.indexOf(' ')<=0){
		ok = false;
		alertStyle(form.name);
	}
	if(form.street.value=='' || form.street.value.indexOf(' ')<=0){
		ok = false;
		alertStyle(form.street);
	}
	if(form.city.value==''){
		ok = false;
		alertStyle(form.city);
	}
	if(form.code.value.length<6){
		ok = false;
		alertStyle(form.code);
	}
	if(form.email.value=='' || !Reg(form.email.value,"^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$")){
		ok = false;
		alertStyle(form.email);
	}
	return ok;
}

function checkShopForm(){
	var form = xajax.$('addShop');
	var ok = true;
	if(form.nazwa.value==''){
		ok = false;
		alertStyle(form.nazwa);
	}
	if(form.miasto.value==''){
		ok = false;
		alertStyle(form.miasto);
	}
	if(form.adres.value==''){
		ok = false;
		alertStyle(form.adres);
	}
	return ok;
}

function normalizeStyle(field){
	field.style.border = 'solid 1px #666';
	field.style.background = '#EEE'
}
function alertStyle(field){
	field.style.border = 'solid 1px #F00';
	field.style.background = '#FFC';
}
function restrictNumber(ev){
	return restrict(ev,"[0-9]");
}
function restrictNumberPattern(ev,field,pattern){
        if(pattern.substr(field.value.length,1)=='-' && restrict(ev,"[\-]")) return true;
        if(pattern.substr(field.value.length,1)=='-' && restrict(ev,"[0-9]")){
                field.value += '-';
                return true;
        }
        if(restrict(ev,"[0-9]")) return true;
        return false;
}
function restrictEmail(ev,field){
	if(restrict(ev,"[0-9A-Za-z\-_@.]")) return true;
	return false;
}
function restrictLetters(ev){
	return restrict(ev,"[A-Za-z\- ąćęłńóśźżĄĆĘŁŃÓŚŹŻ]");
}
function restrictCityStreet(ev){
	return restrict(ev,"[0-9A-Za-z\- ąćęłńóśźżĄĆĘŁŃÓŚŹŻ/.]");
}

function restrict(ev,reg){
	var cch = getCharCode(ev);
	if(cch==0||cch==8||cch==9)return true;
	var rx = new RegExp(reg);
	var letter = String.fromCharCode(cch)
	if(rx.test(letter)) return true;
	return false;
}
function getCharCode(ev){
	return ev.keyCode==0?ev.charCode:ev.keyCode;
}
function Reg(str,reg){
	var rx = new RegExp(reg);
	return rx.test(str);
}
