﻿function SortAllHotelsPrice()
{
 if (!window.poi)
{ inverse=false;
		
		sortobject= jQuery('[class="price"]');
		sortobject.sortElements(function(a, b)
			{ 
				aball=a.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.className;
				bball=b.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.className;
				var a = a.innerHTML;
				var b = b.innerHTML;
				if (a=="ПОД ЗАПРОС")
					{a="999999999";}
				else {a=a.substring(3, a.length-1);}
				if (b=="ПОД ЗАПРОС")
					{b="999999999";}
				else {b=b.substring(3, b.length-1);}
				
				if (aball!=bball)
					return ( 
					isNaN (bball) || isNaN(aball) ? bball > aball : +bball > +aball ) ? inverse ? -1 : 1 :inverse ? 1 : -1;
				else
				return (  
				isNaN (a) || isNaN(b) ? a > b : +a > +b ) ? inverse ? -1 : 1 :inverse ? 1 : -1;},
				function(){return this.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode;
			});
	}
	else
	{
	{ inverse=false;
		
		sortobject= jQuery('[class="dist"]>span');
		sortobject.sortElements(function(a, b)
			{ 
				aball=a.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.className;
				bball=b.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.className;
				var as = a.innerHTML;
				var bs = b.innerHTML;
				if (a.className=="dkm") {as=1000*as;}
				if (a.className=="inf") {as=999999999;}
				if (b.className=="inf") {bs=999999999;}
				if (b.className=="dkm") {bs=1000*bs;}
				if (aball!=bball)
					return ( 
					isNaN (bball) || isNaN(aball) ? bball > aball : +bball > +aball ) ? inverse ? -1 : 1 :inverse ? 1 : -1;
				else
				return (  
				isNaN (as) || isNaN(bs) ? as > bs : +as > +bs ) ? inverse ? -1 : 1 :inverse ? 1 : -1;},
				function(){return this.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode;
			});
	}
	
	}
		pricePreview();
		pricePreview2();
	}

function SortAllHotelsBall()
{
		inverse=false;
		
		sortobject= jQuery('[class="hdlink1"]');
		sortobject.sortElements(function(a, b)
			{ 
				aball=a.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.className;
				bball=b.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.className;	
					return ( 
					isNaN (bball) || isNaN(aball) ? bball > aball : +bball > +aball ) ? inverse ? -1 : 1 :inverse ? 1 : -1;
				},
				function(){return this.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode;
			});

}



function SortAllHotelsPriceOLD()
{
		inverse=false;
		
		sortobject= jQuery('[class="price"]');
		sortobject.sortElements(function(a, b)
			{ 
				
				var a = a.innerHTML;
				var b = b.innerHTML;
				if (a=="ПОД ЗАПРОС")
					{a="999999999";}
				else {a=a.substring(3, a.length-1);}
				if (b=="ПОД ЗАПРОС")
					{b="999999999";}
				else {b=b.substring(3, b.length-1);}
				return ( 
				isNaN (a) || isNaN(b) ? a > b : +a > +b ) ? inverse ? -1 : 1 :inverse ? 1 : -1;},
				function(){return this.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode;
			});

}

function SortAllHotelsName()
{
		inverse=false;
		
		sortobject= jQuery('[class="price"]');
		sortobject.sortElements(function(a, b)
			{ 
				
				var a = a.innerHTML;
				var b = b.innerHTML;
				if (a=="ПОД ЗАПРОС")
					{a="999999999";}
				else {a=a.substring(3, a.length-1);}
				if (b=="ПОД ЗАПРОС")
					{b="999999999";}
				else {b=b.substring(3, b.length-1);}
				return ( 
				isNaN (a) || isNaN(b) ? a > b : +a > +b ) ? inverse ? -1 : 1 :inverse ? 1 : -1;},
				function(){return this.parentNode; 
			});

}
