﻿//Create a boolean variable to check for a valid Internet Explorer instance.
var xmlhttp = false;
//Check if we are using IE.
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-IE browser.
xmlhttp = false;
}
}
//If we are using a non-IE browser, create a javascript instance of the object.
if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
xmlhttp = new XMLHttpRequest();
}

// opacity
function fade(id, opacStart, opacEnd, millisec, show) {
    	var speed = Math.round(millisec / 100);
    	var timer = 0;
    if(opacStart > opacEnd) {
        for(i = opacStart; i >= opacEnd; i--) {
            setTimeout("changeOpac(" + i + ",'" + id + "','" + show + "')",(timer * speed));
            timer++;
        }
    } else if(opacStart < opacEnd) {
        for(i = opacStart; i <= opacEnd; i++)
            {
            setTimeout("changeOpac(" + i + ",'" + id + "','" + show + "')",(timer * speed));
            timer++;
        }
    }
}
function changeOpac(opacity, id, show) {
    var object = document.getElementById(id);
    object.style.opacity = (opacity / 100);
    object.style.MozOpacity = (opacity / 100);
    object.style.KhtmlOpacity = (opacity / 100);

	object.style.filter = 'alpha(opacity=' + opacity + ')';

	if ((show=='login') && (opacity==0)) {
		var xmlhttp = false;
		//Check if we are using IE.
		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-IE browser.
		xmlhttp = false;
		}
		}
		//If we are using a non-IE browser, create a javascript instance of the object.
		if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
		xmlhttp = new XMLHttpRequest();
		}
		var serverPage = "login.php?op=showlogin";
		xmlhttp.open("GET", serverPage);
		xmlhttp.onreadystatechange = function() {
			if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
				object.innerHTML = xmlhttp.responseText;
				fade(id, 1, 100, 500);
			}
		}
		xmlhttp.send(null);
	}
	if ((show=='button') && (opacity==0)) {
		var xmlhttp = false;
		//Check if we are using IE.
		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-IE browser.
		xmlhttp = false;
		}
		}
		//If we are using a non-IE browser, create a javascript instance of the object.
		if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
		xmlhttp = new XMLHttpRequest();
		}
		var serverPage = "login.php?op=showbutton";
		xmlhttp.open("GET", serverPage);
		xmlhttp.onreadystatechange = function() {
			if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
				object.innerHTML = xmlhttp.responseText;
				fade(id, 1, 100, 500);
			}
		}
		xmlhttp.send(null);
	}
}
//********

// login
function loginShow() {
	fade('login', 100, 0, 500, 'login');
}
function loginCancel() {
	fade('login', 100, 0, 500, 'button');
}
function login() {
	var remember = document.getElementById("remember");
	var username = document.getElementById("txtUsername");
	var password = document.getElementById("txtPassword");
	
	var content = document.getElementById("login");
	var serverPage = "login.php?op=login&remember="+remember.checked+"&username="+username.value+"&password="+password.value;

	content.innerHTML = "<img src='images/progress.gif' />";
	xmlhttp.open("GET", serverPage);
	xmlhttp.onreadystatechange = function() {
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
			if (xmlhttp.responseText=="ok-1") {
				window.location = "account.php?op=1&do=bids";
			} else if(xmlhttp.responseText=="ok-2") {
				window.location = "detail_search.php";
			} else {
				content.innerHTML = xmlhttp.responseText;
			}
		}
	}
	xmlhttp.send(null);
	scroll(0,0)
}
function initUser() {
	var content = document.getElementById("login");
	var serverPage = "login.php?op=init";

	content.innerHTML = "<img src='images/progress.gif' />";
	xmlhttp.open("GET", serverPage);
	xmlhttp.onreadystatechange = function() {
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
			if (xmlhttp.responseText=="nok") {
				loginCancel();
			} else {
				content.innerHTML = xmlhttp.responseText;
			}
			getMenu();
		}
	}
	xmlhttp.send(null);
	scroll(0,0)
}
function logoutUser() {
	var content = document.getElementById("login");
	var serverPage = "login.php?op=logout";

	content.innerHTML = "<img src='images/progress.gif' />";
	xmlhttp.open("GET", serverPage);
	xmlhttp.onreadystatechange = function() {
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
			window.location = "index.php";
		}
	}
	xmlhttp.send(null);
	scroll(0,0)
}

function losePassword(op) {
	var content = document.getElementById("login");
	if (op=="field") {
		var serverPage = "login.php?op=showlosepass";
		xmlhttp.open("GET", serverPage);
		xmlhttp.onreadystatechange = function() {
			if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
				content.innerHTML = xmlhttp.responseText;
			}
		}
		xmlhttp.send(null);
	}
	if (op=="new") {
		var email = document.getElementById("txtEmail");
		var serverPage = "login.php?op=losepass&email="+email.value;
		content.innerHTML = "<img src='images/progress.gif' />";
		xmlhttp.open("GET", serverPage);
		xmlhttp.onreadystatechange = function() {
			if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
				content.innerHTML = xmlhttp.responseText;
			}
		}
		xmlhttp.send(null);
		scroll(0,0)
	}
}
//***********
