//xmlhttp.js
	
	//Function to create an XMLHttp Object.
	function getxmlhttp (){
		//Create a boolean variable to check for a valid microsoft active X instance.
		var xmlhttp = false;
		
		//Check if we are using internet explorer.
		try {
			//If the javascript version is greater than 5.
			xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			//If not, then use the older active x object.
			try {
				//If we are using internet explorer.
				xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (E) {
				//Else we must be using a non-internet explorer browser.
				xmlhttp = false;
			}
		}
		
		//If we are using a non-internet explorer browser, create a javascript instance of the object.
		if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
			xmlhttp = new XMLHttpRequest();
		}
		
		return xmlhttp;
	}
	
	//Function to process an XMLHttpRequest.
	function processajax (serverPage, obj, getOrPost, str){
		//Get an XMLHttpRequest object for use.
		xmlhttp = getxmlhttp ();
		if (getOrPost == "get"){
			xmlhttp.open("GET", serverPage);
			xmlhttp.onreadystatechange = function() {
				if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
					obj.innerHTML = xmlhttp.responseText;
				}
			}
			xmlhttp.send(null);
		} else {
			xmlhttp.open("POST", serverPage, true);
			xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
			xmlhttp.onreadystatechange = function() {
				if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
					obj.innerHTML = xmlhttp.responseText;
				}
			}
			xmlhttp.send(str);
		}
	}
function SwapProducts (theelement,Prod1,Prod2,Prior1,Prior2){
		
			serverPage = "products_priority_swap.php" + "?Prod1=" + Prod1 +"&Prod2=" + Prod2 +"&Prior1=" + Prior1 +"&Prior2=" + Prior2;
			var obj = document.getElementById(theelement);
			xmlhttp.open("GET", serverPage);
			xmlhttp.onreadystatechange = function() {
				if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
					obj.innerHTML = xmlhttp.responseText;
				}
			}
			xmlhttp.send(null);
		} 
		
		
function confirmDelete(message,url) 
{
	if (confirm(message)) 
	{
		document.location = url;
	}
}
function previewSkin() 
{
	document.getElementById('previewskinpic').src = 'http://www.piccadillyapartments.com.au/skins/' + document.getElementById('previewskin').options[document.getElementById('previewskin').selectedIndex].value + '/images/thumbnail.jpg';
}
 
function toggledisplay(id)
{
	var element = document.getElementById(id);
	if (element.style.display == 'none') element.style.display = '';
	else element.style.display = 'none';
}
function checkdata(length,element,counter,message)
{
	if (element.value.length > length) 
	{		
		element.value = element.value.substring(0, length);
		alert(message);		
	}
	else
	{
		document.getElementById(counter).innerHTML = length - element.value.length;
	}
}
function NewWindow(mypage,myname,w,h)
{
	var win = null;
	LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
	settings = 'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',toolbar=no, directories=no, location=no,   status=no, menubar=no, resizable=no, scrollbars=no'
	win = window.open(mypage,myname,settings)
}
function popupWindow(mypage,myname,w,h,scroll)
{
	var win = null;
	LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
	settings = 'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',toolbar=no, directories=no, location=no,   status=no, menubar=no, resizable=no, scrollbars='+scroll;
	win = window.open(mypage,myname,settings)
}

function toolTip(msg)
{
}

var refreshinterval=15;
var displaycountdown="yes";
var starttime;
var nowtime;
var reloadseconds=0;
var secondssinceloaded=0;
 
function starttime() 
{ 
	starttime=new Date();
	starttime=starttime.getTime();
	refreshinterval = document.getElementById('newrefresh').value;
	countdown();
} 

function countdown() 
{ 
	nowtime= new Date();
	nowtime=nowtime.getTime();
	secondssinceloaded=(nowtime-starttime)/1000;
	reloadseconds=Math.round(refreshinterval-secondssinceloaded);	

	document.getElementById('newrefresh').value = document.getElementById('newrefresh').value.replace(/[^0-9]/g, '');
	if (document.getElementById('newrefresh').value > 0) refreshinterval = Math.round(document.getElementById('newrefresh').value*60);
	else document.getElementById('newrefresh').value = Math.round(refreshinterval/60)

	
	if (refreshinterval>=secondssinceloaded) 
	{ 
		var timer=setTimeout("countdown()",1000);
		if (displaycountdown=="yes") 
		{ 
			var seconds = reloadseconds;
			var hours;
			var minutes;
			if (seconds >= 60)
			{
				minutes = Math.floor(seconds / 60);
			 	seconds -= (minutes * 60);
			 	if (minutes >= 60)
			   	{
					hours = Math.floor(minutes / 60);
				 	minutes -= (hours * 60);
			   	}
				else hours = 0;
			}
			else
			{
				hours = 0;
				minutes = 0;
			}
			if (hours < 10) hours = "0"+hours;
			if (minutes < 10) minutes = "0"+minutes;
			if (seconds < 10) seconds = "0"+seconds;
			remaintime = hours + ":" + minutes + ":" + seconds;
			document.getElementById('refreshin').innerHTML = remaintime;
		} 
	}
	else 
	{ 
		clearTimeout(timer);
		window.location.reload();
	} 
} 

var W3CDOM = (document.createElement && document.getElementsByTagName);

function initFileUploads()
{
	if (!W3CDOM) return;
	var fakeFileUpload = document.createElement('div');	
	fakeFileUpload.className = 'fakefile';
	fakeFileUpload.appendChild(document.createElement('input'));
	var image = document.createElement('img');
	image.src='../skins/admin/images/search.php';
	fakeFileUpload.appendChild(image);
	var x = document.getElementsByTagName('input');
		
	for (var i=0;i<x.length;i++)
	{
		if (x[i].type != 'file') continue;
		if (x[i].getAttribute('noscript')) continue;
		if (x[i].parentNode.className != 'fileinputs') continue;
		x[i].className = 'file hidden';
		var clone = fakeFileUpload.cloneNode(true);
		x[i].parentNode.appendChild(clone);
		x[i].relatedElement = clone.getElementsByTagName('input')[0];
		if (x[i].value)
			x[i].onchange();
		x[i].onchange = x[i].onmouseout = function () {
			this.relatedElement.value = this.value;
		}
	}
}
function move_box(an, box)
{
    var cleft = 0;
    var ctop = 0;
    var obj = an;

    while (obj.offsetParent)
    {
        cleft += obj.offsetLeft;
        ctop += obj.offsetTop;
        obj = obj.offsetParent;
    }

    box.style.left = cleft + 'px';

    ctop += an.offsetHeight + 8;

    // Handle Internet Explorer body margins,
    // which affect normal document, but not
    // absolute-positioned stuff.
    if (document.body.currentStyle &&
        document.body.currentStyle['marginTop'])
    {
        ctop += parseInt(
            document.body.currentStyle['marginTop']);
    }

    box.style.top = ctop + 'px';
}

// Shows a box if it wasn't shown yet or is hidden
// or hides it if it is curre
function show_hide_box(an, width, height, borderStyle, closeLink)
{
    var href = an.href;
    var boxdiv = document.getElementById(href);

    if (boxdiv != null)
    {
        if (boxdiv.style.display=='none')
        {
            // Show existing box, move it
            // if document changed layout
            move_box(an, boxdiv);
            boxdiv.style.display='block';
        }
        else
            // Hide currently shown box.
            boxdiv.style.display='none';
        return false;
    }

    // Create box object through DOM
    boxdiv = document.createElement('div');

    // Assign id equalling to the document it will show
    boxdiv.setAttribute('id', href);

    boxdiv.style.display = 'block';
    boxdiv.style.position = 'absolute';
    boxdiv.style.width = width + 'px';
    boxdiv.style.height = height + 'px';
    boxdiv.style.border = borderStyle;
    boxdiv.style.textAlign = 'right';
    boxdiv.style.padding = '4px';
    boxdiv.style.background = '#FFFFFF';
    document.body.appendChild(boxdiv);

    var offset = 0;
    
    var contents = document.createElement('iframe');
    contents.scrolling = 'auto';
    contents.frameBorder = '0';
    contents.style.width = width + 'px';
    contents.style.height = (height - offset) + 'px';

    boxdiv.appendChild(contents);

    move_box(an, boxdiv);

    if (contents.contentWindow)
        contents.contentWindow.document.location.replace(
            href);
    else
        contents.src = href;

    // The script has successfully shown the box,
    // prevent hyperlink navigation.
    return false;
}

var imageonoffstate = 'off';
function changeonoff(imgid,imgoff,imgon)
{
	var imagesrc = document.getElementById(imgid);
	if (imageonoffstate == 'off')
	{
		imageonoffstate = 'on';
		imagesrc.src = imgon;
	}
	else
	{
		imageonoffstate = 'off';
		imagesrc.src = imgoff;
	}
}
function loadContent(file)
{
  var head = document.getElementsByTagName('head').item(0)
  var scriptTag = document.getElementById('loadScript');
  if(scriptTag) head.removeChild(scriptTag);
  script = document.createElement('script');
  script.src = file;
	script.type = 'text/javascript';
	script.id = 'loadScript';
	head.appendChild(script)
}
function replaceAll( str, from, to ) 
{
    var idx = str.indexOf( from );	
    while ( idx > -1 ) 
    {
        str = str.replace( from, to );
        idx = str.indexOf( from );
    }	
    return str;
}
function convertvalues(element)
{
	element.value = replaceAll(element.value, '-', '|');
}
function inArray(array, value) 
{
	for(var i = 0; i < array.length; i++)
	{
		if (array[i] === value) return i;
	}
	return false;
}
// CSS Browser Selector   v0.2.5
// Documentation:         http://rafael.adm.br/css_browser_selector
// License:               http://creativecommons.org/licenses/by/2.5/
// Author:                Rafael Lima (http://rafael.adm.br)
// Contributors:          http://rafael.adm.br/css_browser_selector#contributors
var css_browser_selector = function() {
	var 
		ua=navigator.userAgent.toLowerCase(),
		is=function(t){ return ua.indexOf(t) != -1; },
		h=document.getElementsByTagName('html')[0],
		b=(!(/opera|webtv/i.test(ua))&&/msie (\d)/.test(ua))?('ie ie'+RegExp.$1):is('gecko/')? 'gecko':is('opera/9')?'opera opera9':/opera (\d)/.test(ua)?'opera opera'+RegExp.$1:is('konqueror')?'konqueror':is('applewebkit/')?'webkit safari':is('mozilla/')?'gecko':'',
		os=(is('x11')||is('linux'))?' linux':is('mac')?' mac':is('win')?' win':'';
	var c=b+os+' js';
	h.className += h.className?' '+c:c;
}();