function cartAdd( product, quantity ){
	var label = '';
	
	if($('pro-label-checkbox') && $('pro-label-checkbox').checked == true) {
		label = $('pro-label-input').value;
	}
	
	var request_url = host_url + '/www/ajax.php?order=' + product + '&label=' + label;
	
	if( quantity!='' ) request_url+= '&quantity='+quantity;
	
	showInfo( "Dodawanie do koszyka" );

	var json = new cmsAjaxResponse(request_url, {loader: false }).doRequest();
}

function showInfo( text ){

	width = 190;
	height = 140;
	
	windowHeight = getVisibleHeight();
	if (document.documentElement && document.documentElement.scrollTop) theTop = document.documentElement.scrollTop;
	else theTop = document.body.scrollTop;
	
	$('cartInfo').style.top = (theTop+(windowHeight/2)-(height/2)-45)+'px';
	$('cartInfo').style.left = (document.body.scrollLeft+((document.body.clientWidth)/2)-(width/2)-5)+'px';
	
	$('cartInfoText').innerHTML = text;
	$('cartInfo').style.display = "block";
	//$('cartInfo').style.zIndex = "1000";
	
}

function closeInfoTimeout(){
	setTimeout("closeInfo()", 500);
}

function closeInfo(){
	$('cartInfo').style.display = "none";
}


function getVisibleHeight(Width, Height) {
	var myWidth = 0, myHeight = 0;
	if( typeof( window.innerWidth ) == 'number' ) {
	//Non-IE
	myWidth = window.innerWidth;
	myHeight = window.innerHeight;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
	//IE 6+ in 'standards compliant mode'
	myWidth = document.documentElement.clientWidth;
	myHeight = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
	 //IE 4 compatible
	myWidth = document.body.clientWidth;
	myHeight = document.body.clientHeight;
	}
	return myHeight;
}


function showHide(e){

	obj = document.getElementById(e);
	if (obj.style.display == "none"){
		obj.style.display = '';
	}
	else{
		obj.style.display = 'none';
	}
}

function clearForm( form ){
	
	var form = document.forms[form];
	if(form==null) return false;
	
	var elements = form.elements;
	
	for(var index=0; index<elements.length; index++) 
	{
		if(elements[index].nodeName.toUpperCase() == 'INPUT' && elements[index].type.toUpperCase() == 'TEXT')
			elements[index].value = '';
		if(elements[index].nodeName.toUpperCase() == 'SELECT')
			elements[index].selectedIndex = 0;
	}
	return true;
}

function userOtherPlaceChange(){
	var form = document.forms['form_user'];
	
	if (form.place_other.checked){
		form.place_name.readOnly = false;
		form.place_surname.readOnly = false;
		form.place_country.readOnly = false;
		form.place_address.readOnly = false;
		form.place_postcode.readOnly = false;
		form.place_city.readOnly = false;
	}
	else{
		form.place_name.readOnly = true;
		form.place_surname.readOnly = true;
		form.place_country.readOnly = true;
		form.place_address.readOnly = true;
		form.place_postcode.readOnly = true;
		form.place_city.readOnly = true;
	}
}


function userSearch(){
	var form = document.forms['formSearch'];
	
	if(checkSearch()){
		form.submit();
	}
}


function userPerPage(){
	var form = document.forms['formPerPage'];
	
	if(true){
		form.submit();
	}
}

function checkSearch(){
	var accept = true
	var form = document.forms['formSearch'];
	
	if(form==null)	return true;
	obj = form.elements;

	var error=0;
	var i=0;
	for(i=0;i<obj.length;i++){
		if( obj[i].name.indexOf("search")!=-1 ){
			if (obj[i].id == 'text' && obj[i].value==""){
				obj[i].className = 'input_error';
				error=1;
				continue;
			}
			if (obj[i].id == 'int' && (!parseInt(obj[i].value) && obj[i].value!=0) && obj[i].value!=''){
				obj[i].className = 'input_error';
				error=1;
				continue;
			}
			if( obj[i].className == 'input_error'){
				obj[i].className = 'input_ok';
			}
		}
	}
	if(error){
		alert('Wypelnij poprawnie wszystkie czerwone pola');
		return false;
	}
	else{
		return true;
	}	
}

function editCurrency(){

	var accept = true
	var form = document.forms['form_currency'];
	
	if(form.cur_title.value==""){
		accept = false;
	}
	if (accept) {
		form.submit();
	}
	else{
		alert('Podaj nazwe waluty!');
	}
}

/* Spacjany napis */

function toggleSpecialLabel() {
	
	var displayStyle = $('label-input-block').getStyle('display');
	if(displayStyle == 'none') {		
		
		$('label-input-block').setStyle('display', 'block');
		$('new-label').setStyle('visibility', 'visible');
		$('pro-label-input').value = 'Twoja etykieta';
	}else if(displayStyle == 'block') {
		$('label-input-block').setStyle('display', 'none');
		$('new-label').setStyle('visibility', 'hidden');
	}
	
	setTimeout('updateLabel()', 500);
	
}

function updateLabel(){
	
	var label = $('pro-label-input').value;
	if(label == '') label = ' ';
	flashInitialized(label);
}

// called by our action script after initialization
function flashInitialized(text)
{ 
  var isInternetExplorer = navigator.appName.indexOf("Microsoft") != -1;

  // get flash object
  flash = isInternetExplorer ? document.all.flash_txt : document.flash_txt;

  // call action script function
  flash.setText(text);
}
