var travel_site_number_click = 0;


function reloadWindow(){
	
	document.location.reload();
}


function Redirect( url ){
	
	window.location.href = url;
}

function $( v ) { 
	
	if( document.getElementById(v) ){
	
		return( document.getElementById(v) )
	} 

	return false;
}

function showLoading(){
	

	pos = getWindowSize();
	
	x = pos[0]/2 - 5;
	y = pos[1]/2 - 10;
	
	SetElementPositionX('load', x );
	SetElementPositionY('load', y );
	
	SetElementDisplay('load', 'block');
}	
	
function shoeLoadingPosition( obj ){
	
	x = findPosX( obj ) + 130;
	y = findPosY( obj );
	
	SetElementPositionX('load', x );
	SetElementPositionY('load', y );
	
	SetElementDisplay('load', 'block');	
}


function hideLoading(){

	SetElementDisplay('load', 'none');
}	


function hideMessagesDiv(){
	
	SetElementDisplay('messages_div', 'none');
}


function ChangeLangCountry( obj, params ){
	
	if( params == undefined || params == '' ){
		
		params = '';
	}
	
	url = 'site.php?' + params;
	
	if( obj && obj.id && obj.value ){
		
		url += obj.id + '=' + obj.value;
		Redirect( url );
	}	
}

function RedirectParent( url ){
	
	window.parent.location.href = url;
}

function GoBack(){
	
	history.back();
}

function RemoveElement(id){
	
	if( document.getElementById(id) )
		document.getElementById(id).parentNode.removeChild( document.getElementById(id) );
}

function ShowMessage(message){
	
	UnblockAll();
	hideLoading();
	
	alert( message );
}

function limitText(limitField, limitNum) {

	if (limitField.value.length > limitNum) {
		limitField.value = limitField.value.substring(0, limitNum);
	} 
	
}

function UpdateElementContent( elId, val ){ 
	
	if( document.getElementById(elId) ){
		
		document.getElementById(elId).innerHTML = val;
	}
}

function UpdateElementValue( elId, val ){ 
	
	if( document.getElementById(elId) ){
		
		document.getElementById(elId).value = val;
	}
}

function AppendElement(elId, childId){
	
	if( document.getElementById(elId) && document.getElementById(childId) ){
		
		document.getElementById(elId).appendChild(document.getElementById(childId));
	}
}

function AddContentToHiddenDiv(){
	
	if( document.getElementById('hiddenDiv') ){
		
		document.getElementById('hiddenDiv').innerHTML = content;
	}
}

function SetElementDisplay( elId, style){
	
	if( document.getElementById(elId) ){
		
		document.getElementById(elId).style.display = style;
	}
}

function SetElementPositionX( elId, x ){
	
	if( document.getElementById(elId) ){
		
		document.getElementById(elId).style.left = x + 'px';
	}	
}

function SetElementPositionY( elId, y ){
	
	if( document.getElementById(elId) ){
		
		document.getElementById(elId).style.top = y + 'px';
	}	
}

function GetElementValueById( elId ){
	
	if( document.getElementById(elId) && 
		( document.getElementById(elId).type == 'input' || document.getElementById(elId).type == 'select-one' || document.getElementById(elId).type == 'select-multiple' ) ){
		
		return document.getElementById(elId).value;
	}	
	
	return '';
}

function GetRadioValueByName( elName ){
	
	if( document.getElementsByName(elName) ){ 
		
		e = document.getElementsByName(elName);
		
		for (var i=0; i < e.length; i++ ){
			
		   	 if ( e[i].checked ){
		   	  	
		      	return e[i].value;
		     }
	    }		
	}
	
	return '';
}


function GetCheckboxStatusById( elId ){
	
	if( document.getElementById(elId) ){
		
		if( document.getElementById(elId).checked == true ){
			
			return 1;
		}
		else{
			return 0;
		}
	}	
}



function UpdateReportContent( htmlId, active, statusId, activeVal ){
	
		var width;
	
		if( document.getElementById(htmlId) && document.getElementById(htmlId).parentNode ){
			
			width = document.getElementById(htmlId).parentNode.offsetWidth;
		}
	
		UpdateElementContent( htmlId, active );
		UpdateElementContent( statusId, activeVal );
		
		if( document.getElementById(htmlId) && document.getElementById(htmlId).parentNode ){
			
			document.getElementById(htmlId).parentNode.style.width = width - 10 + 'px';
		}		
	
}


function SetParentElementSize( elId, width, height){
	
	if( document.getElementById(elId) && document.getElementById(elId).parentNode ){
		
		el = document.getElementById(elId).parentNode;
		
		if( width != '' ){
		
			el.style.width = width;	
		}

		if( height != '' ){
		
			el.style.height = height;	
		}		
		
	}
}


function changeColor(obj, color){
	
	if( obj && color != ''){
		
		obj.style.color = color;
	}
}

function changeBgColor(obj, color){
	
	if( obj && color != ''){
		
		obj.style.backgroundColor = color;
	}
}

function SetElementHref( elId, val ){ 
	
	if( document.getElementById(elId) ){
		
		document.getElementById(elId).href = val;
	}
}


function findPosX(obj){
   	
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
   }


function findPosY(obj){
		
		var curtop = 0;
		if (obj.offsetParent)
		{
			while (obj.offsetParent)
			{
				curtop += obj.offsetTop
				obj = obj.offsetParent;
			}
		}
		else if (obj.y)
			curtop += obj.y;
		return curtop;
	}
	
	
function getScrollXY() {
	
  var scrOfX = 0, scrOfY = 0;
  
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
  }
  return [ scrOfX, scrOfY ];
}	


function getWindowSize() {

	var myWidth = 0, myHeight = 0;
	
	var scrollCords = getScrollXY();
  
	if( typeof( window.innerWidth ) == 'number' ) {
	    //Non-IE
	    //myWidth = window.innerWidth - 17;
	    //myHeight = window.innerHeight - 17;
	    myWidth = window.innerWidth ;
	    myHeight = window.innerHeight ;
	    
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
	    //IE 6+ in 'standards compliant mode'
	    myWidth = document.documentElement.clientWidth - 2;
	    myHeight = document.documentElement.clientHeight - 2;
	    
	 } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
	    //IE 4 compatible
	    myWidth = document.body.clientWidth - 2;
	    myHeight = document.body.clientHeight - 2;
	 }
	 
	 myWidth += scrollCords[0];
	 myHeight += scrollCords[1];
	
	 return [ myWidth, myHeight ];
}


/*
function ShowLoading(){
	
	SetElementDisplay('loading', 'block');
	
	var loading = document.getElementById( 'loading' );
	var hider = document.getElementById( 'hider' );

	if( hider && loading ){
		
			hider.style.top = 250 + 'px';
			hider.style.left = 400 + 'px';
			hider.style.width = loading.offsetWidth + 'px';
			hider.style.height = loading.offsetHeight + 'px';
			hider.style.display = 'block';	
	}
}
*/

function AddComboValues(inputId, selectId){

	var inp = document.getElementById( inputId );
	var sel = document.getElementById( selectId );

	var newOption = new Option(inp.value, inp.value);
	sel[sel.length] = newOption;
}


function showImg( img_id , id ){
	
	x = findPosX(document.getElementById( id )) - 350;
	y = findPosY(document.getElementById( id )) - 180;
	
	document.getElementById('hiddenImg').style.left = x + 'px';
	document.getElementById('hiddenImg').style.top = y + 'px';
	
	document.getElementById('hiddenImg').innerHTML = document.getElementById( img_id ).innerHTML;
	
	if(document.getElementById('hiddenImg').style.display == "none")	document.getElementById('hiddenImg').style.display = "block";
	else document.getElementById('hiddenImg').style.display = "none";
	
	
}



function printit(){
     
	window.open('/print.php','printer','width=400,height=600,scrollbars=yes');
}


function CheckSiteNumber( obj ){

		if( obj && obj.checked ){
			
			if( obj && travel_site_number_click >= 2 ){

				alert('Only can select only 2 sites.');
				
			}
			
			travel_site_number_click++;
		}
		else{
			travel_site_number_click--;
		}	
}

function getWindowHeight( id ){
	
	obj = document.getElementById( id );

	if( obj ){

		obj.value = document.body.clientHeight;
	}
}

function setAndSubmit( id ){
	
	arr = getWindowSize();
	//getWindowHeight( id );
	
	obj = document.getElementById( id );

	if( obj ){

		obj.value = arr[1];
	}
	
	document.sites_form.submit();
}

