
//	Common Constants

var

	//	Row States

	rs_Original				= 0,
	rs_Modified				= 1,
	rs_Deleted				= 2,
	rs_Added				= 3,

    i_rowState				= 0,


    monthNames 				= new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"),
    monthNamesEng 			= new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"),
    weekdayNames			= new Array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"),
    reservedContentPages	= new Array("index", "images", "cc", "common", "movies", "profile"),

	
	//	Form Saver Variables

	frmSaver_innerHTML,
	frmSaver_form,
	arOutput,
    

    //	Zone Correct in Seconds Beetween Client's and Server's Time
    //	Client_Time - iTimeZoneCorrect == Server's Time

    iTimeZoneCorrect = 0 + (new Date()).getTimezoneOffset() * 60,


    HTTP_HOST = "www.holidayapartmentsandvillas.com";

	



	///
	///	Form Saver Functions
	///

	
	//	Begin output



	
	function frmSaver_clear(saverForm) 
	{
		if (typeof(saverForm) != "undefined")
		{
			frmSaver_form = saverForm;
		} else {
			frmSaver_form = document.getElementById("frmSaver");
		}

		bFoundSaver = false;

		for (i = 0; i < frmSaver_form.childNodes.length; i++)
		{
			if (
				frmSaver_form.childNodes[i].nodeType == document.ELEMENT_NODE
				&&
				frmSaver_form.childNodes[i].getAttribute('id') == 'divSaverDetails'
			) {
				frmSaver_form.childNodes[i].innerHTML = "";
				bFoundSaver = true;
				break;
			}
		}

		if (!bFoundSaver) {
			frmSaver_form.innerHTML = "";
		}

		arOutput = new Array();
	}


	//	Add variable to output
	
	function frmSaver_add(sName, sValue) {
		arOutput[arOutput.length] = new Array(sName, sValue);
	}


	//	Submit output form
	
	function frmSaver_submit(avoidSubmit) {
		var
			sOutput = "";

		for (i = 0; i < arOutput.length; i++) {
			sOutput += '<input type=hidden id="frmInput_' + arOutput[i][0] + '" name="' + arOutput[i][0] + '" value="">';
		}

		bFoundSaver = false;
		for (i = 0; i < frmSaver_form.childNodes.length; i++)
		{
			if (
				frmSaver_form.childNodes[i].nodeType == document.ELEMENT_NODE
				&&
				frmSaver_form.childNodes[i].getAttribute('id') == 'divSaverDetails'
			) {
				frmSaver_form.childNodes[i].innerHTML = sOutput;
				bFoundSaver = true;
				break;
			}
		}

		if (!bFoundSaver) {
			frmSaver_form.innerHTML = sOutput;
		}

		for (i = 0; i < arOutput.length; i++) {
			document.getElementById('frmInput_' + arOutput[i][0]).value = arOutput[i][1];
		}

		if (!avoidSubmit) {
			frmSaver_form.submit();
		}
	}
	
	
	//	Submit output form ONE VARIABLE
	
	function frmSaver_submit_onevariable(avoidSubmit) {
		var
			sOutput = '<input type=hidden id="all_variables_at_one_variable" name="all_variables_at_one_variable" value="">';
		
		bFoundSaver = false;
		for (i = 0; i < frmSaver_form.childNodes.length; i++)
		{
			if (
				frmSaver_form.childNodes[i].nodeType == document.ELEMENT_NODE
				&&
				frmSaver_form.childNodes[i].getAttribute('id') == 'divSaverDetails'
			) {
				frmSaver_form.childNodes[i].innerHTML = sOutput;
				bFoundSaver = true;
				break;
			}
		}

		if (!bFoundSaver) {
			frmSaver_form.innerHTML = sOutput;
		}

		document.getElementById("all_variables_at_one_variable").value = arOutput.join("&;#@#;&&;#@#;&");
		
		if (!avoidSubmit) {
			frmSaver_form.submit();
		}
	}


	//	Add HTML Fields to output (OLD ONE)

	function htmlAddField(sName, sValue) {
		sOutput += '<input type=hidden name="' + escape(sName) + '" value="' +  escape(sValue) + '">';
	}
	
	
	
	//	Parse Column of Array

	function parseIntArray(arSource, i_column) {
		for (i = 0; i < arSource.length; i++) {
			arSource[i][i_column] = parseInt(arSource[i][i_column]);
		}
	}
	
	
	
	//
	//	New Array's method for sortArray function
	//
	
	Array.prototype.quicksort = function(iColumn, bString, bDesceding) {
		
		if (this.length < 2) {
			return false;
		}
		
		function compareFunction(a1, a2) {
			var
				a1Item = a1[iColumn],
				a2Item = a2[iColumn],
				a1Parsed, a2Parsed;
			
			if (bString) {
				
				a1Item += '';
				a2Item += '';

				a1Item = a1Item.toUpperCase();
				a2Item = a2Item.toUpperCase();
				
			} else {
				try {
					
					a1Parsed = parseInt(a1Item);
					a2Parsed = parseInt(a2Item);
					
				} catch (e) {
					
					a1Parsed = a1Item;
					a2Parsed = a2Item;
					
				}
				
				a1Item = a1Parsed;
				a2Item = a2Parsed;
			}
			
			if (a1Item == a2Item) {
				return 0;
			}
			
			if (a1Item > a2Item) {
				return (bDesceding ? -1 : 1);
			}
			
			if (a1Item < a2Item) {
				return (bDesceding ? 1 : -1);
			}
		}
		
		
		var
			i = 0, j = 0, k = 0,
			iIndex = -1,
			iIndex1 = -1,
			iIndex2 = -1,
			iIndex1prev = -1,
			iIndex2next = -1,
			iWrongPlaceElements = 0,
			arTemp = new Array();
		
		
		for (i = 1; i < this.length; i++) {
			if (compareFunction(this[i - 1], this[i]) == 1) {

				iIndex1 = i - 1;
				iIndex2 = i;
				
				iIndex1prev = ((iIndex1) - 1 >= 0 ? (iIndex1 - 1) : iIndex2);
				iIndex2next = ((iIndex2) + 1 < this.length ? (iIndex2 + 1) : iIndex1);
				
				iWrongPlaceElements++;
				
				if (iWrongPlaceElements > 1) {
					break;
				}
			}
		}
		
		if (
			(iWrongPlaceElements == 1)
			&&
			(compareFunction(this[iIndex1], this[iIndex2next]) == 1)
			&&
			(compareFunction(this[iIndex1prev], this[iIndex2]) == 1)
		) {
			iWrongPlaceElements = 2;
		}
		
		if (iWrongPlaceElements == 0) {
			return true;
		}
		
		if (iWrongPlaceElements == 1) {
			
			if (compareFunction(this[iIndex1], this[iIndex2next]) == 1) {
				
				//
				//	iIndex1 to end
				//
				
				arTemp = this[iIndex1];
				for (i = iIndex2; i < this.length; i++) {
					if (compareFunction(arTemp, this[i]) == 1) {
						this[i - 1] = this[i];
					} else {
						break;
					}
					iIndex = i;
				}
				
				this[iIndex] = arTemp;
				
			} else {
				if (compareFunction(this[iIndex1prev], this[iIndex2]) == 1) {
					
					//
					//	iIndex2 to begin
					//
					
					arTemp = this[iIndex2];
					for (i = iIndex1; i >= 0; i--) {
						if (compareFunction(this[i], arTemp) == 1) {
							this[i + 1] = this[i];
						} else {
							break;
						}
						iIndex = i;
					}
					
					this[iIndex] = arTemp;
					
				} else {
					
					//
					//	iIndex1 iIndex2 elements replace
					//
					
					arTemp = this[iIndex1];
					this[iIndex1] = this[iIndex2];
					this[iIndex2] = arTemp;
					
				}
				
			}
			return true;
		}
		
		this.sort(compareFunction);
		return true;
	}
	
	
	//	Sort Array by Selected Column (NEW Realization)
	
	function sortArray(arSource, iColumn, bString, bDesceding) {
		
		bString = (bString || false);
		bDesceding = (bDesceding || false);

		var
			bReturn = true;
			bArrayPoor = (typeof(arSource.quicksort) != "function"),
			arTmp = new Array(),
			i = 0, j = 0;
	
		if (bArrayPoor) {
			for (i = 0; i < arSource.length; i++) {
				arTmp[i] = new Array();
				for (j = 0; j < arSource[i].length; j++) {
					arTmp[i][j] = arSource[i][j];
				}
			}
		}
		
		if (bArrayPoor) {
			bReturn = arTmp.quicksort(iColumn, bString, bDesceding);
		} else {
			bReturn = arSource.quicksort(iColumn, bString, bDesceding);
		}
		
		if (bArrayPoor) {
			for (i = 0; i < arTmp.length; i++) {
				arSource[i] = new Array();
				for (j = 0; j < arTmp[i].length; j++) {
					arSource[i][j] = arTmp[i][j];
				}
			}
		}
		
		return bReturn;
		
	}
	
	
	
	/*
	//	Sort Array by Selected Column
	//	OLD REALIZATION
	function sortArray(arSource, i_column, bString, bDesceding) {
		var
			sortColumn = i_column,
			bStringType = bString,
			bDescedingSort = bDesceding;
		
			function itemComare(a1, a2) {
        		var
        			a1Item = a1[sortColumn],
                    a2Item = a2[sortColumn],
                    a1Parsed, a2Parsed;

        		if (bStringType) {
        			a1Item = a1Item.toUpperCase();
        			a2Item = a2Item.toUpperCase();

        		} else {
					try {
						a1Parsed = parseInt(a1Item);
						a2Parsed = parseInt(a2Item);

					} catch (e) {
						a1Parsed = a1Item;
						a2Parsed = a2Item;
					}

					a1Item = a1Parsed;
					a2Item = a2Parsed;
				}
        		
        		if (a1Item == a2Item) {
        			return 0;
        		}

        		if (a1Item > a2Item) {
        			return bDescedingSort ? -1 : 1;
        		}

        		if (a1Item < a2Item) {
        			return bDescedingSort ? 1 : -1;
        		}
			}
		
		var
			i = j = 0,
			aTmp = new Array();
			
		if (typeof(arSource.sort) != "function") {
			for (i = 0; i < arSource.length; i++) {
				aTmp[i] = new Array();
				for (j = 0; j < arSource[i].length; j++) {
					aTmp[i][j] = arSource[i][j];
				}
			}
			arSource = aTmp;
		}
			
		
		arSource.sort(itemComare);
	}
	*/
	

	//	Find Array Key Value

	function findArrayKeyValue(arSource, keyValue, i_keyColumn, i_valueColumn) {
		var i;

		for (i = 0; i < arSource.length; i++) {
			if (arSource[i][i_keyColumn] == keyValue) {
				if (i_valueColumn != -1) {
					return arSource[i][i_valueColumn];
				} else {
					return i;
				}
			}
		}

		if (i_valueColumn != -1) {
			return false;
		} else {
			return -1;
		}
	}	


	//	Swap values of variables
	
	function swapValues(iOldValue, iNewValue) {
		iTempValue = iOldValue;
		iOldValue = iNewValue;
		iNewValue = iTempValue;
	}


	///	<summary>						Convert Date from Unix to Date format</summary>
	///
	///	<param name="sDate">			Date in MySQL format 'yyyy-mm-dd hh:mm:ss'</param> 
	///
	///	<returns>						JScript Date object</returns>
	
	function dateFromUnix(sDate) {
		if (sDate.length > 10) {
			return new Date (sDate.substr(0, 4), 1 * sDate.substr(5, 2) - 1, sDate.substr(8, 2),
				sDate.substr(11, 2), sDate.substr(14, 2), sDate.substr(17, 2));
		} else {
			return new Date (sDate.substr(0, 4), 1 * sDate.substr(5, 2) - 1, sDate.substr(8, 2));
		}
	}


	//	Convert Date from Unix to String format
	
	function dateFromUnixFormated(sDate) {
		var
			tempDate = new Date (sDate.substr(0, 4), 1 * sDate.substr(5, 2) - 1, sDate.substr(8, 2));

//		US version
//		return monthNames[tempDate.getMonth()].substr(0, 3) + " " + tempDate.getDate() + ", " + tempDate.getFullYear();

//		UK version
		return tempDate.getDate() + " " + monthNames[tempDate.getMonth()] + " " + tempDate.getFullYear();
	}

	//	Convert Date from Unix to Short String format
	
	function dateFromUnixFormatedShort(sDate) {
		return sDate.substr(8, 2) + "/" + sDate.substr(5, 2) + "/" + sDate.substr(2, 2);
	}

	//	Create MySQL Formatted Date
	
	function createMySQLDate(iMonth, iDay, iYear) {
		var
			sMonth, sDay, sYear;
		
		sMonth = '' + iMonth;

		if (sMonth.length < 2) {
			sMonth = '0' + sMonth;
		}

		sDay = '' + iDay;

		if (sDay.length < 2) {
			sDay = '0' + sDay;
		}

		return iYear + '-' + sMonth + '-' + sDay;
	}


	//	Create MySQL Formatted Date from Date object
	
	function createMySQLDateFromDate(dDate) {
		var
			sMonth, sDay, sYear;
		
		sMonth = '' + (dDate.getMonth() + 1);

		if (sMonth.length < 2) {
			sMonth = '0' + sMonth;
		}

		sDay = '' + dDate.getDate();

		if (sDay.length < 2) {
			sDay = '0' + sDay;
		}

		return dDate.getFullYear() + '-' + sMonth + '-' + sDay;
	}




	
	//
	//	ListBox Specific Functions
	//
	

	///	<summary>						Add Item to ListBox</summary>
	///
	///	<param name="listboxObject">	Listbox Object to process</param> 
	///	<param name="itemName">			Title of new item</param> 
	///	<param name="itemValue">		Value of new item</param> 
	///	<param name="itemColor">		Color of new item. Optional</param> 
	///	<param name="itemBackground">	Background color of new item. Optional</param> 
	///	<param name="topPosition">		If true then new item added at the top of list. Optional. Default: false</param> 
	///
	///	<returns>						Added listbox item</returns>

	function listbox_Add(listboxObject, itemName, itemValue, itemColor, itemBackground, topPosition) {
		var
			listOption = document.createElement("OPTION");

		if ((topPosition != null) && topPosition) {
			listboxObject.options.add(listOption, 0);
		} else {
			listboxObject.options.add(listOption);
		}

		itemName += '';
		listOption.text = itemName.replace(/\s/g, '\xa0');
		listOption.value = itemValue;

		if (itemColor != null) {
			listOption.style.color = itemColor;
		}

		if (itemBackground != null) {
			listOption.style.backgroundColor = itemBackground;
		}

		return listOption;
	}


	///	<summary>						Update Item</summary>
	///
	///	<param name="listboxObject">	Listbox Object to process</param> 
	///	<param name="itemIndex">		Index of item to update</param> 
	///	<param name="itemName">			Title of the item</param> 
	///	<param name="itemValue">		Value of the item</param> 
	///	<param name="itemColor">		Color of the item. Optional</param> 
	///	<param name="itemBackground">	Background color of the item. Optional</param> 
	///
	///	<returns>						Added listbox item</returns>

	function listbox_Update(listboxObject, itemIndex, itemName, itemValue, itemColor, itemBackground) {
		var
			listOption = listboxObject.options[itemIndex],
			itemSelected = listboxObject.options[itemIndex].selected;

		
		listOption.text = itemName;

		if (itemValue != null) {
			listOption.value = itemValue;
		}

		if (itemColor != null) {
			listOption.style.color = itemColor;
		}

		if (itemBackground != null) {
			listOption.style.backgroundColor = itemBackground;
		}

		listboxObject.options[itemIndex].selected = itemSelected;

		return listOption;
	}


	///	<summary>						Remove all items from ListBox</summary>
	///
	///	<param name="listboxObject">	Listbox Object to process</param> 

	function listbox_Empty(listboxObject) {
		while(listboxObject.length) {
			listboxObject.remove(0);
		}
	}
	

	///	<summary>						Load Items from Data Array</summary>
	///
	///	<param name="listboxObject">	Listbox Object to process</param> 
	///	<param name="dataArray">		Source Data Array of items</param> 
	///	<param name="titleColumn">		Column with Title</param> 
	///	<param name="visibleColumn">	Column with Visible attribute. Optional</param> 

	function listbox_Load(listboxObject, dataArray, titleColumn, visibleColumn) {
		listbox_Empty(listboxObject);

		for (var i = 0; i < dataArray.length; i++) {
			if (dataArray[i][i_rowState] != rs_Deleted) {
				listbox_Add(listboxObject, dataArray[i][titleColumn], i,
					(visibleColumn != null) && (dataArray[i][visibleColumn] == 0) ? "gray" : null);
			}
		}
	}
	

	//	Move Listbox Item

	function moveListboxItem(itemList, iIndex, iDirection, arSource, i_orderColumn) {
		var
			arFirst	= arSource[itemList.options[iIndex].value],
			arNext	= arSource[itemList.options[iIndex + iDirection].value],
			oOrder, oOption_text, oOption_value, oOption_selected,
			oOption_style_color, oOption_style_backgroundColor;
		
		oOrder = arNext[i_orderColumn];
		arNext[i_orderColumn] = arFirst[i_orderColumn];
		arFirst[i_orderColumn] = oOrder;

		if (arFirst[i_rowState] == rs_Original) {
			arFirst[i_rowState] = rs_Modified;
		}
		
		if (arNext[i_rowState] == rs_Original) {
			arNext[i_rowState] = rs_Modified;
		}
		
		oOption_text = itemList.options[iIndex + iDirection].text;
		oOption_value = itemList.options[iIndex + iDirection].value;
		oOption_selected = itemList.options[iIndex + iDirection].selected;
		oOption_style_color = itemList.options[iIndex + iDirection].style.color;
		oOption_style_backgroundColor = itemList.options[iIndex + iDirection].style.backgroundColor;

		itemList.options[iIndex + iDirection].text = itemList.options[iIndex].text;
		itemList.options[iIndex + iDirection].value = itemList.options[iIndex].value;
		itemList.options[iIndex + iDirection].selected = itemList.options[iIndex].selected;

		itemList.options[iIndex + iDirection].style.color = itemList.options[iIndex].style.color;
		itemList.options[iIndex + iDirection].style.backgroundColor = itemList.options[iIndex].style.backgroundColor;
		

		itemList.options[iIndex].text = oOption_text;
		itemList.options[iIndex].value = oOption_value;
		itemList.options[iIndex].selected = oOption_selected;
		itemList.options[iIndex].style.color = oOption_style_color;
		itemList.options[iIndex].style.backgroundColor = oOption_style_backgroundColor;
		
	}




	///	<summary>						Load JScript Date in List Boxes</summary>
	///
	///	<param name="ctrMonth">			Listbox with month value</param> 
	///	<param name="ctrDay">			Listbox with day value</param> 
	///	<param name="ctrYear">			Listbox with year value</param> 
	///	<param name="normalDate">		Date in JScript format</param> 

	
	function listboxes_LoadDate(ctrMonth, ctrDay, ctrYear, normalDate) {
		dateDay = normalDate.getDate();
		dateMonth = normalDate.getMonth() + 1;
		dateYear = normalDate.getFullYear();
		
		ctrDay.selectedIndex = dateDay - ctrDay.options[0].value;
		ctrMonth.selectedIndex = dateMonth - ctrMonth.options[0].value;
		ctrYear.selectedIndex = dateYear - ctrYear.options[0].value;
	}


	// Load Date (JScript) in List Boxes
	
	function listboxes_LoadMySQLDate(ctrMonth, ctrDay, ctrYear, newDate) {
		normalDate = dateFromUnix(newDate);

		dateDay = normalDate.getDate();
		dateMonth = normalDate.getMonth() + 1;
		dateYear = normalDate.getFullYear();
		
		ctrDay.selectedIndex = dateDay - ctrDay.options[0].value;
		ctrMonth.selectedIndex = dateMonth - ctrMonth.options[0].value;
		ctrYear.selectedIndex = dateYear - ctrYear.options[0].value;
	}

	
	///	<summary>						Correct Date in List Boxes</summary>
	///
	///	<param name="ctrMonth">			Listbox with month value</param> 
	///	<param name="ctrDay">			Listbox with day value</param> 
	///	<param name="ctrYear">			Listbox with year value</param> 
	///
	///	<returns>						Correct date in JScript format</returns>
	
	function listboxes_CorrectDate(ctrMonth, ctrDay, ctrYear) {
		var	
			correctDate = new Date(ctrYear.value, ctrMonth.value - 1, ctrDay.value);
		
		listboxes_LoadDate(ctrMonth, ctrDay, ctrYear, correctDate);

		return correctDate;
	}


	///	<summary>						Convert string to correct file name</summary>
	///
	///	<param name="fileName">			Proposed file name</param> 
	///
	///	<returns>						Correct file name</returns>

	function stringToFileName(fileName) {
		var
			languageUPCharSet = new Array(),
			languageLOCharSet = new Array(),
			languageOutCharSet = new Array(),
			newFileName = fileName.toLowerCase();
	
		if (languageUPCharSet != undefined) {
			for (i = 0; i < languageUPCharSet.length; i++) {
				for (j = 0; j < newFileName.length; j++) {
					if (	newFileName.charAt(j) == languageUPCharSet[i] 
						|| 
						newFileName.charAt(j) == languageLOCharSet[i]) {
							newFileName = newFileName.substring(0, j)+languageOutCharSet[i]+newFileName.substr(j+1);
					}
				}
			}
		}

		newFileName = newFileName.replace(/%[0-9a-fA-F]{2}/g, ' ').replace(/[\s]/g, '-').replace(/[^A-Za-z0-9_\-]/g, '').replace(/\-{2,}/g, '-').replace(/\-+$|^\-+/g, "");

		var
			iPosition = (newFileName + '-').substr(0, 40).lastIndexOf('-');

		if (iPosition < 10) {
			iPosition = (newFileName + '-').substr(0, 50).lastIndexOf('-');;
		}
		
		newFileName = newFileName.substr(0, iPosition < 10 ? 40 : iPosition);
		
		if (newFileName == "") {
			newFileName = "item";
		}
		
		return newFileName;
	}


	///	<summary>						Clear all custom HTML formatting (after MS WORD)</summary>
	///
	///	<param name="divSource">		DIV to process</param> 

	function HTML_ClearFormatting(divSource) {
		sSource = divSource.innerHTML;

		sSource = sSource.replace(/(<[^>]*)(\sclass=["']*Mso[^>\s]+["']*)([>\s])/gi, "$1$3");
		sSource = sSource.replace(/(<[^>]*)(\sclass=[^>\s]+)([>\s])/gi, "$1$3");
		sSource = sSource.replace(/(<[^>]*)(\slang=[^>\s]+)([>\s])/gi, "$1$3");
		sSource = sSource.replace(/(<[^>]*)(\sstyle="[^"]+")([^<]*>)/gi, "$1$3");
		sSource = sSource.replace(/(<[^>]*)(\sface="[^"]+")([^<]*>)/gi, "$1$3");
		sSource = sSource.replace(/(<[^>]*)(\sface='[^']+')([^<]*>)/gi, "$1$3");
		sSource = sSource.replace(/(<[^>]*)(\sface=[^>\s]+)([>\s])/gi, "$1$3");
		sSource = sSource.replace(/<[\/]?[\?a-zA-Z0-9]*:[^>]*>/gi, "");
		sSource = sSource.replace(/<[\/]?style[^>]*>/gi, "");
		sSource = sSource.replace(/<[\/]?SPAN>/gi, "");
		sSource = sSource.replace(/<B>&nbsp;<\/B>/gi, "&nbsp;");
//		sSource = sSource.replace(/<a name=[^>]+><\/a>/gi, "");
		sSource = sSource.replace(/<[\/]?font[^>]*>/gi, "");
//		sSource = sSource.replace(/(<a\s*name=[^>]+>)([\s]*.*)(<\/a>)/gi, "$2");
		sSource = sSource.replace(/(<[^>]*)(\ssize="[^"]+")([^<]*>)/gi, "$1$3");
		sSource = sSource.replace(/(<[^>]*)(\ssize=[^>\s]+)([>\s])/gi, "$1$3");
		
		sSource = sSource.replace(/\n/gi, " ");
		sSource = sSource.replace(/<\/SCRIPT>/gi, "\n");
		sSource = sSource.replace(/<SCRIPT.*/gi, " ");

		sSource = HTML_ClearFormatting_List(sSource);

		divSource.innerHTML = sSource;
	}
	
	function HTML_ClearFormatting_List(text) {
		var
			result;
			
		result = text;
		
		result = result.replace(/<(P|H[1-6])>[^a-z0-9_]&nbsp;(.+)<\/(P|H[1-6])>/gi, "<LI>$2</LI>");
		result = result.replace(/<LI>\s*(&nbsp;)+/gi, "<LI>");
		
		return result;
	}
	
	
	//	common function format bytes to string (Kb, Mb, b)
			
	function bytes_toString(iBytes, iPrecision) {
		var
			sSuffix = "b";
		
		if (
			(typeof(iPrecision) == 'undefined')
			||
			(iPrecision.toString().search(/^[0-4]$/) == -1)
		) {
			iPrecision = 0;
		}
		
		iPrecision = Math.pow(10, iPrecision);
		iBytes = parseInt(iBytes);
		iBytes = isNaN(iBytes) ? 0 : iBytes;
		
		if (iBytes > 1024) {
			sSuffix = "Kb";
			iBytes = Math.round(iBytes/(1024/iPrecision))/iPrecision;
		}
		
		if (iBytes > 1024) {
			sSuffix = "Mb";
			iBytes = Math.round(iBytes/(1024/iPrecision))/iPrecision;
		}
		
		if (iBytes > 1024) {
			sSuffix = "Gb";
			iBytes = Math.round(iBytes/(1024/iPrecision))/iPrecision;
		}
		
		return iBytes + " " + sSuffix;
	}
	
	
	
	//
	//
	//	listbox Quick Load
	//
	//
	
	function listbox_QuickLoad(listboxObject, dataArray, titleFunction, styleFunction) {
		if (typeof(styleFunction) == "undefined") {
			styleFunction = null;
		}
		
		var
			i = 0,
			o = "",
			bStyle = (styleFunction != null),
			bTitle = (typeof(titleFunction) == "function");
			
			
		
		listboxObject.innerHTML = "";
		o = listboxObject.outerHTML.replace(/<\/select>/i, "");
		
		if (!bStyle && !bTitle) {
			for (i = 0; i < dataArray.length; i++) {
				if (dataArray[i][i_rowState] != rs_Deleted) {
					o += '<OPTION value=' + i + '>' + dataArray[i][titleFunction] + '</OPTION>';
				}
			}
		}
		
		if (!bStyle && bTitle) {
			for (i = 0; i < dataArray.length; i++) {
				if (dataArray[i][i_rowState] != rs_Deleted) {
					o += '<OPTION value=' + i + '>' + titleFunction(dataArray[i]) + '</OPTION>';
				}
			}
		}
		
		if (bStyle && !bTitle) {
			for (i = 0; i < dataArray.length; i++) {
				if (dataArray[i][i_rowState] != rs_Deleted) {
					o += '<OPTION value=' + i + ' style="' + styleFunction(dataArray[i]) + '">' + dataArray[i][titleFunction] + '</OPTION>';
				}
			}
		}
		
		if (bStyle && bTitle) {
			for (i = 0; i < dataArray.length; i++) {
				if (dataArray[i][i_rowState] != rs_Deleted) {
					o += '<OPTION value=' + i + ' style="' + styleFunction(dataArray[i]) + '">' + titleFunction(dataArray[i]) + '</OPTION>';
				}
			}
		}
		
		o += '</SELECT>';
		listboxObject.outerHTML = o;
		
	}


	//
	// Find first position of category width catParent = parentID
	// in array arCategories
	// array must be sorted by catParent, catOrder
	//

	function getChildsBegin(parentID, start, end)
	{
		pos = Math.round((start + end) / 2);

		if (start >= end)
		{
			return end;
		}

		if (arCategories[pos][i_catParent]*1 > parentID*1)
		{
			return getChildsBegin(parentID, start, pos-1);
		}

		if (arCategories[pos][i_catParent]*1 < parentID*1)
		{
			return getChildsBegin(parentID, pos+1, end);
		}

		while (pos >= 0 && arCategories[pos][i_catParent] == parentID) 
		{
			pos--;
		}

		return pos+1;
	}



//
//
//

	//	Open new window at right side of screen

	function openNewWindow(url, name, width, height, bRandomPosition) {
		try {
			if (typeof(name) == 'undefined') {
				name = url.replace(/\.html$/i, "");
			}
		
			name = name.replace(/[\/\-]/g, "");

			
			if (typeof(width) == 'undefined') {
				width = 380;

			} else if (width > window.screen.availWidth) {
				width = window.screen.availWidth;
			}
		
			
			
			if (typeof(height) == 'undefined') {
				height = 545;
			
			} else if (height > window.screen.availHeight) {
				height = window.screen.availHeight;
			}

			
			var
				wnd = window.open(url, 'newwindow_' + name, 'scrollbars=yes,width=' + width + ',height=' + height + (bRandomPosition == true ? '' : ',top=10,left=' + (window.screen.availWidth - width - 20)));

			wnd.focus();
			return false;
	
		} catch (e) {
			return true;
		}
	}
	
	
	
	//	Check e-mail address validity
	
	function CheckEmail(email) {
		if (email.search(/^[a-z0-9\'\-_]+[a-z\'0-9\-_.]*@[a-z0-9\-_]+[a-z0-9\-_.]*\.[a-z]{2,4}$/i) == -1) {
			return false;
		}

		return true;
	}
	
	
	//	Check phone number validity
	
	function CheckPhoneNumber(phoneNumber) {
		if (phoneNumber.search(/^\+?[\d\(\)\s\-]+$/) == -1) {
			return false;
		}
		
		return true;
	}
	


	function rtrim(str) {
		return str.replace(/\s+$/g,"");
	}

	function ltrim(str) {
		return str.replace(/^\s+/g, "");
	}

	function trim(str) {
		return str.replace(/\s+$|^\s+/g, "");
	}



	//
	//	to Money conversions
	//	sample.toFixed(2)

	function Stretch(Q, L, c) { var S = Q
		if (c.length>0) while (S.length<L) { S = c+S }
		return S
	}
	
	function StrU(X, M, N) { // X>=0.0
		var
			T,
			S = new String(Math.round(X * Number("1e" + N)))

		if (S.search && S.search(/\D/)!=-1) {
			return '' + X
		}

		with (new String(Stretch(S, M+N, '0')))
		return substring(0, T=(length-N)) + '.' + substring(T)
	}

	function Sign(X) { return X<0 ? '-' : ''; }
	function StrS(X, M, N) { return Sign(X)+StrU(Math.abs(X), M, N) }
	
	try {
		Number.prototype.toFixed = new Function('n','return StrS(this,1,n)')
	} catch (e) {
	}



	function externalLinkOpen(objLink) {
		try {
			window.open(objLink.getAttribute('newhRef'), "newexternawindow", "toolbar=1,location=1,status=1,scrollbars=1,resizable=1");
			return false;
		} catch (ee) {
			return true;
		}
	}


//	Flash detected

var
	requiredVersion					= 5, // Version the user needs to view site (max 7, min 2)
	
	flash2Installed					= false,
	flash3Installed					= false,
	flash4Installed					= false,
	flash5Installed					= false,
	flash6Installed					= false,
	flash7Installed					= false,
	
	maxVersion						= 7,
	actualVersion					= 0,
	
	isIE		= (navigator.appVersion.indexOf("MSIE") != -1)		? true : false,
	isWin		= (navigator.appVersion.indexOf("Windows") != -1)	? true : false,
	
	bFlashPresent					= false;
			
	if(isIE && isWin){
		document.write('<SCR' + 'IPT language="VBScript"\> \n');
		document.write('on error resume next \n');
		document.write('flash2Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.2"))) \n');
		document.write('flash3Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.3"))) \n');
		document.write('flash4Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.4"))) \n');
		document.write('flash5Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.5"))) \n');
		document.write('flash6Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.6"))) \n');
		document.write('flash7Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.7"))) \n');
		document.write('</SCR' + 'IPT\> \n');
	}
	
	function detectFlash() {  
		if (navigator.plugins) {
			if (
				navigator.plugins["Shockwave Flash 2.0"]
				||
				navigator.plugins["Shockwave Flash"]
			) {
				var
					isVersion2 = navigator.plugins["Shockwave Flash 2.0"] ? " 2.0" : "",
					flashDescription = navigator.plugins["Shockwave Flash" + isVersion2].description,
					flashVersion = parseInt(flashDescription.charAt(flashDescription.indexOf(".") - 1));
				
				// DEBUGGING: uncomment next line to see the actual description.
				//alert("Flash plugin description: " + flashDescription);
				
				flash2Installed = flashVersion == 2;
				flash3Installed = flashVersion == 3;
				flash4Installed = flashVersion == 4;
				flash5Installed = flashVersion == 5;
				flash6Installed = flashVersion == 6;
				flash7Installed = flashVersion >= 7;
			}
		}
		
		for (var i = 2; i <= maxVersion; i++) {	
			if (eval("flash" + i + "Installed") == true) actualVersion = i;
		}
		
		if(navigator.userAgent.indexOf("WebTV") != -1) actualVersion = 2;	
		
		//	uncomment next line to display flash version during testing
		//alert("version detected: " + actualVersion);
		
		if (actualVersion >= requiredVersion) {
			bFlashPresent = true;
		}
	}


	detectFlash();

