var tact=1;

var tcnt=0;

function tslide() {
  if(!tcnt) return;

  $("#tl"+tact).fadeOut('slow', function() {

      if(tact==tcnt) tact=1; else tact++;

      $("#tl"+tact).fadeIn('slow', function() {

        window.setTimeout("tslide()",1000);

      });

    });



}



function m_polec(typ,tytul,url) {

  window.open('pop_recomend.php?k='+typ+'&t='+tytul+'&i='+url,'polec','width=400,height=500,left=20,top=10,scrollbars=yes,resizable=yes,status=yes');

} 

 

function m_zapytaj(typ,tytul,url) {

  window.open('pop_product_ask.php?k='+typ+'&t='+tytul+'&i='+url,'polec','width=400,height=375,left=20,top=10,scrollbars=yes,resizable=yes,status=yes');

} 

 

function CreateControl(src,width,height,url)

{

  if(url!="") src = src+"?clickTAG="+url

  document.write('<object type="application/x-shockwave-flash" width="'+width+'" height="'+height+'" data="'+src+'"><param name="type" value="application/x-shockwave-flash" /><param name="movie" value="'+src+'" /><param name="quality" value="high" /><param name="codebase" value="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" /><param name="wmode" value="transparent" /><param name="always" value="allowscriptaccess" /><param name="pluginspage" value="http://www.macromedia.com/go/getflashplayer" />');

  document.writeln('</object>');

}



function m_druk(typ,id) {

  switch(typ) {

    case "produkt": adres="pop_product"; break;

  }

  popup(adres+'.php?i='+id,'druk');

}



function m_set_mark(i) {

  for(var n=1; n<6; n++) {

    document.getElementById('oc'+n).className=(n<=i?'ocena_on':'ocena_off');

  }

  document.getElementById('op_ocena').value=i;

}

function m_validate_mark() {

  var err = '';

  if(document.getElementById('op_autor').value=='') err += '- wprowadź swoje imię i nazwisko\n';

  if(document.getElementById('op_tresc').value=='') err += '- wprowadź treść komentarza\n';

  if(document.getElementById('op_kod').value=='') err += '- przepisz kod z obrazka\n';

  if(err!='') {

    alert('Błąd wypełniania formularza:\n'+err);

    return false;

  } 

  return true;

}

function m_refreshimage(obj){

  obj.src = obj.src + '#';

}



function allValidChars(email) {

  var parsed = true;

  var validchars = "abcdefghijklmnopqrstuvwxyz0123456789@.-_";

  for (var i=0; i < email.length; i++) {

    var letter = email.charAt(i).toLowerCase();

    if (validchars.indexOf(letter) != -1)

      continue;

    parsed = false;

    break;

  }

  return parsed;

}



function isValidEmail(email, required) {

    if (required==undefined) {   // if not specified, assume it's required

        required=true;

    }

    if (email==null) {

        if (required) {

            return false;

        }

        return true;

    }

    if (email.length==0) {  

        if (required) {

            return false;

        }

        return true;

    }

    if (! allValidChars(email)) {  // check to make sure all characters are valid

        return false;

    }

    if (email.indexOf("@") < 1) { //  must contain @, and it must not be the first character

        return false;

    } else if (email.lastIndexOf(".") <= email.indexOf("@")) {  // last dot must be after the @

        return false;

    } else if (email.indexOf("@") == email.length) {  // @ must not be the last character

        return false;

    } else if (email.indexOf("..") >=0) { // two periods in a row is not valid

	return false;

    } else if (email.indexOf(".") == email.length) {  // . must not be the last character

	return false;

    }

    return true;

}



function my_numbers(obj,e){

  if(error && obj.name!=error_obj) {return false;}

  var keynum;

  var keychar;

  var numcheck;



  if(window.event)  {keynum = e.keyCode;  } // IE

  else if(e.which) {keynum = e.which;}// Netscape/Firefox/Opera 

  keychar = String.fromCharCode(keynum);

  numcheck = /\d/;

  if(numcheck.test(keychar) || keynum==110 || keynum==188 || keynum==8 || keynum==9 ||  (keynum>95 && keynum<109) || (keynum>=37 && keynum<=40)) return true;

  return false;

}



var PopupWindows = new Array();

PopupWindows["standard"] = "width=1150,height=800,scrollbars=yes,resizable=yes,status=yes"; 

PopupWindows["polec"] = "width=500,height=400,scrollbars=yes,resizable=yes,status=yes"; 

PopupWindows["pomoc"] = "width=800,height=550,left=20,top=10,scrollbars=yes,resizable=yes,status=yes"; 

PopupWindows["druk"] = "width=700,height=600,left=20,top=10,scrollbars=yes,resizable=yes,status=yes,menubar=1"; 

PopupWindows["panel"] = "width=760,height=650,left=20,top=10,scrollbars=no,resizable=no,status=yes"; 

PopupWindows["panel2"] = "width=990,height=650,left=20,top=10,scrollbars=yes,resizable=yes,status=yes"; 

PopupWindows["panel3"] = "width=1000,height=750,left=20,top=5,scrollbars=yes,resizable=yes,status=yes"; 

function popup(url, name, parameter) {

  if (name == "" || name == null) {

		name = "standard";

	}

	if (PopupWindows[name] != null) {

		parameter = PopupWindows[name];

	}

	else if (parameter == "" || parameter == null) {

		parameter = PopupWindows["standard"];

	}



	var width, height, left = null, top = null;

	temp = parameter.split(",");

	for (var i = 0; i < temp.length; i++) {

		values = temp[i].split("=");

		if (values[0] == "width") width = parseInt(values[1]);

		if (values[0] == "height") height = parseInt(values[1]);

		if (values[0] == "left") left = parseInt(values[1]);

		if (values[0] == "top") top = parseInt(values[1]);

	}

	if (left == null) {

		left = Math.round((screen.width - width) / 2);

	}

	if (top == null) {

		top = Math.round((screen.height - height) / 3);

	}

	if (left != null) {

		parameter += ",screenX="+left+",left="+left;

	}

	if (top != null) {

		parameter += ",screenY="+top+",top="+top;

	}

//alert(url+ " " +name+ " "+parameter);

	var popuphandler = 	window.open(url, name, parameter);

	if (popuphandler != null) {

		popuphandler.window.focus();

	}	else {

	  alert('Nie można otworzyć wymaganego okna!');

	}

} 



