﻿// JScript source code
//alert("testing");
function stringtocookievv(value)
{
	//alert("tostringcookie");
	var FieldSeperator= "$";
	var ItemSeperator= "~";
	var SectionSeperator= "^";
	var  cSearch= "Search";
	var  cENDSearch= "EndSearch";
	var csearchterm= "SearchTerm";
	var carr= "ArrivalDate";
    var cdept = "DeptaureDate";
    var crooms = "NoOfRoom";
    var cocc = "Occupancy";
    var ckey="SearchKey";
	var cLANG="Lang";
	var iCurrentLoc=0;
	var iTempLoc=1;
	var sInputValue=value +"^";
	var sTempValue="";
	var sBookingValue="";
	var sBookingValueTemp="";
	var sRoomValue="";
	var sRoomValueTemp="";
	var sFieldName="";
	var sFieldValue="";
	//Disect the booking object info.
    //Booking Data
    //alert(sInputValue);
    sBookingValue = Mid(sInputValue, iCurrentLoc, InStr(sInputValue, SectionSeperator));
    iCurrentLoc = Len(sBookingValue);
    //sBookingValueTemp is the field+value pair for the data...
    //We can loop through the text...
    var mainarray=new Array();
    var idx;
    idx=0;
    var itemplocnew;
    itemplocnew=0;
    var sBookingtempValue;
    //alert("before while"+Len(sBookingValue));
    while (iTempLoc <= Len(sBookingValue)){
        //alert("inside while");
		//alert("Right = "+Right(sBookingValue, Len(sBookingValue) - iTempLoc + 2));
		//alert("Instr = "+InStr(Right(sBookingValue, Len(sBookingValue) - iTempLoc + 2), FieldSeperator));
		//alert("itemplocnew="+itemplocnew);
		//alert("iTempLoc="+iTempLoc);
		if (iTempLoc==1)
		{
			sBookingtempValue=sBookingValue;
			sBookingValueTemp=sBookingtempValue.substring(0,sBookingtempValue.indexOf(FieldSeperator));
		}else{
			sBookingtempValue=sBookingtempValue.substring(sBookingtempValue.indexOf(FieldSeperator)+1,sBookingtempValue.length);
			sBookingValueTemp=sBookingtempValue.substring(0,sBookingtempValue.indexOf(FieldSeperator));
		}
		//alert("sBookingtempValue="+sBookingtempValue);
		//sBookingValueTemp = Mid(sBookingValue, itemplocnew, InStr(Right(sBookingValue, Len(sBookingValue) - iTempLoc + 2), FieldSeperator));
		//alert("sBookingValueTemp = "+sBookingValueTemp);
		//itemplocnew=itemplocnew+Len(sBookingValueTemp);
        iTempLoc = iTempLoc + Len(sBookingValueTemp)+1;
        if (Left(sBookingValueTemp, 7) == cSearch) {
			//Were at the start of the Booking record, no data to process, only an ID tag.
        }else if (Left(sBookingValueTemp, 10) == cENDSearch){
			//Were at the end of the Booking record.. no action to take...
        }else{
			//Break down sBookingValueTemp into Field and Value
            //sFieldName = Mid(sBookingValueTemp, 1, InStr(sBookingValueTemp, ItemSeperator));
            sFieldName= sBookingValueTemp.substring(0,sBookingtempValue.indexOf(ItemSeperator));
            sFieldValue=sBookingValueTemp.substring(sBookingtempValue.indexOf(ItemSeperator)+1,sBookingtempValue.length);
          // alert("sFieldName="+sFieldName);
           //alert("sFieldValue="+sFieldValue);
            //Strip off the Dilimeter item
           // sFieldName = Left(sFieldName, Len(sFieldName) - 1);
            //sFieldValue = Right(sBookingValueTemp, Len(sBookingValueTemp) - Len(sFieldName) - 1);
            //Strip off the Dilimeter item
           // sFieldValue = Left(sFieldValue, Len(sFieldValue) - 1);
            // as were looping, we need to find the object item that matches the fieldname...
            //(Turn hard-coded text into contants...)
            switch(sFieldName){
				case csearchterm:
					mainarray[0] = sFieldValue;
                case carr:
					mainarray[1] = sFieldValue;
                case cdept:
                    mainarray[2] = sFieldValue;
                case crooms:
					mainarray[3] = sFieldValue;
                case cocc:
					mainarray[4] = sFieldValue;
				case ckey:
					mainarray[5] = sFieldValue;
               
           }
		}
	}
	return mainarray;
}
function sitestringtocookievv(value)
{
	//alert("tostringcookie");
	var FieldSeperator= "$";
	var ItemSeperator= "~";
	var SectionSeperator= "^";
	var  cSearch= "Search";
	var  cENDSearch= "EndSearch";
	var csearchterm= "SearchTerm";
	var iCurrentLoc=0;
	var iTempLoc=1;
	var sInputValue=value +"^";
	var sTempValue="";
	var sBookingValue="";
	var sBookingValueTemp="";
	var sRoomValue="";
	var sRoomValueTemp="";
	var sFieldName="";
	var sFieldValue="";
	//Disect the booking object info.
    //Booking Data
    //alert(sInputValue);
    sBookingValue = Mid(sInputValue, iCurrentLoc, InStr(sInputValue, SectionSeperator));
    iCurrentLoc = Len(sBookingValue);
    //sBookingValueTemp is the field+value pair for the data...
    //We can loop through the text...
    var mainarray=new Array();
    var idx;
    idx=0;
    var itemplocnew;
    itemplocnew=0;
    var sBookingtempValue;
   // alert("before while"+Len(sBookingValue));
    while (iTempLoc <= Len(sBookingValue)){
        //alert("inside while");
		//alert("Right = "+Right(sBookingValue, Len(sBookingValue) - iTempLoc + 2));
		//alert("Instr = "+InStr(Right(sBookingValue, Len(sBookingValue) - iTempLoc + 2), FieldSeperator));
		//alert("itemplocnew="+itemplocnew);
		//alert("iTempLoc="+iTempLoc);
		if (iTempLoc==1)
		{
			sBookingtempValue=sBookingValue;
			sBookingValueTemp=sBookingtempValue.substring(0,sBookingtempValue.indexOf(FieldSeperator));
		}else{
			sBookingtempValue=sBookingtempValue.substring(sBookingtempValue.indexOf(FieldSeperator)+1,sBookingtempValue.length);
			sBookingValueTemp=sBookingtempValue.substring(0,sBookingtempValue.indexOf(FieldSeperator));
		}
		//alert("sBookingtempValue="+sBookingtempValue);
		//sBookingValueTemp = Mid(sBookingValue, itemplocnew, InStr(Right(sBookingValue, Len(sBookingValue) - iTempLoc + 2), FieldSeperator));
		//alert("sBookingValueTemp = "+sBookingValueTemp);
		//itemplocnew=itemplocnew+Len(sBookingValueTemp);
        iTempLoc = iTempLoc + Len(sBookingValueTemp)+1;
        if (Left(sBookingValueTemp, 7) == cSearch) {
			//Were at the start of the Booking record, no data to process, only an ID tag.
        }else if (Left(sBookingValueTemp, 10) == cENDSearch){
			//Were at the end of the Booking record.. no action to take...
        }else{
			//Break down sBookingValueTemp into Field and Value
            //sFieldName = Mid(sBookingValueTemp, 1, InStr(sBookingValueTemp, ItemSeperator));
            sFieldName= sBookingValueTemp.substring(0,sBookingtempValue.indexOf(ItemSeperator));
            sFieldValue=sBookingValueTemp.substring(sBookingtempValue.indexOf(ItemSeperator)+1,sBookingtempValue.length);
          // alert("sFieldName="+sFieldName);
           //alert("sFieldValue="+sFieldValue);
            //Strip off the Dilimeter item
           // sFieldName = Left(sFieldName, Len(sFieldName) - 1);
            //sFieldValue = Right(sBookingValueTemp, Len(sBookingValueTemp) - Len(sFieldName) - 1);
            //Strip off the Dilimeter item
           // sFieldValue = Left(sFieldValue, Len(sFieldValue) - 1);
            // as were looping, we need to find the object item that matches the fieldname...
            //(Turn hard-coded text into contants...)
            if (sFieldName==csearchterm)
            {
				mainarray[0] = sFieldValue;
            }
           /* switch(sFieldName){
				case csearchterm:
					mainarray[0] = sFieldValue;
                            
           }*/
		}
	}
	return mainarray;
}
function maincookiesearch(value)
{
	//alert("maincookie");
	//alert("value ="+value);
	var FieldSeperator= "$";
	var ItemSeperator= "~";
	var SectionSeperator= "^";
	 var iCurrentLoc = 0;
	 var iTempLoc = 1;
	 var sInputValue = value;
	// alert(sInputValue);
	 var sTempValue = "";
     var sBookingValue = "";
     var sBookingValueTemp = "";
     var sRoomValue = "";
     var sRoomValueTemp = "";
     var sFieldName = "";
     var sFieldValue = "";
     var iLocOfCookie = 0;
     var iNoOfBookings = 0;
     var snoofcookie = 0;
     sBookingValue = Mid(sInputValue, iCurrentLoc, InStr(sInputValue, SectionSeperator));
     //alert("sBookingValue =" +sBookingValue);
     iCurrentLoc = Len(sBookingValue);
     //alert("iCurrentLoc =" +iCurrentLoc);
     var colBooking =new Array();
     var idx;
    idx=0;
    var sbook = "";
    var icount;
    icount=sInputValue.length;
    var itempLocOfCookie;
    itempLocOfCookie=0;
    //alert("icount = "+icount);
    //alert("UCase(Left(sInputValue, 7)) =" +UCase(Left(sInputValue, 7)));
     if (UCase(Left(sInputValue, 6)) == UCase("Search")) {
            while (iLocOfCookie < Number(icount)){
				//alert("sInputValue inside if ="+sInputValue);
				
                snoofcookie = sInputValue.indexOf("EndSearch");
                
               
                //alert("snoofcookie = "+snoofcookie);
                if (snoofcookie > 0){
				
                    //Do Until iTempLoc >= Len(sBookingValue)
                    iNoOfBookings =iNoOfBookings+ 1;
                    
                   // objBooking.ToStringData = Mid(sInputValue, iLocOfCookie, snoofcookie + 10)
					var subarray=new Array();
					
					//alert(Mid(sInputValue, itempLocOfCookie, snoofcookie + 10));
					subarray=stringtocookievv(Mid(sInputValue, itempLocOfCookie, snoofcookie + 10));
					//alert(subarray.length);
                    //Loop
                    colBooking[idx]=subarray;
                    idx=idx+1;
                    iLocOfCookie = iLocOfCookie+snoofcookie + 11;
                    snoofcookie = 0;
               }
              // alert("iLocOfCookie = "+iLocOfCookie);
               sInputValue=sInputValue.substring(sInputValue.indexOf("EndSearch")+11,sInputValue.length);
              // alert("sInputValue123 ="+sInputValue);
               //iLocOfCookie=iLocOfCookie+1
            }
        }
        return colBooking;
     
}
function maincookiesitesearch(value)
{
	//alert("maincookie");
	//alert("value ="+value);
	var FieldSeperator= "$";
	var ItemSeperator= "~";
	var SectionSeperator= "^";
	 var iCurrentLoc = 0;
	 var iTempLoc = 1;
	 var sInputValue = value;
	 //alert(sInputValue);
	 var sTempValue = "";
     var sBookingValue = "";
     var sBookingValueTemp = "";
     var sRoomValue = "";
     var sRoomValueTemp = "";
     var sFieldName = "";
     var sFieldValue = "";
     var iLocOfCookie = 0;
     var iNoOfBookings = 0;
     var snoofcookie = 0;
     sBookingValue = Mid(sInputValue, iCurrentLoc, InStr(sInputValue, SectionSeperator));
     //alert("sBookingValue =" +sBookingValue);
     iCurrentLoc = Len(sBookingValue);
     //alert("iCurrentLoc =" +iCurrentLoc);
     var colBooking =new Array();
     var idx;
    idx=0;
    var sbook = "";
    var icount;
    icount=sInputValue.length;
    var itempLocOfCookie;
    itempLocOfCookie=0;
    //alert("icount = "+icount);
    //alert("UCase(Left(sInputValue, 7)) =" +UCase(Left(sInputValue, 7)));
     if (UCase(Left(sInputValue, 6)) == UCase("Search")) {
            while (iLocOfCookie < Number(icount)){
				//alert("sInputValue inside if ="+sInputValue);
				
                snoofcookie = sInputValue.indexOf("EndSearch");
                
               
              //  alert("snoofcookie = "+snoofcookie);
                if (snoofcookie > 0){

                    //Do Until iTempLoc >= Len(sBookingValue)
                    iNoOfBookings =iNoOfBookings+ 1;
                    
                   // objBooking.ToStringData = Mid(sInputValue, iLocOfCookie, snoofcookie + 10)
					var subarray=new Array();
					
					//alert(Mid(sInputValue, itempLocOfCookie, snoofcookie + 10));
					subarray=sitestringtocookievv(Mid(sInputValue, itempLocOfCookie, snoofcookie + 10));
					//alert(subarray.length);
                    //Loop
                    colBooking[idx]=subarray;
                    idx=idx+1;
                    iLocOfCookie = iLocOfCookie+snoofcookie + 11;
                    snoofcookie = 0;
               }
             // alert("iLocOfCookie = "+iLocOfCookie);
               sInputValue=sInputValue.substring(sInputValue.indexOf("EndSearch")+11,sInputValue.length);
              //alert("sInputValue123 ="+sInputValue);
               //iLocOfCookie=iLocOfCookie+1
            }
        }
        return colBooking;
     
}

function Displaycsearch( control, visible) { 
		//alert("control fff="+control);
		var browsername=navigator.appName;
		if(document.layers){
            browsername="NN4";
//            alert("browsername" +browsername);
        }
        if(document.all){
            browsername="ie";
            //alert("browsername" +browsername);
        }
        if(!document.all && document.getElementById){
            browsername="NN6";
            //alert("browsername" +browsername);
        }
		if (browsername=="NN6"){
			var ctril;
			ctril= "document.getElementById(\""+control+"\")";
			
			var ctlName;
			ctlName = eval(ctril);
			
			switch (visible) {
				case "Hide":
					ctlName.style.visibility = 'hidden';
					ctlName.style.display = 'none';
					break;
				case "Show":
					ctlName.style.visibility = 'visible';
					ctlName.style.display = '';
					break;
				}
		}
		else if (browsername=="NN4"){
			var ctlName;
			ctlName = eval('document.'+ control);
			switch (visible) {
				case "Hide":
					ctlName.style.visibility = 'hidden';
					ctlName.style.display = 'none';
					break;
				case "Show":
					ctlName.style.visibility = 'visible';
					ctlName.style.display = '';
					break;
				}
		}
		else{
		//alert("control =" +control);
			var ctlName;
			//ctlName = eval(control);
			ctlName = eval("document.getElementById(\""+control+"\")");
			//alert("ctlName ="+ctlName);
			switch (visible) {
			
				case "Hide":
					ctlName.style.visibility = 'hidden';
					ctlName.style.display = 'none';
					break;
				case "Show":
					ctlName.style.visibility = 'visible';
					ctlName.style.display = '';
					//alert(visible);
					break;
				}
		}
	}
function loadsearchcookie()
{
	//alert("testing DisplayFromCookie");

	var soutput;
	soutput="";
	var str;
	str="";
	//str="Search$SearchTerm~bangkok$ArrivalDate~2008-07-01$DeptaureDate~2008-07-02$NoOfRoom~4$Occupancy~2|1|2~2|0~2|2|8|9~1|0$EndSearch"
	str=ReadCookiesearch("HTNSearch");
	
	var finalcol=new Array();
	
		finalcol=maincookiesearch(str);
		var i;
		var ii;
		var changehref;
		var deletehref;
		var summaryhref;
		//alert(finalcol.length);
		if (finalcol.length>0)
		{
			for (i=0;i<finalcol.length;i++)
			{
				ii=i;
				ii=ii+1;
				var ssearchterm;
				var sarrivaldate;
				var sdeptdate;
				var sroom;
				var socc;
				var skey;
				var subfarray=new Array();
				subfarray=finalcol[i];
				//alert(subfarray[0]);
				if (subfarray.length>0)
				{
					if (subfarray[0]==undefined)
					{
						ssearchterm="";
					}else{
						ssearchterm=subfarray[0];
					}
					//alert(subfarray[1].length);
					if (subfarray[1].length==0)
					{
						sarrivaldate="";
						
					}else{
						sarrivaldate=subfarray[1];
					}
					if (subfarray[2].length==0)
					{
						sdeptdate="";
					}else{
						sdeptdate=subfarray[2];
					}
					
					if (subfarray[3].length==0)
					{
						sroom=1;
					}else{
						sroom=subfarray[3];
					}
					if (subfarray[4].length==0)
					{
						socc="1|0";
					}else{
						socc=subfarray[4];
					}
					if (subfarray[5].length==0)
					{
						skey="";
					}else{
						skey=subfarray[5];
					}
					
					var ssterm;
					
					ssterm=ssearchterm.replace(/[+]/g," ");
				
					setleftsearchcookie(ssterm,sarrivaldate,sdeptdate,sroom,socc,skey);
				}
			}
						
		}
		//alert("here");
		loadsitesearchcookie();
}


function loadsitesearchcookie()
{
	//alert("testing DisplayFromCookie");

	var soutput;
	soutput="";
	var str;
	str="";
	//str="Search$SearchTerm~bangkok$ArrivalDate~2008-07-01$DeptaureDate~2008-07-02$NoOfRoom~4$Occupancy~2|1|2~2|0~2|2|8|9~1|0$EndSearch"
	str=ReadCookiesearch("HTNSiteSearch");
	//alert("str =" +str);
	var finalcol=new Array();
	
		finalcol=maincookiesitesearch(str);
		//alert("finalcol =" +finalcol);

		
		var i;
		var ii;
		var changehref;
		var deletehref;
		var summaryhref;
		//alert(finalcol.length);
		if (finalcol.length>0)
		{
			for (i=0;i<finalcol.length;i++)
			{
				ii=i;
				ii=ii+1;
				var ssearchterm;
				var sarrivaldate;
				var sdeptdate;
				var sroom;
				var socc;
				var subfarray=new Array();
				subfarray=finalcol[i];
				//alert(subfarray[0]);
				if (subfarray.length>0)
				{
					if (subfarray[0]==undefined)
					{
						ssearchterm="";
					}else{
						ssearchterm=subfarray[0];
					}
					
					var ssterm;
					ssterm=ssearchterm.replace(/[+]/g," ");
					//alert("ssearchterm ="+ssterm);
					document.getElementById("textarea").value=ssterm;
				}
			}
						
		}
}
function setleftsearchcookie(ssterm,arr,dept,sr,socc,skey)
{
	var lang;
lang=document.getElementById("language").value;
	var sarr,sfinalarr,sfinaldept,occ,adult,children,age,age1,splitocc,ssocc,nor;
	var shdnarr,shdndept;
	if (arr=="")
	{
		sfinalarr="dd/mm/yy";
		shdnarr="";
	}
	else
	{
		sarr=arr.split("-");
		sfinalarr=dateconvertorsearchnew(lang,sarr[2],sarr[1],sarr[0]);
		//alert(sfinalarr);
		//sfinalarr=sarr[2] +"/"+sarr[1]+"/"+sarr[0].substring(2);
		shdnarr=sarr[2] +"/"+sarr[1]+"/20"+sarr[0].substring(2);
		shdndept="";
	}
	//alert("inside");
	sarr="";
	//alert("dept = "+dept);
	if (dept=="")
	{
		sfinaldept="dd/mm/yy";
	}
	else if (dept=="undefined")
	{
		sfinaldept="dd/mm/yy";
		shdndept="";
	}
	else
	{
		sarr=dept.split("-");
		sfinaldept=dateconvertorsearchnew(lang,sarr[2],sarr[1],sarr[0]);
		//sfinaldept=sarr[2] +"/"+sarr[1]+"/"+sarr[0].substring(2);
		shdndept=sarr[2] +"/"+sarr[1]+"/20"+sarr[0].substring(2);
	}
	document.getElementById("cFreeSearch").value=ssterm;
	document.getElementById("arrivaldate").value=sfinalarr;
	document.getElementById("depaturedate").value=sfinaldept;
	document.getElementById("ddlNoOfRooms").value=sr;
	document.getElementById("calendararr").value=shdnarr;
	document.getElementById("calendardept").value=shdndept;
	document.getElementById("searchkey").value=skey;
	occ=socc.split("~");
	nor=parseInt(sr);
	
	for (i=1; i <= 4; i++)
	{
		//alert("i = "+i+" nor = "+nor);
		if (i <= nor)
		{
			//alert("inside");
			Displaycsearch('Room'+i, 'Show');
			ssocc=occ[i-1];
			
			splitocc=ssocc.split("|");
			adult=parseInt(splitocc[0]);
			children=parseInt(splitocc[1]);
			
			if (children==1)
			{
				age=splitocc[2];
			}
			else if (children==2)
			{
				age=splitocc[2];
				age1=splitocc[3];
			}
			var childs;
			if (children > 0)
			{
				Displaycsearch('ChildAges', 'Show');
				childs = 1;   
			}
			else
			{   
				if (childs != 1)
				{
					Displaycsearch('ChildAges', 'Hide');
				}
			}
			
			switch(children)
			{
				case 0:
					if (i==1)
					{
						//alert("adult = "+adult);
						//document.Searchfrm.ddlNoOfAdults.options[parseInt(adult)].selected = parseInt(adult);
						//document.Searchfrm.ddlNoOfAdults.options
						document.getElementById("ddlNoOfAdults").value=parseInt(adult);
						//alert("test");
						document.getElementById("ddlNoOfChild1").value=parseInt(children);
						
					}
					else
					{
						
						var iNum;
						iNum=i-1;
						eval('document.getElementById("ddlNoOfAdults'+ i +'").value = parseInt(adult)');
						eval('document.getElementById("ddlNoOfChild'+ i +'").value = parseInt(children)');
					}
					Displaycsearch('childAgeR'+i, 'Hide');
					Displaycsearch('ddlChildAge'+i+'1', 'Hide');
					Displaycsearch('ddlChildAge'+i+'2', 'Hide');
					
					break;
				case 1:
					if (i==1)
					{
						document.getElementById("ddlNoOfAdults").value=adult;
						document.getElementById("ddlNoOfChild1").value=children;
						document.getElementById("ddlChildAge11").value=age;
					}
					else
					{
						eval('document.getElementById("ddlNoOfAdults'+ i +'").value = parseInt(adult)');
						eval('document.getElementById("ddlNoOfChild'+ i +'").value = parseInt(children)');
						eval('document.getElementById("ddlChildAge'+ i +'1").value = parseInt(age)');
					}
					Displaycsearch('childAgeR'+i, 'Show');
					Displaycsearch('ddlChildAge'+i+'1', 'Show');
					Displaycsearch('ddlChildAge'+i+'2', 'Hide');
					break;
				case 2:
					if (i==1)
					{
						document.getElementById("ddlNoOfAdults").value=adult;
						document.getElementById("ddlNoOfChild1").value=children;
						document.getElementById("ddlChildAge11").value=age;
						document.getElementById("ddlChildAge22").value=age1;
					}
					else
					{
						eval('document.getElementById("ddlNoOfAdults'+ i +'").value = parseInt(adult)');
						eval('document.getElementById("ddlNoOfChild'+ i +'").value = parseInt(children)');
						eval('document.getElementById("ddlChildAge'+ i +'1").value = parseInt(age)');
						eval('document.getElementById("ddlChildAge'+ i +'2").value = parseInt(age1)');
					}
					
					Displaycsearch('childAgeR'+i, 'Show');
					Displaycsearch('ddlChildAge'+i+'1', 'Show');
					Displaycsearch('ddlChildAge'+i+'2', 'Show');
					
					break;
				default:
					Displaycsearch('childAgeR'+i, 'Hide');
					break;
			}
			
		}
		else
		{
			Displaycsearch('childAgeR'+i, 'Hide');
			Displaycsearch('ddlChildAge'+i+'1', 'Hide');
			Displaycsearch('ddlChildAge'+i+'2', 'Hide');
		}
	}
	
}

function dateconvertorsearch(lang,inday,inmon,inyear)
{
	var sdate;
	if (lang.toUpperCase()=="CN")
	{
		sdate=inyear.substring(2,inyear.length)+"年"+inmon+"月"+inday+"日";
	}
	else if (lang.toUpperCase()=="JP")
	{
		sdate=inyear.substring(2,inyear.length)+"年"+inmon+"月"+inday+"日";
	}
	else if (lang.toUpperCase()=="KR")
	{
		sdate=inyear+"년 "+inmon+"월 "+inday+"일";
	}
	else if (lang.toUpperCase()=="DE")
	{
		var monthname;
		monthname=monthsShortDE[(Number(inmon)-1)];
		sdate=inday+" "+monthname+" "+inyear.substring(2,inyear.length);
	}
	else if (lang.toUpperCase()=="FR")
	{
		var monthname;
		monthname=monthsShortFR[(Number(inmon)-1)];
		sdate=inday+" "+monthname+" "+inyear.substring(2,inyear.length);
	}
	else if (lang.toUpperCase()=="IT")
	{
		var monthname;
		monthname=monthsShortIT[(Number(inmon)-1)];
		sdate=inday+" "+monthname+" "+inyear.substring(2,inyear.length);
	}
	else if (lang.toUpperCase()=="ES")
	{
		var monthname;
		monthname=monthsShortES[(Number(inmon)-1)];
		sdate=inday+" "+monthname+" "+inyear.substring(2,inyear.length);
	}
	else
	{
		var monthname;
		//monthname=monthsShortEN[(Number(inmon)-1)];
		sdate=inday+"/"+inmon+"/"+inyear.substring(2,inyear.length);
	}
	return sdate;
}
//read cookie
function ReadCookiesearch(cookieName) {
 var theCookie=""+document.cookie;
 var ind=theCookie.indexOf(cookieName);
 if (ind==-1 || cookieName=="") return "";
 var ind1=theCookie.indexOf(';',ind);
 if (ind1==-1) ind1=theCookie.length; 
//alert(utfdecode(unescape(theCookie.substring(ind+cookieName.length+1,ind1))));
 return utfdecode(unescape(theCookie.substring(ind+cookieName.length+1,ind1)));
//return theCookie.substring(ind+cookieName.length+1,ind1);
}

//UCASE Function to convert to uppercase
function UCasesearch(str){
  return str.toUpperCase();
}
 /***
                IN: str - the string whose length we are interested in

                RETVAL: The number of characters in the string
        ***/
function Lensearch(str)
{  return String(str).length;  }
/***
        IN: str - the string we are LEFTing
            start - our string's starting position (0 based!!)
            len - how many characters from start we want to get

        RETVAL: The substring from start to start+len
***/
function Midsearch(str, start, len)
        /***
                IN: str - the string we are LEFTing
                    start - our string's starting position (0 based!!)
                    len - how many characters from start we want to get

                RETVAL: The substring from start to start+len
        ***/
        {
                // Make sure start and len are within proper bounds
                if (start < 0 || len < 0) return "";

                var iEnd, iLen = String(str).length;
                if (start + len > iLen)
                        iEnd = iLen;
                else
                        iEnd = start + len;

                return String(str).substring(start,iEnd);
        }

 function Leftsearch(str, n)
        /***
                IN: str - the string we are LEFTing
                    n - the number of characters we want to return

                RETVAL: n characters from the left side of the string
        ***/
        {
                if (n <= 0)     // Invalid bound, return blank string
                        return "";
                else if (n > String(str).length)   // Invalid bound, return
                        return str;                // entire string
                else // Valid bound, return appropriate substring
                        return String(str).substring(0,n);
        }


function Rightsearch(str, n)
        /***
                IN: str - the string we are RIGHTing
                    n - the number of characters we want to return

                RETVAL: n characters from the right side of the string
        ***/
        {
                if (n <= 0)     // Invalid bound, return blank string
                   return "";
                else if (n > String(str).length)   // Invalid bound, return
                   return str;                     // entire string
                else { // Valid bound, return appropriate substring
                   var iLen = String(str).length;
                   return String(str).substring(iLen, iLen - n);
                }
        }


function InStrsearch(strSearch, charSearchFor)
/*
InStr(strSearch, charSearchFor) : Returns the first location a substring (SearchForStr)
                           was found in the string str.  (If the character is not
                           found, -1 is returned.)
                           
Requires use of:
	Mid function
	Len function
*/
{

var j;
	for (j=0; j< Len(strSearch); j++)
	{
	    if (charSearchFor == Mid(strSearch, j, 1))
	    {
			return j;
	    }
	}
	return -1;
}
function InStrNewsearch(strSearch, charSearchFor)
/*
InStr(strSearch, charSearchFor) : Returns the first location a substring (SearchForStr)
                           was found in the string str.  (If the character is not
                           found, -1 is returned.)
                           
Requires use of:
	Mid function
	Len function
*/
{

var j;
	for (j=0; j< Len(strSearch); j++)
	{
	    if (charSearchFor == Mid(strSearch, j, 1))
	    {
			return j;
	    }
	}
	return -1;
}
function MidNewsearch(str, start, len)
        /***
                IN: str - the string we are LEFTing
                    start - our string's starting position (0 based!!)
                    len - how many characters from start we want to get

                RETVAL: The substring from start to start+len
        ***/
        {
                // Make sure start and len are within proper bounds
                if (start < 0 || len < 0) return "";

                var iEnd, iLen = String(str).length;
                if (start + len > iLen)
                        iEnd = iLen;
                else
                        iEnd = start + len;

                return String(str).substring(start,iEnd);
        }
        function GetMonthStringnewsearch(num)
		 {
		 var month;
		 switch(num)
					{
					 case 0:
						  month = "Jan";
						  break;
					 case 1:
						  month = "Feb";
						  break;
					 case 2:
						  month = "Mar";
						  break;
					 case 3:
						  month = "Apr";
						  break;
					 case 4:
						  month = "May";
						  break;
					 case 5:
						  month = "Jun";
						  break;
					 case 6:
						  month = "Jul";
						  break;
					 case 7:
						  month = "Aug";
						  break;
					 case 8:
						  month = "Sep";
						  break;
					 case 9:
						  month = "Oct";
						  break;
					 case 10:
						  month = "Nov";
						  break;
					 case 11:
						  month = "Dec";
						  break;
					}
		 return month;
		 }
function utfdecode (utftext) {
        var string = "";
        var i = 0;
        var c =0;
        var c3;
        var c1 =0;
        var c2 = 0;

        while ( i < utftext.length ) {

            c = utftext.charCodeAt(i);

            if (c < 128) {
                string += String.fromCharCode(c);
                i++;
            }
            else if((c > 191) && (c < 224)) {
                c2 = utftext.charCodeAt(i+1);
                string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
                i += 2;
            }
            else {
            c3=0;
                c2 = utftext.charCodeAt(i+1);
                c3 = utftext.charCodeAt(i+2);
                string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
                i += 3;
            }

        }

        return string;
    }





