var WWW_PATH = '/';

function viewProducer(pro)
{
	win_width=650;
	win_height=700;

	pos_left=Math.round((screen.width-win_width)/2);
	pos_top=Math.round((screen.height-win_height)/2);

	// window.open("viewdesigner.php?des="+des+"&lang="+lang, "designer_info", "fullscreen=no,width="+win_width+",height="+win_height+",left="+pos_left+",top="+pos_top+",resizable=yes,scrollbars=yes");
	window.open(WWW_PATH+"producer-detail/"+lang+"/"+pro, "producer_info", "fullscreen=no,width="+win_width+",height="+win_height+",left="+pos_left+",top="+pos_top+",resizable=yes,scrollbars=yes");

	return false;
}

function viewDesigner(des)
{
	win_width=650;
	win_height=700;

	pos_left=Math.round((screen.width-win_width)/2);
	pos_top=Math.round((screen.height-win_height)/2);

	// window.open("viewdesigner.php?des="+des+"&lang="+lang, "designer_info", "fullscreen=no,width="+win_width+",height="+win_height+",left="+pos_left+",top="+pos_top+",resizable=yes,scrollbars=yes");
	window.open(des, "designer_info", "fullscreen=no,width="+win_width+",height="+win_height+",left="+pos_left+",top="+pos_top+",resizable=yes,scrollbars=yes");

	return false;
}

function viewPrint(pro, url)
{
	win_width=750;
	win_height=550;

	pos_left=Math.round((screen.width-win_width)/2);
	pos_top=Math.round((screen.height-win_height)/2);

	open_url = WWW_PATH+"viewprint/"+lang+"/"+pro+"/"+url;

	window.open(open_url, "print_tisk", "fullscreen=no,width="+win_width+",height="+win_height+",left="+pos_left+",top="+pos_top+",resizable=yes,scrollbars=yes");

	return false;
}

function printPage(lang)
{
	if (lang == "cz")
	{
		printIt = confirm('Před tiskem si nastavte orientaci stránky na šířku.');
	} else {
		printIt = confirm('Before printing please change the page orientation.');
	}

	if (printIt) { window.print(); }

	return false;
}


function request(typ, id)
{
	pos_left=Math.round((screen.width-500)/2);
	win_width=500;

	pos_top=Math.round((screen.height-450)/2);

    // request[typ] = window.open("viewrequest.php?id="+id+"&typ="+typ+"&lang="+lang, "request_"+typ, "fullscreen=no,width="+win_width+",height=450,left="+pos_left+",top="+pos_top+",resizable=no,scrollbars=no");
	request[typ] = window.open(WWW_PATH+"request/"+lang+"/"+typ+"/"+id, "request_"+typ, "fullscreen=no,width="+win_width+",height=450,left="+pos_left+",top="+pos_top+",resizable=no,scrollbars=no");
	request[typ].focus();

	return false;
}


function workshop_check(lang)
{
	var name = document.getElementsByName("form[name]")[0];
	var surname = document.getElementsByName("form[surname]")[0];
	var company = document.getElementsByName("form[company]")[0];
	var email = document.getElementsByName("form[email]")[0];
	var persons = document.getElementsByName("form[persons]")[0];

	error = false;

	if (name.value.length < 2) { error = true; }
	if (surname.value.length < 2) { error = true; }
	if (company.value.length < 2) { error = true; }
	if (persons.value < 1) { error = true; }

	if (error)
	{
		if (lang == "cz"){ alert("Prosím, vyplňte pole označená *"); }
		if (lang == "en"){ alert("Please, complete the * fields"); }

		return false;
	}

	return emailCheck(email.value, lang);
}


function request_step1(lang)
{
	var name = document.getElementsByName("form[name]")[0];
	var surname = document.getElementsByName("form[surname]")[0];
	var country = document.getElementsByName("form[country]")[0];
	var email = document.getElementsByName("form[email]")[0];

	error = false;

	if (name.value.length < 2) { error = true; }
	if (surname.value.length < 2) { error = true; }
	if (country.value.length < 2) { error = true; }
	
	if (error)
	{
		if (lang == "cz"){ alert("Prosím, vyplňte pole označená *"); }
		if (lang == "en"){ alert("Please, complete the * fields"); }

		return false;
	}

	if (!emailCheck(email.value, lang)) {
	
    	return false;
    	
    } else {
    
        var step1 = document.getElementById('step-1');
        var step2 = document.getElementById('step-2');
        
        step1.className = "display-none";
        step2.className = "display-block";
        
        return false; 
    }
}


function request_step2(lang)
{
    var step1 = document.getElementById('step-1');
    var step2 = document.getElementById('step-2');   
    
    step1.style.visibility = "hidden";
    step2.style.visibility = "hidden";

    step1.className = "display-block";
        
    return true; 
}


function sendpage(url)
{
	pos_left=Math.round((screen.width-300)/2);
	pos_top=Math.round((screen.height-350)/2);

	window.open(WWW_PATH+"viewsendpage/"+lang+"/"+url, "_blank", "fullscreen=no,width=300,height=350,left="+pos_left+",top="+pos_top+",resizable=no,scrollbars=no");

	return false;
}


function sendpage_check(lang)
{
	var sender = document.getElementsByName("form[sender]")[0];
	var recipient = document.getElementsByName("form[recipient]")[0];

	return emailCheck(sender.value, lang);
	return emailCheck(recipient.value, lang);
}


function clearSubmit(submit)
{
	if ((submit.value == 'search >') || (submit.value == 'hledat >')) {
		submit.value = '';
	}
}
	


/*******************************************************************************/
/*
/*  EMAIL CHECK SCRIPT | ver 0.2
/* 
/*  Original author: unknown         
/*
/*  Modified by: c0rw | www.coex.cz | 2oo4-2oo5
/*
/*******************************************************************************/

function emailCheck (emailStr,lang) {

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) {
    if (lang=='en') { alert("Email check: address seems incorrect (check @ and .'s)"); }
    if (lang=='cz') { alert("Kontrola emailu: adresa je zřejmě neplatná (chybí @ nebo .)"); }
    return false;
}

var user=matchArray[1];
var domain=matchArray[2];

if (user.match(userPat)==null) {
    if (lang=='en') { alert("Email check: the username doesn't seem to be valid."); }
    if (lang=='cz') { alert("Kontrola emailu: uživatelské jméno je zřejmě neplatné."); }
    return false;
}

var IPArray=domain.match(ipDomainPat);

if (IPArray!=null) {
  for (var i=1;i<=4;i++) {
    if (IPArray[i]>255) {
        if (lang=='en') { alert("Email check: destination IP address is invalid!"); }
        if (lang=='cz') { alert("Kontrola emailu: cílová IP adresa není správná!"); }
    return false;
    }
  }
  return true;
}

var domainArray=domain.match(domainPat);

if (domainArray==null) { 
    if (lang=='en') { alert("Email check: the domain name doesn't seem to be valid."); }
    if (lang=='cz') { alert("Kontrola emailu: doména je zřejmě neplatná."); }    
    return false; 
}

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) {
   if (lang=='en') { alert("Email check: the address must end in a three-letter domain, or two letter country."); }
   if (lang=='cz') { alert("Kontrola emailu: adresa musí končit platnou koncovkou."); }
   return false;
}

if (len<2) {
   if (lang=='en') { alert("Email check: this address is missing a hostname!"); }
   if (lang=='cz') { alert("Kontrola emailu: zřejmě chybí název hostitele!"); }
   return false;
}

return true;
}

