function chkObject(inParent,theVal) {

	if(inParent){

		if (window.opener.document.getElementById(theVal) != null) {

			return true;

		} 

		else {

			return false;

		}

	}

	else{

		if (document.getElementById(theVal) != null) {

			return true;

		} 

		else {

			return false;

		}

	}

}




function popup(url)

{
		
     window.open(url);

}



function showEventDivs(optnVar)

{

	if (optnVar == 1)

	{

		$('divPastEventsList').hide();

		$('divFutureEventsList').show();

		$('spanFutureEventsHeader').style.color = "#FF0000";

		$('spanPastEventsHeader').style.color = "#666666";

	}

	else

	{

		$('divFutureEventsList').hide();

		$('divPastEventsList').show();

		$('spanPastEventsHeader').style.color = "#FF0000";

		$('spanFutureEventsHeader').style.color = "#666666";

	}

	

}



function changeMainPicture(PhotoId)

{

	//$('divBigPhoto').innerHTML = '<a href="http://192.168.1.155/sportvision/img_gallery/' + GalleryId + '/or' + PhotoPath + '" rel="shadowbox[gallery]"><img src="http://192.168.1.155/sportvision/img_gallery/' + GalleryId + '/bg' + PhotoPath + '"  /></a>';

	

	/*Shadowbox.init({

			players:    ["qt", "wmp", "flv", "swf", "img"]

		});

	*/

	/*$$('#divBigPhoto a')[0].href = 'img_gallery/' + GalleryId + '/or' + PhotoPath; 

	$$('#divBigPhoto img')[0].src = 'img_gallery/' + GalleryId + '/bg' + PhotoPath;

	$$('#divBigPhoto a')[0].rel = '';

	$$('#divBigPhoto a')[0].onclick = function(){

			Shadowbox.open({

				content:    '<div id="welcome-msg"><img src="img_gallery/' + GalleryId + '/bg' + PhotoPath '"/></div>',

				player:     "html",

				title:      "Welcome",

				height:     350,

				width:      350

			});

		};*/

	

	

	for (i=0; i<picsArray.length; i++)

	{

		$('big_' + picsArray[i]).style.display= "none";

	}

		

	$('big_' + PhotoId).style.display= "block";

	

	

} 



function goToPage(dropDownValue)

{	

	switch (dropDownValue)

	{

		case 'f':

			clLink = $('selectFederatii').value;

			window.location = "clienti/federatii/" + clLink;

			break;

		case 'c':

			clLink = $('selectCluburi').value;

			window.location = "clienti/cluburi/" + clLink;

			break;

		case 'b':

			clLink = $('selectBrandingPersonal').value;

			window.location = "clienti/branding-personal/" + clLink;

			break;

		default:

			alert("Something went wrong..");

	}

}



function navigate(month, year) {

  new Ajax.Request('calendarAjax.php', {

      method: 'get',

      parameters: { paramMonth: month, paramYear: year },

      onSuccess: process,

      onFailure: function() { 

      alert("There was an error with the connection"); 

    }

  });

}



function process(transport) {

  var response = transport.responseText;

//  alert(response);

  $('divCalendar').innerHTML = response;  

}



function incarcaCumparator(clientType, clientId)

{

	//alert (clientType + " " + clientId);

	if (clientType == "user")

	{

		$('divCumparatorFinal').innerHTML = $('divUser').innerHTML;

	}

	else

	{

		$('divCumparatorFinal').innerHTML = $('divCompanyDetails_' + clientId).innerHTML;

	}

	$('clientType').value = clientType;

	$('clientId').value = clientId;

}



function incarcaAdresa(addressType, addressId)

{

	//alert (addressType + " " + addressId);

	if (addressType == "pucu")

	{

		$('divAdresaLivrare').innerHTML = $('divAdresaPucu').innerHTML;	

		$('spanMPRamburs').hide();

		$('spanMPAgrafa').show();

		if ($('paymentType').value == 4)

		{

			$('paymentType').value = 0;

			$('divMP').innerHTML = '';

		}

		$('divNewAddress').hide();

		$('divAdresaLivrare').show();

		clearNewAddressForm();

	}

	else

	{

		if (addressType == "address")

		{

			$('divAdresaLivrare').innerHTML = $('divAddress_' + addressId).innerHTML;

			$('spanMPRamburs').show();

			$('spanMPAgrafa').hide();

			if ($('paymentType').value == 1)

			{

				$('paymentType').value = 0;

				$('divMP').innerHTML = '';

			}

			$('divNewAddress').hide();

			$('divAdresaLivrare').show();

			clearNewAddressForm();

		}

		else

		{

			if ($('paymentType').value == 1)

			{

				$('paymentType').value = 0;

				$('divMP').innerHTML = '';

			}

			$('spanMPRamburs').show();

			$('spanMPAgrafa').hide();

			$('divAdresaLivrare').hide();

			$('divNewAddress').show();

		}

	}

	$('addressType').value = addressType;

	$('addressId').value = addressId;

}



function clearNewAddressForm()

{

	//$('adrAdresa').value = "";

	//$('adrLocalitate').value = "";

	//$('adrIdJudet').value = 1;

	//$('adrCodPostal').value = "";

}

function incarcaModalitatePlata (paymentTypeId)

{

	switch(paymentTypeId)

	{

		case 1:

			$('divMP').innerHTML = "Plata se va efectua în numerar, în momentul ridicării comenzii din sediul Agrafa.";

			break;

		case 2:

			$('divMP').innerHTML = "Plata se va efectua prin ordin de plată.";

			break;

		case 3:

			$('divMP').innerHTML = "Plata se va efectua prin card bancar.";

			break;

		case 4:

			$('divMP').innerHTML = "Plata se va efectua ramburs, în momentul livrării comenzii.";

			break;

	}

	$('paymentType').value = paymentTypeId;

}





function toggleDatePersonaleEdit()

{

//	$('divEditDatePersonale').addClassName("displayBlock");

	//$('divEditDatePersonale').show();

	Effect.Appear('divEditDatePersonale');

}



function displayAddCompanyForm()

{

	Effect.Appear('divAddNewCompanyForm');

}



function changeCartonTab(activeTab)

{

	if (activeTab == 'divTabStandard')

	{

		$('divTabSpecial').removeClassName('divTabCarton_on');

		$('divTabStandard').removeClassName('divTabCarton_off');

		

		$('divTabSpecial').addClassName('divTabCarton_off');

		$('divTabStandard').addClassName('divTabCarton_on');

		

		$('divListaCartoaneSpecial').style.display = "none";		

		$('divListaCartoaneStandard').style.display = "block";

	}

	else

	{

		$('divTabStandard').removeClassName('divTabCarton_on');

		$('divTabSpecial').removeClassName('divTabCarton_off');

		

		$('divTabStandard').addClassName('divTabCarton_off');

		$('divTabSpecial').addClassName('divTabCarton_on');

		

		$('divListaCartoaneStandard').style.display = "none";		

		$('divListaCartoaneSpecial').style.display = "block";

	}

}



function displayBigCartonPicture(cartonPhoto, cartonId)

{

	//alert(cartonId + " " + cartonPhoto);

	img = '<img width="280" height="156" src="product_photos/' + cartonPhoto + '" />';

	$('divPreviewCartoane').innerHTML = img;

	//alert($('spanNumeCarton_' + cartonId).innerHTML);

	$('divPreviewAboveTextSpan').innerHTML = $('divCartText_' + cartonId).innerHTML;

	$('divPreviewAboveTextTitle').innerHTML = $('spanNumeCarton_' + cartonId).innerHTML;

}





function toggleFataVerso(clickedItem)

{

	switch (clickedItem)

	{

		case "fata":

			$('divUnFingurFisier').hide();

			$('divFisierVerso').hide();

			break;

		case "fataVerso":

			$('divUnFingurFisier').show();

			$('divFisierVerso').show();

			break;

		case "check":

			if ($('unSingurFisier').checked == true)

			{

				$('divFisierVerso').hide();

			}

			else

			{

				$('divFisierVerso').show();

			}

			break;

	}

}



function changePrice(typeVar, nameVar, pret)

{

	var cantitate = parseInt($('cantitate').value) * 100;

	if (!cantitate)

	{

		cantitate = 100;

		$('cantitate').value = 1;

	}

	var fataVerso = $('fataVerso').value;

	if (fataVerso == true)

		fataVerso = 'FV';

	else

		fataVerso = 'F';
	

	switch (typeVar)

	{

		case 'cart':

			$('idCarton').value = nameVar;

			$('pretCarton').value = pret;

			break;

		case 'fataVerso':

			

			break;

		case 'plast':

			$('idPlastifiere').value = nameVar;

			$('pretPlastifiere').value = pret;

			break;

		case 'colt':

			$('idColturi').value = nameVar;

			$('pretColturi').value = pret;

			break;

		case 'reducere':

			

			if ($('reducere').checked == true)
			{
				$('pretReducere').value = 1;
				/* modif 02.08.2010 */
				if (fataVerso == "FV")
				{
					alert("Daca alegeti aceasta optiune cartea de vizita va fi printata numai Fata!");
				}
				fataVerso = 'F';
				/* end */
				
			}
			else

				$('pretReducere').value = 0;

			break;

	}

	

	var idCarton = $('idCarton').value;

	

	

	

	

	

	

	var price = 0;

	//alert("fv: " + fataVerso);

	

	for (var index = 0; index < pricesArray.length; index++) 

	{

		/* pentru cazul 1000+ bucati, unde maximul nu e setat si e pus din baza de date automat 0*/

		if (pricesArray[index].max > 0) 

		{

			if ((pricesArray[index].id == idCarton) && (pricesArray[index].fataVerso == fataVerso) && (pricesArray[index].min <= cantitate) && (pricesArray[index].max >= cantitate))

			{

				price = pricesArray[index].price;

			}

		}

		else

		{

			if ((pricesArray[index].id == idCarton) && (pricesArray[index].fataVerso == fataVerso) && (pricesArray[index].min <= cantitate))

			{

				price = pricesArray[index].price;

			}

		}

	}

	

	plastifiere = $('pretPlastifiere').value;

	colturi = $('pretColturi').value;

	carton = price;

	reducere = $('pretReducere').value;

	

	//alert(reducere);

	//alert ("(" + plastifiere + " + " + colturi + " + " + carton + ") * " + cantitate);

	if (reducere == 1)

	{

		price = ((parseFloat(plastifiere) + parseFloat(colturi) + parseFloat(carton)) * parseInt(cantitate)) * (0.7);

	}

	else

	{

		price = (parseFloat(plastifiere) + parseFloat(colturi) + parseFloat(carton)) * parseInt(cantitate);

	}

	$('divPretTotal').innerHTML = price.toFixed(2) + " lei";

	$('pretTotal').value = price;

}



function addHomepageBoxBg(divId)

{

	$(divId).addClassName('bgYellowArrow');

}



function removeHomepageBoxBg(divId)

{

	$(divId).removeClassName('bgYellowArrow');

}



function displayBackgrounds(categId, categName)

{

	previouslySelectedCategory = $('currentlySelectedCategory').value;

	if (previouslySelectedCategory != '')

		$('divBgCateg_' + previouslySelectedCategory).removeClassName('selectedCategory');

	

	$('divBgCateg_' + categId).addClassName('selectedCategory');

	$('currentlySelectedCategory').value = categId;

	

	if (chkObject(false, 'divBackgroundCateg_' + categId) == false)

	{

		$('divDisplayBgImages').innerHTML = "<div class='divNuExistaPoza'>Nu exista poze in aceasta categorie!</div>";

	}

	else

	{

		//$('divDisplayHeaderName').innerHTML = '<b>' + categName + '</b>';

		$('divDisplayBgImages').innerHTML = $('divBackgroundCateg_' + categId).innerHTML;

	}

	

	if ($('divDisplayBgImagesHolder').style.display == "none")

	{

		Effect.Appear('divDisplayBgImagesHolder', { duration: 1 } );

	}



	$('divPersonalizeazaBg').style.display = "block";

}



function closeDisplayBackgrounds()

{

	Effect.Fade('divDisplayBgImagesHolder', { duration: 1 } );

	$('divDisplayHeaderName').innerHTML = "";

	$('divDisplayBgImages').innerHTML = "";

}



function continuaCumpararea() 

{

	if ($('divContinuaCumparareaOption').style.display == "none")

		Effect.SlideDown('divContinuaCumparareaOption', { duration: 1 } );

	else

		Effect.SlideUp('divContinuaCumparareaOption', { duration: 1 } );

}



function selectTemplate(TemplateId)

{

	previouslySelectedTemplate = $('selectedTemplate').value;

	if (previouslySelectedTemplate != '')

	{

		$('divTemplate_' + previouslySelectedTemplate).removeClassName('divSelectedTemplate');

	}

	

	$('divTemplate_' + TemplateId).addClassName('divSelectedTemplate');

	$('selectedTemplate').value = TemplateId;

	

	$('radioTemplate_' + TemplateId).checked = true;

	

	

	return false;

}



function selectBg(BgId)

{

	previouslySelectedBg = $('selectedBg').value;

	if (previouslySelectedBg != '')

	{

		$('divBg_' + previouslySelectedBg).removeClassName('divSelectedBg');

	}

	

	$('divBg_' + BgId).addClassName('divSelectedBg');

	$('selectedBg').value = BgId;

	

	$('radioBg_' + BgId).checked = true;

	

	return false;

}


function OpenPopup(PopupDiv, ItemId)
{
	scroll(0,0);
	MaxHeightOffset = document.body.offsetHeight;
	MaxHeightClient = document.documentElement.clientHeight;
	MaxHeight = Math.max(MaxHeightOffset, MaxHeightClient);
	$('Overlay').style.height = MaxHeight + "px";
	
	$('Overlay').style.display = "block";
	$(PopupDiv).style.display = "block";
	
	$('CartItemId').value=ItemId;
	
	
	return false;
}


function ClosePopup(PopupDiv)
{
	$(PopupDiv).style.display = "none";
	$('Overlay').style.display = "none";
}

function ColorCartonBorder(vElem)
{
	vActiveImagesArr = $$('.imgBorderActive');
	//(vActiveImagesArr.length);
	for (i=0; i<vActiveImagesArr.length; i++)
	{
		vActiveImagesArr[i].className = vActiveImagesArr[i].className.replace('imgBorderActive', ' ');
		vActiveImagesArr[i].className += ' imgBorder';
	}
	
	for (i=0; i<vElem.childNodes.length; i++)
	{
		if (vElem.childNodes[i].name == "poza")
		{
			vElem.childNodes[i].className = vElem.childNodes[i].className.replace('imgBorder', ' ');
			vElem.childNodes[i].className += ' imgBorderActive ';
		}
	}
}
