//======================================================================//
//		trim functions													//																					//
//======================================================================//

String.prototype.Trim = function(){
	return this.replace(/(^\s*)|(\s*$)/g, "");
}

String.prototype.LTrim = function(){
	return this.replace(/(^\s*)/g, "");
}

String.prototype.Rtrim = function(){
	return this.replace(/(\s*$)/g, "");
}

//======================================================================//
//		check date validaty in "dd.mm.yyyy" format						//																						//
//======================================================================//

function check_date(d_Date, str_Separator){
	var arr_DateParts;
	var n_Errors = 0;
	
	arr_DateParts = d_Date.split(str_Separator);
	
	if (arr_DateParts[0].Trim().length > 2 || arr_DateParts[1].Trim().length > 2 ||
		arr_DateParts[2].Trim().length > 4 || arr_DateParts[2].Trim().length < 4){
		n_Errors++;
	}
	
	for (i in arr_DateParts){
		if (isNaN(parseInt(arr_DateParts[i])) == true){
			n_Errors++;
		}
	}
	
	if (isNaN(parseInt(arr_DateParts[0])) == false){
		if (arr_DateParts[0] > 31){
			n_Errors++;
		}
	}
	
	if (isNaN(parseInt(arr_DateParts[1])) == false){
		if (arr_DateParts[1] > 12){
			n_Errors++;
		}
	}
	
	if (n_Errors > 0){
		return -1;
	}else{
		if (check_date_validaty(arr_DateParts[0].Trim(), arr_DateParts[1].Trim(), arr_DateParts[2].Trim()) == 1){
			return 1;
		}else{
			return -1;
		}
	}
}

//================================================================================//
//	convert date to numbers of millisecond since January 1, 1970, 00:00:00		  //
//================================================================================//

function date_ms(d_Date, str_Separator){
	var arr_DateParts	= d_Date.split(str_Separator);
	var n_DateUTC		= Date.UTC((arr_DateParts[2] - 1900), (arr_DateParts[1] - 1), arr_DateParts[0]);
	
	return n_DateUTC;
}

//================================================================================//
//	get today date in '01.01.2001' format
//================================================================================//

function get_today_date(n_Separator){
	var obj_Today			= new Date();
	var d_Today				= obj_Today.getDate() + n_Separator + (obj_Today.getMonth() + 1) + n_Separator + obj_Today.getYear()
	
	return d_Today;
}

//=============================================================//
//	amount digits grouping function
//=============================================================//

function digit_grouping(n_Amount){
	var str_Amount			= '';
	var str_AmountGrouped	= '';
	var i					= '';
	
	str_Amount	= n_Amount.toString();
	i			= str_Amount.length;
	
	while (i >= 0){
		i -= 3;
		if (i > 0){
			str_AmountGrouped = '.' + str_Amount.substr(i,3) + str_AmountGrouped;
		}else{
			str_AmountGrouped = str_Amount.substr(0,(i + 3)) + str_AmountGrouped;
		}
	}
	
	return str_AmountGrouped;
}

//================================================================================//
//	check numeric values
//================================================================================//

function is_Numeric(n_Value){
	if (isNaN(parseInt(n_Value)) == true){
		return -1;
	}else{
		return 1;
	}
}
//================================================================================//
//	set select box options
//================================================================================//

function show_error_msg(str_ErrorMessage){
	if (str_ErrorMessage.Trim().length > 0){
		str_ErrorMessage = '\n--------------------------------------------------------------------------------\t' + str_ErrorMessage;
		str_ErrorMessage = 'Please check follow form fileds:\t' + str_ErrorMessage;
		alert(str_ErrorMessage);
	}
}

//================================================================================//
//	set select box options
//================================================================================//

function show_error_msg_tr(str_ErrorMessage){
	if (str_ErrorMessage.Trim().length > 0){
		str_ErrorMessage = '\n--------------------------------------------------------------------------------\t' + str_ErrorMessage;
		str_ErrorMessage = 'Lütfen aşağıdaki alanları kontrol ediniz:\t' + str_ErrorMessage;
		alert(str_ErrorMessage);
	}
}

//================================================================================//
//	get UserAgent (browser)
//================================================================================//

function UA(){
	if (navigator.appName.indexOf("Netscape") != -1)
		return 'NN';
	if (navigator.appName.indexOf("Microsoft") != -1)
		return 'IE';
}

//====================================================================================================//
//	show hide layers function,
//	where str_LayerID is a layer name, and str_Action is a 'show' or 'hide'
//====================================================================================================//

function showhidelayer(str_LayerID, str_Action){
	if (str_LayerID.Trim() != '' && str_Action.Trim() != ''){
		obj_Layer = (UA() == 'NN') ? eval('document.layers.' + str_LayerID) : eval('document.all.' + str_LayerID);
		
		if (str_Action == 'show')
			obj_Layer.style.display = 'block';
		if (str_Action == 'hide')
			obj_Layer.style.display = 'none';
	}
}

//====================================================================================================//
//	check date validaty, return 1 if date is true or -1 if date is not true							  //
//====================================================================================================//

function check_date_validaty(dp_Day, dp_Month, dp_Year){
	var arr_MonthDays	= new Array(12);
	
	arr_MonthDays[0]	= 31;
	arr_MonthDays[1]	= 28;
	arr_MonthDays[2]	= 31;
	arr_MonthDays[3]	= 30;
	arr_MonthDays[4]	= 31;
	arr_MonthDays[5]	= 30;
	arr_MonthDays[6]	= 31;
	arr_MonthDays[7]	= 31;
	arr_MonthDays[8]	= 30;
	arr_MonthDays[9]	= 31;
	arr_MonthDays[10]	= 30;
	arr_MonthDays[11]	= 31;
	
	if (dp_Day > 0 && dp_Month > 0 && dp_Year > 0){
		if (dp_Month <= 12){
			if (dp_Year/4 == Math.floor(dp_Year/4)){
				arr_MonthDays[1] = 29;
			}
			
			if (dp_Day <= arr_MonthDays[dp_Month - 1]){
				return 1;
			}else{
				return -1;
			}
		}else{
			return -1;
		}
	}
}

//====================================================================================================//
//	destroy pop up window object
//====================================================================================================//

function destroy_opener(str_WindowName){
	if (opener){
		var obj_PopUpWindow = eval('opener.' + str_WindowName);
		if (obj_PopUpWindow){
			obj_PopUpWindow = null;
		}
	}
}

//================================================================================//
//	set set_form_action_domain
//================================================================================//

function set_form_action_domain(str_Path){
	var str_Domain;
	if (document.domain.Trim() == 'proaui' || document.domain.Trim() == 'bitdev'){
		str_Domain = 'http://bitsecure' + str_Path;
	}else if (document.domain.Trim() == 'localhost'){
		str_Domain = 'http://localhost' + str_Path;
	}else if (document.domain.Trim() == 'www.bookinturkey.com'){
		str_Domain = 'https://secure.bookinturkey.com' + str_Path;
	}else{
		str_Domain = 'https://secure.bookinturkey.com' + str_Path;
	}
	return str_Domain;
}

//============================================================//
//		alert befor send reservation details				
//============================================================//

function be_patient(){
	alert('Rezervasyonunuz İnternet bağlantı hızına  göre 15 ile 60 saniye  arası  sürebilir !!!\t\n\n' + 
			'Rezervasyon durumu ile ilgili mesajı çıkana kadar, lütfen sabırlı olup hiç bir linke veya\nbutona  TIKLAMAYIN  !!!  ' +
			'Aksi  taktirde  rezervasyonunuz  tamamlanmayacaktır  !!!\n\n\tŞimdi \"OK\" butona tıklayıp, rezervasyonun ' +
			'tamamlanmasını\n\t\t\tBEKLEYİNİZ !!!' )
}