﻿function eshopStartIE() {
	// code for IE
	if(!document.body.currentStyle) return;
	var subs = document.getElementsByName('submenu');
	for(var i=0; i<subs.length; i++) {
		var li = subs[i].parentNode;
		if(li && li.lastChild.style) {
			li.onmouseover = function() {
				this.lastChild.style.visibility = 'visible';
			}
			li.onmouseout = function() {
				this.lastChild.style.visibility = 'hidden';
			}
		}
	}
}

function gCook( name ) {
	var start = document.cookie.indexOf( name + "=" );
	var len = start + name.length + 1;
	if ( ( !start ) && ( name != document.cookie.substring( 0, name.length ) ) ) {
		return null;
	}
	if ( start == -1 ) return null;
	var end = document.cookie.indexOf( ';', len );
	if ( end == -1 ) end = document.cookie.length;
	return unescape( document.cookie.substring( len, end ) );
}

function sCook( name, value, expires, path, domain, secure ) {
	var today = new Date();
	today.setTime( today.getTime() );
	if ( expires ) {
		expires = expires * 1000 * 60 * 60 * 24;
	}
	var expires_date = new Date( today.getTime() + (expires) );
	document.cookie = name+'='+escape( value ) +
		( ( expires ) ? ';expires='+expires_date.toGMTString() : '' ) + //expires.toGMTString()
		( ( path ) ? ';path=' + path : '' ) +
		( ( domain ) ? ';domain=' + domain : '' ) +
		( ( secure ) ? ';secure' : '' );
}

function dCook( name, path, domain ) {
	if ( gCook( name ) ) document.cookie = name + '=' +
			( ( path ) ? ';path=' + path : '') +
			( ( domain ) ? ';domain=' + domain : '' ) +
			';expires=Thu, 01-Jan-1970 00:00:01 GMT';
}

function inArray(needle, haystack) {
    var length = haystack.length;
    for(var i = 0; i < length; i++) {
        if(haystack[i] == needle) return true;
    }
    return false;
}

function places(show, indexes) {
	var ind = indexes.split(' ');
	if(inArray(show.options[show.selectedIndex].value, ind))
		document.getElementById("placeholder").style.visibility = 'visible';
	else
		document.getElementById("placeholder").style.visibility = 'hidden';
}

function notprague(show) {
	if(show.selectedIndex!=0) {
		var txt = '<h4>Upozornění</h4>';
			txt += 'Stavy zásob u jednotlivých kusů zboží zrcadlí <b>stav skladu na centrále v Praze</b> a je proto možné, že některé Vámi vybrané zboží bude dostupné až dle závozu jednotlivých poboček. O dostupnosti zboží na pobočce budete informováni co nejdříve. Děkujeme. ';
			
		$.prompt(txt,{
			buttons: { Potvrdit: true}
		});
	}
}

function contactperson(show) {
	if(show.options[show.selectedIndex].value == 1) {
		document.getElementById("cont_pers").style.visibility = 'visible';
		document.getElementById("firholder").style.display = 'block';
		document.getElementById("labelid").innerHTML = 'Firma* :';
	}
	else {
		document.getElementById("cont_pers").style.visibility = 'hidden';
		document.getElementById("firholder").style.display = 'none';
		document.getElementById("labelid").innerHTML = 'Jméno a příjmení* :';
	}
}

function mod_order(id, formelem) {
	
	switch(id.options[id.selectedIndex].value) {
		case "resend":
			var txt = '<h4>Shrnutí objednávky</h4>';
			txt += 'Znovu odeslat e-mail se shrnutím objednávky?<br /><br  /> ';
			txt += 'Samotná objednávka se prodejci znovu neodesílá, jedná se pouze o kopii pro Vás. ';
				
			function mycallbackform_order_resend(v,m,f){
				if(v != undefined) {
					if(v==true) document.getElementById(formelem).submit();
					else id.selectedIndex=0;
				}
				else id.selectedIndex=0;
			}
			
			$.prompt(txt,{
					callback: mycallbackform_order_resend,
				buttons: { Odeslat: true, Zrušit: false }
			});
			
			break;
		case "list":
			var txt = '<h4>Obsah objednávky</h4>';
			txt += document.getElementById(formelem+'_list').value;
			
			$.prompt(txt,{
				buttons: { Zavřít: true}
			});
			
			id.selectedIndex=0;
			break;
		case "refresh":
			var txt = '<h4>Obnovení košíku</h4>';
			txt += 'Vytvoří kopii vybrané objednávky do nového košíku.<br /><br /> ';
			txt += '<b>Název nového košíku:</b> <br /><input type="text" class="inpt" id="newname" name="newname" value="" />';
				
			function mysubmitform_order_refresh(v,m,f){
				if(v != undefined) {
					if(v==true) {
						if(f.newname.length>0) {
							document.getElementById(formelem+'_newname').value = f.newname;
							document.getElementById(formelem).submit();
							return true;
						}
						else {id.selectedIndex=0; return false;}
					}
					else {id.selectedIndex=0; return true;}
				}
			}
			
			function mycallbackform_order_refresh(v,m,f){
				id.selectedIndex=0;
			}
			
			$.prompt(txt,{
				submit: mysubmitform_order_refresh,
				callback: mycallbackform_order_refresh,
				buttons: { Obnovit: true, Zrušit: false }
			});
			
			break;
	}
}

function mod_basket(id, formelem) {
	
	switch(id.options[id.selectedIndex].value) {
		case "rename":
			var txt = '<h4>Přejmenování košíku</h4>';
			txt += 'Umožňuje přizpůsobit si názvy košíků vlastním potřebám.<br /><br /> ';
			txt += '<b>Nový název košíku:</b> <br /><input type="text" class="inpt" id="newname" name="newname" value="" />';
				
			function mysubmitform_basket_rename(v,m,f){
				if(v != undefined) {
					if(v==true) {
						if(f.newname.length>0) {
							document.getElementById(formelem+'_newname').value = f.newname;
							document.getElementById(formelem).submit();
							return true;
						}
						else {id.selectedIndex=0; return false;}
					}
					else {id.selectedIndex=0; return true;}
				}
				
			}
			
			function mycallbackform_basket_rename(v,m,f){
				id.selectedIndex=0;
			}
			
			$.prompt(txt,{
				submit: mysubmitform_basket_rename,
				callback: mycallbackform_basket_rename,
				buttons: { Přejmenovat: true, Zrušit: false }
			});
			
			break;
		case "copy":
			var txt = '<h4>Kopírování košíku</h4>';
			txt += 'Vytvoří kopii košíku s identickými položkami pod novým názvem.<br /><br /> ';
			txt += '<b>Název nového košíku:</b> <br /><input type="text" class="inpt" id="newname" name="newname" value="" />';
				
			function mysubmitform_basket_copy(v,m,f){
				if(v != undefined) {
					if(v==true) {
						if(f.newname.length>0) {
							document.getElementById(formelem+'_copyname').value = f.newname;
							document.getElementById(formelem).submit();
							return true;
						}
						else {id.selectedIndex=0; return false;}
					}
					else {id.selectedIndex=0; return true;}
				}
			}
			
			function mycallbackform_basket_copy(v,m,f){
				id.selectedIndex=0;
			}
			
			$.prompt(txt,{
				submit: mysubmitform_basket_copy,
				callback: mycallbackform_basket_copy,
				buttons: { Kopírovat: true, Zrušit: false }
			});
			
			break;
		case "forward":
			var txt = '<h4>Přeposlat košík</h4>';
			txt += 'Zašle na zadanou e-mailovou adresu kopii zvoleného košíku. ';
			txt += 'Pokud e-mailová adresa patří registrovanému uživateli e-shopu, obdrží adresát upozornění o novém uživatelském košíku. ';
			txt += 'Jinak se adresátovi odešle e-mail s odkazem, přes který se otevře e-shop s Vašimi položkami v košíku. ';
			txt += 'Lze vyplnit i vzkaz, který se adresátovi zobrazí v úvodu e-mailu.<br /><br />';
			txt += '<b>E-mailová adresa:</b> <br /><input type="text" class="inpt" id="email" name="email" value="" /><br /><br />';
			txt += '<b>Úvodní text:</b> <br /><textarea id="message" class="inpt" name="message"></textarea>';
				
			function mysubmitform_basket_forward(v,m,f){
				if(v != undefined) {
					if(v==true) {
						mail=/^.+@.+\..{2,4}$/;
						if(mail.test(f.email)==true) {
							document.getElementById(formelem+'_forward_email').value = f.email;
							document.getElementById(formelem+'_forward_message').value = f.message;
							document.getElementById(formelem).submit();
							return true;
						}
						else {
							m.children('#email').css("color","#ff0000");
							return false;
						}
					}
					else {
						id.selectedIndex=0;
						return true;
					}
				}
			}
			
			function mycallbackform_basket_forward(v,m,f){
				id.selectedIndex=0;
			}
			
			$.prompt(txt,{
				submit: mysubmitform_basket_forward,
				callback: mycallbackform_basket_forward,
				buttons: { Přeposlat: true, Zrušit: false }
			});
			
			break;
		case "delete":
			var txt = '<h4>Odstranění košíku</h4>';
			txt += 'Opravdu chcete odstranit tento košík?<br /><br  /> ';
				
			function mycallbackform_basket_delete(v,m,f){
				if(v != undefined) {
					if(v==true) document.getElementById(formelem).submit();
					else id.selectedIndex=0;
				}
				else id.selectedIndex=0;
			}
			
			$.prompt(txt,{
				callback: mycallbackform_basket_delete,
				buttons: { Odstranit: true, Zrušit: false }
			});
			
			break;
		case "switch":
		case "order":
			document.getElementById(formelem).submit();
			break;
		case "list":
			var txt = '<h4>Obsah košíku</h4>';
			txt += document.getElementById(formelem+'_list').value;
			
			$.prompt(txt,{
				buttons: { Zavřít: true}
			});
			
			id.selectedIndex=0;
			break;
	}
}

function newbasket(id) {
	var txt = '<h4>Vytvoření košíku</h4>';
	txt += 'Vytvoří nový košík pro lepší organizaci Vašich nákupů.<br /><br /> ';
	txt += '<b>Název nového košíku:</b> <br /><input type="text" class="inpt" id="newname" name="newname" value="' + document.getElementById('new_basket_name').value + '" />';
		
	function mysubmitform_basket_create(v,m,f){
		if(v != undefined) {
			if(v==true) {
				if(f.newname.length>0) {
					document.getElementById('new_basket_name').value = f.newname;
					document.getElementById('new_basket').submit();
					return true;
				}
				else return false;
			}
			else return true;
		}
	}
	
	$.prompt(txt,{
		submit: mysubmitform_basket_create,
		buttons: { Vytvořit: true, Zrušit: false }
	});
	
	return false;
}

function osd_feedback_show(txt) {
	$.prompt(txt,{
		buttons: { Zavřít: true }
	});
}

