 
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){}
}
function limitHotelImage(o)
{
	var maxHeight = 183
	var maxWidth = 264
	try {
		if (o.height>maxHeight) o.height = maxHeight;
		if (o.width>maxWidth) o.width = maxWidth;
	} 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;
}
