
function ReloadPage(action)
{
	document.getElementById('myaction').value = action ;
	document.mForm.submit();	
}

function ShowPostForm()
{
	if(document.getElementById('addpost').style.display == 'none')
		document.getElementById('addpost').style.display = 'inline' ;
	else
		document.getElementById('addpost').style.display = 'none' ;
}


function addslashes(str) 
{
	str=str.replace(/\'/g,'\\\'');
	str=str.replace(/\"/g,'\\"');
	str=str.replace(/\\/g,'\\\\');
	str=str.replace(/\0/g,'\\0');
	return str;
}

function showMainPageIconContent(icon,action)
{
	if(action == 'show')
	{
		document.getElementById('toplabel').innerHTML = document.getElementById('text_'+icon).value ; 
		document.getElementById('text_main').style.display = 'none';
		document.getElementById(icon).style.display = '';		
		
	}
	else
	{				
		document.getElementById('savetime').style.display = 'none';
		document.getElementById('newideas').style.display = 'none';
		document.getElementById('addopinion').style.display = 'none';
		document.getElementById('forum').style.display = 'none';
		document.getElementById('productlist').style.display = 'none';
		
		document.getElementById('text_main').style.display = '';
		document.getElementById('toplabel').innerHTML = document.getElementById('text_default').value ; 
	}
	
}



function setPointer(theRow, RowNr, theAction)
{

    var theCells = null;

    var theDefaultClass = 'listTableRowLow';
    var thePointerClass = 'listTableRowHigh';
    var theMarkClass    = 'listTableRowMark';    

	switch(theAction)
	{
	  case "over" :
		  if(theRow.className != theMarkClass)
		    theRow.className = thePointerClass ;
	  break;
	  case "out" :
		  if(theRow.className != theMarkClass)
		    theRow.className = theDefaultClass ;
	  break;
	  case "click" :
		
		  if(theRow.className != theMarkClass)
		    theRow.className = theMarkClass ;
	      else theRow.className = thePointerClass ;
	  break;
	}
}



function ShiftComponent(kind)
{		

		img = document.getElementById("componentImage_"+kind);
		
		if(img.className != 'CSS_Image_'+kind)
			img.className = 'CSS_Image_'+kind ; 
		else
			img.className = 'CSS_Image_default' ;
		
		res = document.getElementsByTagName("span");

		for(r = 0 ; r < res.length ; r++)
		{
			if(res[r].id.substring(0,9) == 'component')	
			{
				if(res[r].title == kind)
				{
					if(res[r].className == 'CSS_'+kind)	
						res[r].className = '';
					else
						res[r].className = 'CSS_'+kind ; 	
						
					
						
				}					
			}
		}
}




function SendQuestion(prefix,validation)
{

	fieldInput 		= document.getElementsByTagName("input");
	fieldTextarea	= document.getElementsByTagName("textarea");
	
	var res = true ; 
	
	for ( property in validation ) 
	{	
		for(r = 0 ; r < fieldInput.length ; r++)
		{
		
			if(fieldInput[r].id == property)
			{				
				eval("result = "+validation[property]+"(fieldInput["+r+"]);");

				if(result == false)
				{									
					fieldInput[r].style.border = '1px solid #ff0000';	
					res = false ; 
				}
				else
				{
					fieldInput[r].style.border = '1px solid #000000';	
				}
			} 			
		}

		for(r = 0 ; r < fieldTextarea.length ; r++)
		{
			if(fieldTextarea[r].id == property)
			{
				eval("result = "+validation[property]+"(fieldTextarea["+r+"]);");
				
				if(result == false)
				{
					fieldTextarea[r].style.border = '1px solid #ff0000';	
					res = false ; 
				}
				else
				{
					fieldTextarea[r].style.border = '1px solid #000000';	
				}
			} 			
		}
		
	}		
	
	
	if(res == true){
		document.mForm.action = 'pytanie_wyslane.html' ;
		document.mForm.submit();		
	}
}

function checkForm(validation)
{
	fieldInput 		= document.getElementsByTagName("input");
	fieldTextarea	= document.getElementsByTagName("textarea");
			
	var res = true ; 
			for ( property in validation ) 
			{	
				for(r = 0 ; r < fieldInput.length ; r++)
				{
					if(fieldInput[r].id == property)
					{
						eval("result = "+validation[property]+"(fieldInput["+r+"]);");
						
						if(result == false)
						{
							if( property == 'condition')
								document.getElementById('condition_field').style.border = '1px solid #ff0000';  
							else						
								fieldInput[r].style.border = '1px solid #ff0000';	
							
							res = false ; 
						}
						else
						{
							if( property == 'condition')			
								document.getElementById('condition_field').style.border = '1px solid #ffffff';  
							else					
								fieldInput[r].style.border = '1px solid #000000';	
						}
					} 			
				}
				
				
				for(r = 0 ; r < fieldTextarea.length ; r++)
				{
					if(fieldTextarea[r].id == property)
					{
						eval("result = "+validation[property]+"(fieldTextarea["+r+"]);");
						
						if(result == false)
						{
							fieldTextarea[r].style.border = '1px solid #ff0000';	
							res = false ; 
						}
						else
						{
							fieldTextarea[r].style.border = '1px solid #000000';	
						}
					} 			
				}	
			}	
			
		return res ; 
}

function SendDish(prefix,validation)
{

	fieldInput 		= document.getElementsByTagName("input");
	fieldTextarea	= document.getElementsByTagName("textarea");
	
	var res = true ; 
	
	for ( property in validation ) 
	{	
		for(r = 0 ; r < fieldInput.length ; r++)
		{
		
			if(fieldInput[r].id == property)
			{
				eval("result = "+validation[property]+"(fieldInput["+r+"]);");
				
				if(result == false)
				{
					if( property == 'condition')
						document.getElementById('condition_field').style.border = '1px solid #ff0000';  
					else						
						fieldInput[r].style.border = '1px solid #ff0000';	
					
					res = false ; 
				}
				else
				{
					if( property == 'condition')			
						document.getElementById('condition_field').style.border = '1px solid #ffffff';  
					else					
						fieldInput[r].style.border = '1px solid #000000';	
				}
			} 			
		}

		for(r = 0 ; r < fieldTextarea.length ; r++)
		{
			if(fieldTextarea[r].id == property)
			{
				eval("result = "+validation[property]+"(fieldTextarea["+r+"]);");
				
				if(result == false)
				{
					fieldTextarea[r].style.border = '1px solid #ff0000';	
					res = false ; 
				}
				else
				{
					fieldTextarea[r].style.border = '1px solid #000000';	
				}
			} 			
		}
		
	}		
	
	
	if(res == true){
		document.mForm.action = 'przepis_dodany.html' ;
		document.mForm.submit();		
	}
}


function IsChecked(obj)
{
	if(obj.checked == true)
		return true ;
		
	return false ;  
}


function NotEmpty(obj)
{
	if(obj.value != '')
		return true ; 
	
	return false ; 	
}



function IsEmail(obj) {

		str = obj.value

		var at="@" ; 
		var dot="." ; 
		var lat=str.indexOf(at) ; 
		var lstr=str.length ; 
		var ldot=str.indexOf(dot) ; 
		
		if ((str==null)||(str=="")){
		   return false
		}
			
		
		if (str.indexOf(at)==-1){		   
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){		   
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){		    
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){		   
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){		    
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){		    
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){		    
		    return false
		 }
		 
		 

 		 return true					
	}










function submitForm(file,page)
{
 document.getElementById('calledpage').value = page ;
 document.mForm.action=file;
 document.mForm.submit();
}



function ChangeLanguage(lang)
{
       var actualLink  = '' ;
       var tmpLink = document.location ;
	   var regex = /.language=../g;
	
       tmpLink = tmpLink.toString();

       var tmp = tmpLink.substring(1*tmpLink.length-1,tmpLink.length);

       if(tmp == '#')
       {
               actualLink = tmpLink.substring(0,1*tmpLink.length-1);
       }
       else
       {
               actualLink = tmpLink ;
       }

       if( actualLink.indexOf('?') == -1 )
               actualLink = actualLink+'?' ;

       actualLink = actualLink.replace(regex, '')
	   actualLink = actualLink+'&language='+ lang;

       document.location = actualLink ;
}

function ShowXml()
{
	var actualLink  = '' ; 
	var tmpLink = document.location ;
	tmpLink = tmpLink.toString();

	var tmp = tmpLink.substring(1*tmpLink.length-1,tmpLink.length);
	
	if(tmp == '#')
	{
		actualLink = tmpLink.substring(0,1*tmpLink.length-1);
	}
	else
	{
		actualLink = tmpLink ;
	}
	
	if( actualLink.indexOf('?') == -1 )
		actualLink = actualLink+'?' ; 
		
	actualLink = actualLink+'&showxml=1' ; 

	document.location = actualLink ; 
}

function openElementEditWindow()
{
	if(document.getElementById('componentListDiv').style.display == 'inline') 
	{
		document.getElementById('componentListDiv').style.display = 'none' ; 
	}
	else
	{
		document.getElementById('componentListDiv').style.display = 'inline' ;
	}
	
	var iFrameId = parent.document.getElementById('componentListIframe') ; 
	iFrameId.height = 1*document.getElementById('componentListTable').offsetHeight + 10 ; 
}






































function Login()
{
	document.getElementById('login_check').value = 'yes' ; 
	//document.mForm.action = '?page=login';
	document.mForm.submit();	
}

function LoginPartner()
{
	document.getElementById('login_partner_check').value = 'yes' ; 
	document.mForm.submit();	
}

function changeMainPicture(r)
{
	document.getElementById('mainPicture').src = r.src ; 
}

function CheckOrder()
{
	document.getElementById('new_user_check').value = 'yes' ;
	document.mForm.submit();
}

function CheckRegistration()
{
	document.getElementById('new_user_check').value = 'yes' ;
	document.mForm.submit();
}

function Search(action)
{
	document.mForm.action = action;
	document.mForm.submit();	
}


function NextResult(next,sorting,category)
{	
	//document.getElementById('currentPage').value = next ;	
	document.mForm.action = '?page=search&currentPage='+next+'&sorting='+sorting+'&category='+category ;
	document.mForm.submit();
}

function PreviousResult(previous,sorting,category)
{
	//document.getElementById('currentPage').value = previous ;	
	document.mForm.action = '?page=search&currentPage='+previous+'&sorting='+sorting+'&category='+category ;
	document.mForm.submit();
}

function ShowDescription(id)
{
	document.mForm.action="index.php?page=description&productId="+id;
	document.mForm.submit();
}

function ReloadCart(action)
{
	document.mForm.action = action;
	document.mForm.submit();
}

function SearchByCategory(category)
{	

	//document.getElementById('filter_category').value = category ;
	document.mForm.action = 'index.php?page=search&category='+category;
	document.mForm.submit();	
}

function SearchProducts(searchingBy)
{
	document.getElementById('searchingBy').value = searchingBy;
	document.mForm.action="index.php?page=search";
	document.mForm.submit();
}



function setMenuPointer(theRow, RowNr, theAction)
{
    var theDefaultClass = 'MenuList';
    var thePointerClass = 'MenuListHigh';
    var theMarkClass    = 'MenuListMark';    

	switch(theAction)
	{
	  case "over" :
		  if(theRow.className != theMarkClass)
		    theRow.className = thePointerClass ;
	  break;
	  case "out" :
		  if(theRow.className != theMarkClass)
		    theRow.className = theDefaultClass ;
	  break;
	  case "click" :
		
		  if(theRow.className != theMarkClass)
		    theRow.className = theMarkClass ;
	      else theRow.className = thePointerClass ;
	  break;
	}
}


function setPointer(theRow, RowNr, theAction)
{

    var theCells = null;

    var theDefaultClass = 'listTableRowLow';
    var thePointerClass = 'listTableRowHigh';
    var theMarkClass    = 'listTableRowMark';    

	switch(theAction)
	{
	  case "over" :
		  if(theRow.className != theMarkClass)
		    theRow.className = thePointerClass ;
	  break;
	  case "out" :
		  if(theRow.className != theMarkClass)
		    theRow.className = theDefaultClass ;
	  break;
	  case "click" :
		
		  if(theRow.className != theMarkClass)
		    theRow.className = theMarkClass ;
	      else theRow.className = thePointerClass ;
	  break;
	}
}



function SelectAllCheckBox(name)
{
	for (i=0;i< document.mForm.elements.length;i++) 
	{
		if(document.mForm.elements[i].type=='checkbox' && document.mForm.elements[i].name.substring(0,name.length) == name)
		{
			document.mForm.elements[i].checked = true;
		}
		
	}  
}



function ShowImage(id)
{
	var imagePointer = 'image['+id+']' ; 
	var imageName = document.getElementById(imagePointer).value ; 
	//alert(imageName)
	ChangeImage(imageName) ; 
}
 
	
function ChangeImage(name)
{
	var tab				= GetPositionTable();
	var currently = GetCurrentlyPosition(name);
	var tableName = 'imagetable['+currently+']' ; 
	
	var tmpTableName ; 

	for( var t = 0 ; t < tab.length ; t ++ )
	{
		tmpTableName = 'imagetable['+t+']' ; 
		//document.getElementById(tmpTableName).border = 0 ;
	}

	//document.getElementById(tableName).border = 1 ;
	document.getElementById('mainimage').src = name ;
}

function GetPositionTable()
{	
	var tab = new Array(100) ; 
	var k = 0 ; 

	for(var t = 0 ; t < document.mForm.elements.length ; t++)
	{
		if(document.mForm.elements[t].name.substring(0,5) == 'image')
		{
			tab[k] = document.mForm.elements[t].value ; 
			k ++ ;
		}
	}

	var newTab = new Array(k);

	for( var t = 0 ; t < k ; t++ )
	{
		newTab[t] = tab[t] ; 
	}

	return newTab ; 
}



function GetCurrentlyPosition(name)
{
	var tab = GetPositionTable() ; 

	for(var t = 0 ; t < tab.length ; t++)
	{
		if(tab[t] == name)
		{
			return t ; 
		}
	}
}



function ShowNext()
{
	var tab = GetPositionTable() ; 
	var name = document.getElementById('mainimage').src ; 

	var currently = GetCurrentlyPosition(name) ; 

	if( currently+1 <= tab.length -1 )
		ChangeImage(tab[currently+1]) ; 		
	else 
		ChangeImage(tab[0]) ; 
}



function ShowPrevious()
{
	var tab = GetPositionTable() ; 
	var name = document.getElementById('mainimage').src ; 
	var currently = GetCurrentlyPosition(name) ; 

	if( currently-1 >= 0 )
		ChangeImage(tab[currently-1]) ;
	else 
		ChangeImage(tab[tab.length-1]) ;
}



function ShowFirstImage()
{
	var imageTable =  GetPositionTable();
	ChangeImage(imageTable[0]) ;
}



function ShowLastImage()
{
	var imageTable =  GetPositionTable();
	ChangeImage(imageTable[imageTable.length-1]) ;
}



function CallSlideShow()
{
	if(document.getElementById('slideFlag').value == 0)
	{
		document.getElementById('slideFlag').value = 1 ;
		SlideShow() ;
	}
	else
	{
		document.getElementById('slideFlag').value = 0 ;
	}
}


function UnselectAllCheckBox(name)
{
	for (i=0;i< document.mForm.elements.length;i++) 
	{
		if(document.mForm.elements[i].type=='checkbox' && document.mForm.elements[i].name.substring(0,name.length) == name)
		{
			document.mForm.elements[i].checked = false;
		}
		
	}  
}

function ReverseCheckBox(name)
{
	for (i=0;i< document.mForm.elements.length;i++) 
	{
		if(document.mForm.elements[i].type=='checkbox' && document.mForm.elements[i].name.substring(0,name.length) == name)
		{
			if(document.mForm.elements[i].checked)
				document.mForm.elements[i].checked = false;
			else 
				document.mForm.elements[i].checked = true ; 
		}
		
	}  
}


function SlideShow() 
{
	if(document.getElementById('slideFlag').value == 0)
		return ;

	var delay = 1; 
	
	ShowNext();
	
	setTimeout("SlideShow()",delay*2000);
}



function ChangeTotalPrice()
{
	var totalPriceField = document.getElementById('totalPriceField').value ;

	var deliveryType = document.getElementById('order_deliverytype') ; 
	var deliveryId = deliveryType[deliveryType.selectedIndex].value ; 
	
	var tmpPrice = "deliveryPrices_"+deliveryId ; 
	var tmpName = "deliveryName_"+deliveryId ; 
	
	var deliveryPriceField = document.getElementById(tmpPrice).value ; 
	var deliveryNameField = document.getElementById(tmpName).value ; 
		 
	document.getElementById('deliveryTypeField').innerHTML = deliveryNameField ; 
	document.getElementById('deliveryPriceField').innerHTML = deliveryPriceField ;  
	
	document.getElementById('allPriceField').innerHTML = 1*totalPriceField + 1*deliveryPriceField ; 
}

function OpenAdditionalWindow(id)
{
	if(document.getElementById(id).style.display == 'none')
		document.getElementById(id).style.display = 'inline';		
	else 
		document.getElementById(id).style.display = 'none';		
}



function OpinionWindow(Id)
{
	window.open('controlers/addopinion.inc.php?id='+Id, 'opinion', 'menubar=no,toolbar=no,location=no,directories=no,status=no,scrollbars=yes,resizable=no,fullscreen=no,channelmode=no,width=450,height=300');	
}


function PrintWindow(Id)
{
	window.open('/controlers/printdish.inc.php?id='+Id, 'printdish', 'menubar=no,toolbar=no,location=no,directories=no,status=no,scrollbars=yes,resizable=no,fullscreen=no,channelmode=no,width=600,height=650');	
}


function PrintProductList()
{
	window.open('/controlers/printproductlist.inc.php', 'printproductlist', 'menubar=no,toolbar=no,location=no,directories=no,status=no,scrollbars=yes,resizable=no,fullscreen=no,channelmode=no,width=600,height=650');	
}



function tree(id)
{

  this.id = id;

  this.click = function ()
  {
    for (var i = 0, el_node; i < this.parentNode.childNodes.length; i++)
    {
      el_node = this.parentNode.childNodes.item(i)
      if (el_node.nodeName.toLowerCase() == 'ul')
      {
        el_node.style.display = el_node.style.display == 'none' ? 'block' : 'none';
        this.parentNode.style.backgroundImage = 'url("' + (el_node.style.display == 'none' ? 'closed' : 'opened') + '.gif")';
        return;
      }
    }
  }

  this.start = function (el)
  {
    for (var i = 0, el_node; i < el.childNodes.length; i++)
    {
      el_node = el.childNodes.item(i);
      if (el_node.nodeName.toLowerCase() == 'a')
      {
        el_node.onclick = this.click;
        for (var j = 0; j < el_node.parentNode.childNodes.length; j++)
        {
          if (el_node.parentNode.childNodes.item(j).nodeName.toLowerCase() == 'ul')
          {
            el_node.parentNode.style.backgroundImage = 'url("closed.gif")';
            el_node.className = (el_node.className ? el_node.className + ' ' : '') + 'folder';
            break;
          }
          if (el_node.parentNode.childNodes.item(j).nodeName.toLowerCase() == 'li') break;
        }
        if (el_node.href && unescape(el_node.href) == unescape(window.location.href))
        {
          el_node.className = 'active';
          var el_parentNode = el_node;
          do
          {
            el_parentNode = el_parentNode.parentNode;
            if (el_parentNode.nodeName.toLowerCase() == 'ul')
            {
              el_parentNode.style.display = 'block';
              if (document.getElementById(this.id) != el_parentNode) el_parentNode.parentNode.style.backgroundImage = 'url("opened.gif")';
            }
          }
          while (document.getElementById(this.id) != el_parentNode)
        }
      }
      else if (el_node.nodeName.toLowerCase() == 'ul') el_node.style.display = 'none';
      this.start(el_node);
    }
  }

  if (document.getElementById && document.childNodes)
  {
    if (document.images)
    {
      new Image().src = 'opened.gif';
      new Image().src = 'document.gif';
    }
    this.start(document.getElementById(this.id));
  }
}













