// JavaScript Document

function showMenuPos(pozID, banerSrc, linkHref) {

	if (banerSrc != '') {

		var mainMenuImg;
		mainMenuImg = document.getElementById('mainMenuImg');
		
		if (mainMenuImg != null)
		{
			mainMenuImg.src = banerSrc;
			
			//jeszcze linka dorob
			$("#mainMenuImgLink").attr('href', linkHref );
		}
	
	}
	
}


function modifyText() {

	var fieldFirm		=	document.getElementById('fieldFirm');
	var fieldName		=	document.getElementById('fieldName');
	var fieldSurname	=	document.getElementById('fieldSurname');
	var fieldAddress	=	document.getElementById('fieldAddress');
	var fieldCity		=	document.getElementById('fieldCity');
	var fieldCode		=	document.getElementById('fieldCode');
	var fieldRegion		=	document.getElementById('fieldRegion');


	var fieldWFirm		=	document.getElementById('fieldWFirm');
	var fieldWName		=	document.getElementById('fieldWName');
	var fieldWSurname	=	document.getElementById('fieldWSurname');
	var fieldWAddress	=	document.getElementById('fieldWAddress');
	var fieldWCity		=	document.getElementById('fieldWCity');
	var fieldWCode		=	document.getElementById('fieldWCode');
	var fieldWRegion	=	document.getElementById('fieldWRegion');



	fieldWFirm.value		=	fieldFirm.value;
	fieldWName.value		=	fieldName.value;
	fieldWSurname.value		=	fieldSurname.value;
	fieldWAddress.value		=	fieldAddress.value;
	fieldWCity.value		=	fieldCity.value;
	fieldWCode.value		=	fieldCode.value;
	fieldWRegion.selectedIndex		=	fieldRegion.selectedIndex;


}

function pokazAdresWysylki(pokaz) {
	
	var adresWysylkiBox = document.getElementById('adresWysylkiBox');
	if (pokaz) {
		adresWysylkiBox.style.display = 'block';
	}
	else {
		adresWysylkiBox.style.display = 'none';
	}
	
}



function sprawdzEmail(email) {
	advAJAX.post(
	{
		url: "includes/xmlConn.php?type=emailValid",
		email : email,
		onSuccess : function(obj) {
			var emailWolny = document.getElementById('emailWolny');
			var xml = obj.responseXML.documentElement;
			var value = xml.childNodes[0].childNodes[0].nodeValue;
			if (value == 'TRUE') {

				emailWolny.value = 'true';
			}
			else
			{

				emailWolny.value = 'false';
			}

			
			
			//jeszcze raz sprawdz pole maila czy jest poprawne
			sprytextfield1.validate();
			
		}
	}
	);
}
/*
function setMainImage(imageName, bigImageName) {
	
	//imgBigLink
	
	var imgBigLink = document.getElementById('imgBigLink');
	imgBigLink.setAttribute('href', 'produkty/foto/' + bigImageName);


	var productMainImage = document.getElementById('productMainImage');
	productMainImage.src = 'produkty/foto/' + imageName;
	
}*/

function setMainImage(imageName, orgImageName, fotoNum) {

	var productMainImage = document.getElementById('productMainImage');
	productMainImage.src = 'produkty/foto/' + imageName;
	
	
	//szukaj elementu do powiekszania
	var powiekszZdjecieBtn;
	powiekszZdjecieBtn = document.getElementById('powiekszZdjecieBtn');
	
	if (powiekszZdjecieBtn)
	{
		powiekszZdjecieBtn.setAttribute('href', 'produkty/foto/' + orgImageName);
	}
	
	
	var mainImageInBigSizeLink;
	mainImageInBigSizeLink = document.getElementById('mainImageInBigSizeLink');
	
	if (mainImageInBigSizeLink)
	{
		mainImageInBigSizeLink.setAttribute('href', 'produkty/foto/' + orgImageName);
	}
	
}

function dodajDoKoszyka(boxID) {
	
	
	var curBoxID = 0;
	
	var curBoxObj = null;
	
	//odznacz pozostale
	do {
		
		curBoxObj = document.getElementById('szybkieDK_' + curBoxID);
		
		if (curBoxObj != null && boxID != curBoxID) {
			uDKW(curBoxID);
		}
		
		curBoxID++;
		
	} while( curBoxObj != null );
	
	
	
	var b_przechowalnia = document.getElementById('b_przechowalnia_' + boxID);
	var b_caly = document.getElementById('b_caly_' + boxID);

	var szybkieDK = document.getElementById('szybkieDK_' + boxID);

	if (b_przechowalnia)
	b_przechowalnia.style.display = 'none';
	
	if (b_caly)
	b_caly.style.display = 'none';
	
	if (szybkieDK)
	szybkieDK.style.display = 'block';
	
}


function uDKW(boxID) {

	//anuluj dodawanie do koszyka
	var b_przechowalnia = document.getElementById('b_przechowalnia_' + boxID);
	var b_caly = document.getElementById('b_caly_' + boxID);

	var szybkieDK = document.getElementById('szybkieDK_' + boxID);

	if (b_przechowalnia)
	b_przechowalnia.style.display = 'block';
	
	if (b_caly)
	b_caly.style.display = 'block';
	
	if (szybkieDK)
	szybkieDK.style.display = 'none';

	
}

function DKW(boxID) {
	
	//szybkie dodawanie do koszyka, pobierz ilosc pobierz produkt ID i wrzuc do koszyka
	
	var produktID = document.getElementById('produktID_' + boxID).value;
	var ilosc = dojo.byId("iloscDK_" + boxID).value;

	window.location = 'http://hurtownia.hurtico.pl/koszyk/action=addProduct&nextaction=lastView&id=' + produktID + '&ilosc=' + ilosc;

}

function DKWnkP(boxID) {
	
	//szybkie dodawanie do koszyka, pobierz ilosc pobierz produkt ID i wrzuc do koszyka
	
	var formObj = document.getElementById('form_' + boxID);
	formObj.submit();

}


function navAnim(name) {

	var topNavi_tel = document.getElementById('topNavi_tel');
	var topNavi_gg = document.getElementById('topNavi_gg');
	var topNavi_skype = document.getElementById('topNavi_skype');
	
	topNavi_tel.style.display = 'none';
	topNavi_gg.style.display = 'none';
	topNavi_skype.style.display = 'none';
	
	if (name == 'tel') topNavi_tel.style.display = 'inline';
	if (name == 'gg') topNavi_gg.style.display = 'inline';
	if (name == 'skype') topNavi_skype.style.display = 'inline';
	
	
}

function dodajDoPowiadomienODostepnosci( produktID ) {
	
	advAJAX.post(
	{
		url: "includes/xmlConn.php?type=addToInformation&pId=" + produktID,
		onSuccess : function(obj) {

			//alert(obj.responseText);
			var btnPowiadomienieBox = document.getElementById('btnPowiadomienieBox_' + produktID);
			btnPowiadomienieBox.innerHTML = '<a class="button_a_powiadomienie" title="Ten produkt jest aktualnie niedostepny, lecz dostaniesz powiadomienie na e-mail, gdy bedzie dostepny ponownie w naszej ofercie."></a>';
			
		}
	}
	);
}

function dodajDoPrzechowalni( produktID, nr ) {
	
	advAJAX.post(
	{
		url: "/includes/xmlConn.php?type=addToP&pId=" + produktID,
		onSuccess : function(obj) {


			var btnPrzechowalniaBox = document.getElementById('btnPrzechowalniaBox_' + produktID);
			btnPrzechowalniaBox.innerHTML = '<a id="b_przechowalnia_' + nr + '" class="button_a_przechowalnia" title="Tej produkt znajduje sie w Twojej przechowalni"></a>';

		}
	}
	);

	

}

function selectAll(startName, value) {


	var i;
	var firstE;

	i = 0;

	do {

		firstE = document.getElementById(startName + i);

		firstE.checked = value;

		i++;

	} while ( firstE != null );

}

function submitForm (formName) {
	
	var formObj = document.getElementById(formName);
	formObj.submit();
	
}

function ValidNIP(input_data)
{
	//
	
	if ( !input_data.match( /^[0-9]{3}-[0-9]{2}-[0-9]{2}-[0-9]{3}$/ )
	&& !input_data.match( /^[0-9]{3}-[0-9]{3}-[0-9]{2}-[0-9]{2}$/ ) )
	return false;
	var my_nums = input_data.replace(/-/g,'');
	var valid_nums = "657234567";
	var sum=0;
	for (var temp=8;temp>=0;temp--)
	sum += (parseInt(valid_nums.charAt(temp)) * parseInt(my_nums.charAt(temp)));
	if ( (sum % 11) == 10 ? false : ((sum % 11) == parseInt(my_nums.charAt(9))) )
	return true;
	else
	return false;
}

