 
window.onload				= init;

function init()
{
	if(window.initKSForm) initKSForm();	
}

function send_sendToAFriend(path,nPopupWinWidth, nPopupWinHeight, bPopupWinScrollbars, bPopupWinToolbar)
{
	nPopupWinTop = screen.height/2 - nPopupWinHeight/2;
	nPopupWinLeft = screen.width/2 - nPopupWinWidth/2;
	
	//nDocID, nFolderID, strDoctype, strPageHeader
	//window.open(strLocation + 'TemplateControls/SendToAFriendTemplatePopup.aspx?docID=' + nDocID + '&folderID=' + nFolderID + '&docType=' + strDoctype + '&pageHeader=' + strPageHeader, 'sendToFrient','top=' + nPopupWinTop + ',left=' + nPopupWinLeft + ',width=' + nPopupWinWidth + ',height=' + nPopupWinHeight + ',scrollbars=' + (bPopupWinScrollbars=='True'?'yes':'no') + ',toolbar=' + (bPopupWinToolbar=='True'?'yes':'no'));
	
	var arrLocation = String(document.links[0]).split('Templates');
	window.open(path, 'sendToFrient','top=' + nPopupWinTop + ',left=' + nPopupWinLeft + ',width=' + nPopupWinWidth + ',height=' + nPopupWinHeight + ',scrollbars=' + bPopupWinScrollbars + ',toolbar=' + bPopupWinToolbar);
}

function play_video(videoSource)
{
	var frameObj = document.getElementById('VideoTemplate1_frameVideo');
	frameObj.src	=	videoSource;
}

function openPopUpWindow(url, width, height, scroll, resizable)
{
	if(!width)
	{
			window.open(url);
	}	
	else	window.open(url,null,'height=' + height + ',width=' + width + ',menubar=no,status=yes,scrollbars=' + scroll + ',resizable=' + resizable);
}

function CopyTextIntoClipboard(s)
{
	try{window.clipboardData.setData("Text",s);}catch(e){};
}

function ShowModalDialog(sUrl, sArguments, iWidth, iHeight)
{
	sFeatures = "unadorned:Yes; status:Yes; help:No; dialogWidth:" + iWidth + "px; dialogHeight:" + iHeight + "px";	
	
	CopyTextIntoClipboard(sUrl);
	
	return(showModalDialog(sUrl, sArguments, sFeatures));
}
//''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
function xmlBubbleSort(sortNode, sortOn, nodeName, type)
{
	var nodes			= sortNode.selectNodes(nodeName);
	
	for (var i=0; i<nodes.length; i++)
	{
		var node		= nodes[i];
		var rows		= node.selectNodes(nodeName);
		
//		for(var n=0; n<rows.length; n++)	xmlBubbleSort(node, sortOn, type);
		
		var tests		= node.parentNode.selectNodes(nodeName);
		
		for(var nd=0; nd<tests.length; nd++)
		{
			var test	= tests[nd];
			var c1		= trim(test.selectSingleNode(sortOn).text);
			var c2		= trim(node.selectSingleNode(sortOn).text);
			
			switch(type)
			{
				case 'float':
				
					c1	= parseFloat(c1);
					c2	= parseFloat(c2);
				
				break;
				default:
				break;
			}
			if(c1 > c2)
			{
				test.parentNode.insertBefore(node, test);
				
//				window.status	+= nd+", ";
				
				break;
			}
//			window.status	+= ".";
		}
//			window.status	+= ",";
	}
}
//''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
//''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
//''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
function dbg(O)
{
	if(typeof(O)=="string"||typeof(O)=="number"){alert(O);return;}
	
	var arr	=	[];
	var count = 0;
	for(var o in O)
	{
		if(typeof(O[o])=="string" || typeof(O[o])=="number")
		{
				arr.push(o+"='"+O[o]+"' " + (count%5==0?"\n":";   "));
		}
		else{
			arr.push(o + (count%5==0?"\n":";   "));
			//dbg(O[o])
		}
		count++;
	}
	arr.sort();
	alert(arr.join(""));
}
function TryLoadImg(e,o){
	if(o.tryed) return;
	o.tryed = true;
	//alert("TryLoadImg");
	//try{window.clipboardData.setData("Text",o.src);}catch(e){};
	o.src = "http://212.25.113.202/graphics/orcedia.jpg"
}
//''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
//''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
function loading(arg)	{	ws(arg);			}
function loadpage()		{	ws("loading...");	}
function saving()		{	ws("saving...");	}
function done()			
{
	if(window.top.dialogArguments && window.top.dialogArguments.window)
	{	
		window.dialogArguments.window.status		= "Done";	
	}
	else					window.status			= "Done";		
}
function ws(arg)		
{
	if(window.top.dialogArguments && window.top.dialogArguments.window)
	{	
		window.dialogArguments.window.status		= arg;
	}
	else					window.status			= arg;			
}
//''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
function CFloat(vle,dflt)
{
    var str		= trim(vle);
    var strd	= trim(dflt);
    
	var intg	= parseFloat(str,10);
	var intd	= parseFloat(strd,10);
	
		intd	= (isNaN(intd)?0:intd);
    
	return (isNaN(intg)?intd:intg);
}
//''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
function CInt(vle,dflt)
{
    var str		= trim(vle);
    var strd	= trim(dflt);
    
	var intg	= parseInt(str,10);
	var intd	= parseInt(strd,10);
	
		intd	= (isNaN(intd)?0:intd);
    
	return (isNaN(intg)?intd:intg);
}
//''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
function CStr(vle,dflt)
{
       dflt += "";
    if(dflt=="undefined") dflt = "";
    if(dflt=="null")      dflt = "";

       vle += "";
    if(vle=="undefined") return dflt;
    if(vle=="null")      return dflt;
    
    return vle;
}
//''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
function trim(vle)
{
        var trm = CStr(vle);
    return  trm.replace(/(^\s*)|(\s*$)/g, "");
}
//''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
function visible(obj)
{
	if(obj) obj.style.visibility 	= "visible";	
}
//''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
function hidden(obj)
{
	if(obj) obj.style.visibility	= "hidden";	
}
//''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
function disabled(obj)
{
	if(obj) obj.disabled		 	= true;	
}
//''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
function enabled(obj)
{
	if(obj) obj.disabled		 	= false;	
}
//''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
function isNone(obj)
{
	if(obj)
	{
		if(obj.style.display=="none")	return true;	
		else							return false;
	} 
}
//''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
function none(o)
{
	if(o) o.style.display		= "none";	
}
//''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
function block(o)
{
	if(o) o.style.display		= "block";	
	
}
//''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
function blocknone(o)
{	
	try
	{
		if(o)
		{
			if(o.style.display && o.style.display=="block")
			{
					none(o);
			}	
			else	block(o);
		}
	}
	catch(e){ws("blocknone() "+e.description)}
}
//''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
function imageOff(o)
{
	o.src		= o.src.replace(/_on\./gi,"_off.");
}
//''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
function imageOn(o)
{
	o.src		= o.src.replace(/_off\./gi,"_on.");
}
//''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
function imageOnOff(o)
{
	try
	{
		if(o && o.src)
		{
			if(o.src.indexOf("_on.")>0)
			{
					imageOff(o);
			}	
			else	imageOn(o);
		}
	}
	catch(e){ws("imageOnOff() "+e.description)}
}
//''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
function classOff(o)
{
	o.className	= o.className.replace(/_on/gi,"_off");
}
//''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
function classOn(o)
{
	o.className	= o.className.replace(/_off/gi,"_on");
}
//''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
//''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
function postXMLData(xmlpath, xmldoc)
{
	try
	{
		loading(xmlpath);
		
		var xmlhttp						= new ActiveXObject("Microsoft.XMLHTTP");
			xmlhttp.onreadystatechange	= HandleStateChange;
			xmlhttp.Open("POST", xmlpath, false);
			xmlhttp.setRequestHeader("Content-Type", "text/xml; charset='utf-8' ");
			xmlhttp.Send(xmldoc);
	}
	catch (e){ws("postXMLData() "+e.description);}
	
			xmlhttp		= null;

	return;

//''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
	function HandleStateChange()
	{
//		alert(xmlhttp.readyState);
		
		if(xmlhttp.readyState==4)
		{
			window.result	= xmlhttp.responseText;
			
			if(window.result)
			{
				if(window.result.toLowerCase().indexOf("error")>=0)	ws("postXMLData.HandleStateChange() error: "+window.result);
				else												done();
			}
		}
	}
}
//''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
function readXML(xml)
{
	var	xmldoc								= null;
	
	try
	{
		var	xmldoc							= new ActiveXObject("Msxml2.DOMDocument");
			xmldoc.async					= false;
			xmldoc.loadXML(xml);
	}
	catch(e)
	{
		throw new Error(e.description);
	}
	if(xmldoc.parseError.errorCode!=0)
	{
		throw new Error(xmldoc.parseError.reason);
	}
	return xmldoc;	
}
//''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
function redirect(result)
{
	if(result.toLowerCase().indexOf("http://")<0 && result.toLowerCase().indexOf("https://")<0)	return false;
	else											
	{
		window.location.href			= result; 	
		
		return true;
	}
}
//''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
//''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

function limitImageHeight(imgId, maxHeight)
{
	try {
		var o = document.getElementById(imgId);
		if (o.height>maxHeight) o.height = maxHeight;
	} catch(e){}
}
var prevO,prevMaxHeight
function limitObjHeight(o, maxHeight)
{
	prevO = o
	prevMaxHeight = maxHeight
	setTimeout("limitObjHeightAfterLoad()","1000")
}
function limitObjHeightAfterLoad(){
	try {
		if (prevO.height>prevMaxHeight) prevO.height = prevMaxHeight;
	} catch(e){}
}

var idx=0;
function limitHotelImage(id)
{
	var o=document.getElementById(id);
	var maxHeight = 183
	var maxWidth = 264
	
	try {
		if(idx>=120)
			return;
		if(o.height==0)
		{
			idx++;
			setTimeout("limitHotelImage('"+id+"')","500");
		}
		else
		{
			if (o.height>maxHeight) o.height = maxHeight;
			if (o.width>maxWidth) o.width = maxWidth;
			return;
		}
	} catch(e){}
	
}
//''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
/////////////////IMAGE ROTATOR///////////////////////////

var interval = 5;
var random_display = 1;
interval *= 1000;
var image_index = 0;
function rotateImage(place)
{
	var new_image = getNextImage();
	document[place].src = new_image;
	var recur_call = "rotateImage('"+place+"')";
	setTimeout(recur_call, interval);
}
function getNextImage()
{
	if (random_display) 
	{
		image_index = generate(0, number_of_image-1);
	}
	else 
	{
		image_index = (image_index+1) % number_of_image;
	}
	var new_image = eval('image'+image_index);
	return(new_image);
}

function generate(x, y) 
{
	var range = y - x + 1;
	return Math.floor(Math.random() * range) + x;
}

////////////////////////////   Draw HomePage Search Engine - start  ////////////////////////////
var SeAJAX = null;

var se = {};

var seKeyParams = {};


function ShowSE(docId,urlPrefix,lang,se_type)
{
    seKeyParams.docid = docId
    seKeyParams.seType=se_type;
    var key = "SE_"+seKeyParams.docid;
    
    
    if(!isnull(se[key]))
    {
        DrawSE(se[key])
        return;
    }
    
    
    
    var sURL = urlPrefix  + "HomePageSE.aspx?lang=" + lang  + "&DocID=" + docId +"&seType="+se_type ;
    
    //try{window.clipboardData.setData("Text",sURL);}catch(e){};
    
    if ( window.XMLHttpRequest ) 
    {
	   SeAJAX = new XMLHttpRequest();
    }
    else 
    {
	   SeAJAX = new ActiveXObject("MSXML2.XMLHTTP");
    }
    SeAJAX.onreadystatechange = ShowSECallback;  
    
    SeAJAX.open( "GET", sURL, true );
    
    SeAJAX.send(null);
}

function ShowSECallback()
{
    if ( SeAJAX.readyState == 4) {
        try{
            var content = SeAJAX.responseText
           // var contentArr = content.split("~~~")
            
           // content = contentArr[1]
            
            var key = "SE_"+seKeyParams.docid;
            
            se[key] = content;
            //alert(content);
            //try{window.clipboardData.setData("Text",content);}catch(e){};
           DrawSE(content)
            
            
            
        }
        catch(e){
            //alert(e.description)
        }
    }
}

var strContent="";
function DrawSE(str)
{
	if (strContent=="" && str!="")
	{
		strContent = str;
	}
    var divSe = document.getElementById('divSeContent');
    if (divSe==null||divSe=='null')
    {
		setTimeout("DrawSE()",500);    
    }
    //try{window.clipboardData.setData("Text",galleryPopPagingHTML);}catch(e){};
    
    divSe.innerHTML = strContent; 
    strContent="";
    //divSe.style.display=''

}
var ajaxCall;
function GetBanners(lang)
{
	var param='';
	var url=window.location.href;
	var arr=url.split('?');
	if(arr.length>1)
	{
		param=arr[1];
	}
	
	if ( window.XMLHttpRequest ) 
	{
		ajaxCall = new XMLHttpRequest();
	}
	else 
	{
		ajaxCall = new ActiveXObject("MSXML2.XMLHTTP");
	}
	ajaxCall.onreadystatechange = getBannersRes;
	var urlStr=CLVAR.GET_BANNERS_URL+"?lang="+lang;
	if(param != '')
	{
		urlStr+='&'+param;
	}
	//alert(urlStr)
	ajaxCall.open("GET", urlStr, true );
	ajaxCall.send(null);
}

function getBannersRes()
{
	if ( ajaxCall.readyState == 4) 
	{
		try
		{
			var content = ajaxCall.responseText;
			var contentArr = content.split("~~~")
			content = contentArr[1];
			var divObj=document.getElementById("divHeaderBanners");
			if(divObj)
			{
				divObj.innerHTML=content;
			}
			
		}
		catch(e){};
	}

}

////////////////////////////   Draw HomePage Search Engine - end  ////////////////////////////