var daysWeek=new Array('Sun', 'Mon', 'Tue', 'Wed', 'Thu' ,'Fri', 'Sat');
var shortMon=new Array('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');
var countryNames=new Array();

Date.prototype.format = function(format) {
	var returnStr = '';
	var replace = Date.replaceChars;
	for (var i = 0; i < format.length; i++) {
		var curChar = format.charAt(i);
		if (replace[curChar])
			returnStr += replace[curChar].call(this);
		else
			returnStr += curChar;
	}
	return returnStr;
};
Date.replaceChars = {
	shortMonths: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
	longMonths: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],
	shortDays: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'],
	longDays: ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'],
	
	// Day
	d: function() { return (this.getDate() < 10 ? '0' : '') + this.getDate(); },
	D: function() { return Date.replaceChars.shortDays[this.getDay()]; },
	j: function() { return this.getDate(); },
	l: function() { return Date.replaceChars.longDays[this.getDay()]; },
	N: function() { return this.getDay() + 1; },
	S: function() { return (this.getDate() % 10 == 1 && this.getDate() != 11 ? 'st' : (this.getDate() % 10 == 2 && this.getDate() != 12 ? 'nd' : (this.getDate() % 10 == 3 && this.getDate() != 13 ? 'rd' : 'th'))); },
	w: function() { return this.getDay(); },
	z: function() { return "Not Yet Supported"; },
	// Week
	W: function() { return "Not Yet Supported"; },
	// Month
	F: function() { return Date.replaceChars.longMonths[this.getMonth()]; },
	m: function() { return (this.getMonth() < 11 ? '0' : '') + (this.getMonth() + 1); },
	M: function() { return Date.replaceChars.shortMonths[this.getMonth()]; },
	n: function() { return this.getMonth() + 1; },
	t: function() { return "Not Yet Supported"; },
	// Year
	L: function() { return "Not Yet Supported"; },
	o: function() { return "Not Supported"; },
	Y: function() { return this.getFullYear(); },
	y: function() { return ('' + this.getFullYear()).substr(2); },
	// Time
	a: function() { return this.getHours() < 12 ? 'am' : 'pm'; },
	A: function() { return this.getHours() < 12 ? 'AM' : 'PM'; },
	B: function() { return "Not Yet Supported"; },
	g: function() { return this.getHours() == 0 ? 12 : (this.getHours() > 12 ? this.getHours() - 12 : this.getHours()); },
	G: function() { return this.getHours(); },
	h: function() { return (this.getHours() < 10 || (12 < this.getHours() < 22) ? '0' : '') + (this.getHours() < 10 ? this.getHours() + 1 : this.getHours() - 12); },
	H: function() { return (this.getHours() < 10 ? '0' : '') + this.getHours(); },
	i: function() { return (this.getMinutes() < 10 ? '0' : '') + this.getMinutes(); },
	s: function() { return (this.getSeconds() < 10 ? '0' : '') + this.getSeconds(); },
	// Timezone
	e: function() { return "Not Yet Supported"; },
	I: function() { return "Not Supported"; },
	O: function() { return (this.getTimezoneOffset() < 0 ? '-' : '+') + (this.getTimezoneOffset() / 60 < 10 ? '0' : '') + (this.getTimezoneOffset() / 60) + '00'; },
	T: function() { return "Not Yet Supported"; },
	Z: function() { return this.getTimezoneOffset() * 60; },
	// Full Date/Time
	c: function() { return "Not Yet Supported"; },
	r: function() { return this.toString(); },
	U: function() { return this.getTime() / 1000; }
}




function onloadPage(mode,showvalid){

	switch (leftTrim(mode)){
		case 'BEST OF':
		if (window.refresh_calendar) {
		refresh_calendar()
    	}else{
		GetData();
		GetBestOf();
		preloadBestOfImg();
		}
		hideloading();
		break;
		case 'BOOKING':
		hideloading();
		 if (window.noresize) return;
			var w=window.screen.availwidth;
			var h=window.screen.availheight;
				if (!w || w<=0){
				wi=700;
				h=550;
				}
			window.moveTo(0,0)
			window.resizeTo(w,h)

			if (window.correctprice) correctprice();

		break;
		case 'PRO DEAL':sendrequest();break;
		case 'ALP ADMINISTRATION':
		case 'FIRST ADMINISTRATION':
		case 'ACCOUNTING':
		case 'CLIENTS':
		case 'DEBTORS':
		case 'ALL DOCKETS':
		case 'CREDITORS':
		case 'CARS':
		case 'PRO TEMPO':
		case 'LIST': hideloading();break;
		case 'DOCKETS': 
		hideloading();
		if(window.showCanceled && showvalid) showCanceled();
		if (window.needSearch &&       datedeal) datedeal.submit();
		break;
		break;
		case 'SMS':custumerSearch();showcount();mainform.smscounter.value=smsleft;break;
		default: return;
		}
}

function leftTrim(sString) {
if (!sString || sString.length<2)return sString;
while (sString.substring(0,1) == ' '){
sString = sString.substring(1, sString.length);
}
return sString;
}


/*
var keybdBuf = "";
var keybdTick = 0;
var keybdElementName = "";
function onSelectKeyPress()
{
	var now = new Date();
	if (now.valueOf() > keybdTick.valueOf()+1500 || window.event.srcElement.name != keybdElementName)
		keybdBuf = "";
	keybdTick = now;
	keybdElementName = window.event.srcElement.name;
	var keyCode = parseInt(window.event.keyCode,10);
	keybdBuf += MakeUpper(String.fromCharCode(keyCode));
	var index = -1, s;
	for (var i = 0; i < window.event.srcElement.length; i++) {
		s = MakeUpper(window.event.srcElement.item(i).text);
		s = s.substr(0, keybdBuf.length);
		if (s == keybdBuf) {
			index = i;
			break;
		}
	}
	if (index != -1) {
		window.event.srcElement.selectedIndex = index;
		window.event.returnValue = false;
		if (window.event.srcElement.onchange)
			window.event.srcElement.onchange();
	}
	return false;
}

function MakeUpper(s)
{
	var outStr, c;
	outStr = "";
	for (var i = 0; i < s.length; i++) {
		c = s.charCodeAt(i);
		if (c >= 97 && c <= 122)
			c -= 32;
		outStr += String.fromCharCode(c);
	}
	return outStr;
}
*/
function keyOnlyEng(obj,num){
	ek=event.keyCode;
	lim=65;lmax=127;
	if (num && num==2) {
		lim=30;num=false;	
		}
	if (num) {lim=48;lmax=57;}
	
	if (ek >lmax || ek<lim ) {
			event.keyCode=0;
			alert (num?'Only number':'Only english');
			obj.focus();
			}
}



function compareNumbers(a, b) {
   return a - b
}




function Select(){
	this.options = new Array();
}

Select.prototype.addOption = function(text,value){
	this.options[this.options.length] = new Option(text,value);
}

Select.copy = function(select1,select2){
	select2.options.length = select1.options.length;
	for (var i=0;i<select1.options.length;i++){
		if (select1.options[i]&&select2.options[i]){
			select2.options[i].text = select1.options[i].text;
			select2.options[i].value = select1.options[i].value;
		}
		else select2.options.length--;
	}
			select2.selectedIndex = 0;
}



function changeViewHeader(ob){
	if (document.all.HeaderDiv.style.display!='none'){
		document.all.HeaderDiv.style.display='none';
		checkValXml(document.all.tmpInput,'setSessionVariable','needClose|true')
		ob.src='images/open.gif'
		}else{
		document.all.HeaderDiv.style.display='inline';
		checkValXml(document.all.tmpInput,'setSessionVariable','needClose|false')
		ob.src='images/close_grey.gif'
		}
	}

function openDealWin(url){
	var DealWin = window.open('','Dealwin','scrollbars=yes,resizable=yes,dependent=yes,left=0,top=0,titlebar=yes');
	DealWin.document.writeln("<span style='font:x-small Arial'>Please Wait...</span>");
	DealWin.focus();
	DealWin.document.location=url;
}

function hotelInfo(cityHot,nameHot)
{
	a='../new/hotelinfo.php?citycode='+cityHot+'&hotel='+nameHot.replace(/&/g,'%26')+'&';
	var hotelWin = window.open(a,'hotel','width=650,height=550,dependent=yes,titlebar=no,scrollbars=yes');
	hotelWin.focus();
}


function checkValXml(objectName,functionName,adds) {

if (functionName=='upperCase') {
objectName.value=objectName.value.toUpperCase()
return;
}


if (!objectName || !objectName.value) return;
	if (!adds) adds='';
	var req="<request><function>"+functionName+"</function><value>"+objectName.value+"</value><argument>"+adds+"</argument></request>";
	var xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	xmlhttp.open("POST","/midoffice/checkval.php",true);
	xmlhttp.setRequestHeader("content-type","application/xml");
  	xmlhttp.onreadystatechange = function () {
    if (xmlhttp.readyState == 4)   objectName.value=xmlhttp.responseText;
	}

	xmlhttp.send(req);
}


function sendxml(target,xmlobj,adds,zip){
	if (!adds) adds='';
	t = (target=='t4t2hotels') ? 't4t2hotels' : ('xmlserver'+(zip?'Zip':''));
	var req="<request><target>"+target+"</target>"+adds+"</request>";
	//alert(target);
	//alert(req)
	var xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	xmlhttp.open("POST","/xmlServer/"+t+".php?"+(window.sessionid?"?PHPSESSID="+window.sessionid:''),true);
	xmlhttp.setRequestHeader("content-type","application/xml");
  	xmlhttp.onreadystatechange = function () {
    if (xmlhttp.readyState == 4) {
		ok=1;
        xmlobj.load(xmlhttp.responseXML); // responseXML : XmlDocument

		//alert(xmlhttp.responseText);
		 if (xmlobj.parseError.errorCode){
			 		hideloading();
					alert("Xml Error :"+xmlobj.parseError.reason)	;
					}
			 }
   	}
	xmlhttp.send(req);
}


function viewloading(){
	if (!document.getElementById('loading')) return;
	x=document.getElementById('loading');
      if (!x.length)   {x.style.visibility="visible";x.focus();}
      else for(i=0;i<x.length;i++ )  x[i].style.visibility="visible";
	  
	   	for (i=0;i<10000;i++);
}

function hideloading(){
	if (!document.getElementById('loading')) return;
	x=document.getElementById('loading');
      if (!x.length)   x.style.visibility="hidden";
      else for(i=0;i<x.length;i++ )  x[i].style.visibility="hidden";
}

function getCalFl(){

var depCity;

if (!document.frames['callFrame'] || !document.frames['callFrameRet'] || !document.frames['callFrame'].document.all('setfield') ||  !document.frames['callFrameRet'].document.all('setfield')) return;

if (document.searchcity.dep_city) depCity=document.searchcity.dep_city.value;

if (!depCity) depCity=window.poinOfOrign?window.poinOfOrign:"TLV";
depCity=depCity.toUpperCase();

if (document.searchcity.country.value.length==3){
	document.all("tocity").innerHTML='Departure: '+depCity+'-'+document.searchcity.country.value.toUpperCase();
	document.all("fromcity").innerHTML='Return: '+document.searchcity.country.value.toUpperCase()+'-'+depCity;
	document.frames['callFrame'].document.all('setfield').value='txtYesDate';
	document.frames['callFrameRet'].document.all('setfield').value='txtYesDateRet';
	document.frames['callFrame'].getFlights();
	document.frames['callFrameRet'].getFlights();
	}
	else{
	document.frames['callFrame'].clearFlights();
	document.frames['callFrameRet'].clearFlights();
	document.all("tocity").innerHTML='Departure';
	document.all("fromcity").innerHTML='Return';
	}
}


function openwin( url, target ){
		newwin=window.open( url, target , "width=300,height=400,resizable=yes,scrollbars=yes");
		newwin.focus();
		}

function openWinCity(forma,field){
	var cityList = window.open('','','dependent=yes,width=300,height=240,,left=40,top=138,scrollbars=yes');
	cityList.document.write('<font style="font: xx-small Verdana;">Data loading...</font>');
	cityList.focus();
	cityList.document.location='selectcity.php?name='+forma+'.'+field+'&cod='+eval(forma+"."+field+".value")
}

function WRONG_print_money(val){
	bigValue=parseInt (val*100)
	if (isNaN (bigValue)) bigValue=0;
	if (bigValue==0) return '0.00'
	textValue=bigValue+'';
	l=textValue.length
	return textValue.substring(0,l-2)+'.'+textValue.substring(l,l-2)
}

function print_money(val){
  return (1*val).toFixed(2);
}

function calculator(fld){
	var res;
	re=/[^0-9\+\-\*\.\/ ]/
	ek=window.event.keyCode;
	if (ek==13) {
		if (!fld.value || re.exec(fld.value))return false;
		try {
			eval('res='+fld.value);
		}
		catch (e) {
		 	return false;
		 }
		if (!isNaN(res))  fld.value=res.toFixed(2);
		if (fld.onchange)fld.onchange();
		return true;
		}
	return false;

}


