var w;

function bringToFront() {
	w.focus();
}

function openEBayOnTop(earl, opts) {
	w = window.open(earl, "_blank", opts);
	setTimeout('bringToFront()', 1000);
}

function clickRover(itemID, iSource) {
	try {
		pageTracker._trackPageview("/redir/" + itemID);

		openEBayOnTop(
				"/redir?s=" + iSource + "&q=" + itemID,
				"status=0,toolbar=0,location=0,menubar=0,directories=0,scrollbars=1,scrollbars=yes,resizable=yes,resizable=1");
	} catch (err) {
		alert(err.description);
	}
}

function emailcheck(str) {

	var at = "@";
	var dot = ".";
	var lat = str.indexOf(at);
	var lstr = str.length;
	var ldot = str.indexOf(dot);
	if (str.indexOf(at) == -1) {
		alert("Invalid E-mail ID");
		return false;
	}

	if (str.indexOf(at) == -1 || str.indexOf(at) == 0
			|| str.indexOf(at) == lstr) {
		alert("Invalid E-mail ID");
		return false;
	}

	if (str.indexOf(dot) == -1 || str.indexOf(dot) == 0
			|| str.indexOf(dot) == lstr) {
		alert("Invalid E-mail ID")
		return false
	}

	if (str.indexOf(at, (lat + 1)) != -1) {
		alert("Invalid E-mail ID");
		return false;
	}

	if (str.substring(lat - 1, lat) == dot
			|| str.substring(lat + 1, lat + 2) == dot) {
		alert("Invalid E-mail ID");
		return false;
	}

	if (str.indexOf(dot, (lat + 2)) == -1) {
		alert("Invalid E-mail ID");
		return false;
	}

	if (str.indexOf(" ") != -1) {
		alert("Invalid E-mail ID");
		return false;
	}
	return true;
}

var http = new ActiveXObject("Msxml2.XMLHTTP");

function isValidReferEmail(emailID) {
	if ((emailID.value == null) || (emailID.value == "")) {
		alert("Please Enter your Email Address");
		emailID.focus();
		return false;
	}
	htmlCode = getUrl('/OctazenEmailValidation?email=' + emailID.value);
	alert(htmlCode);

}

function getUrl(url) {
	http.open("GET", url, false);
	http.send();
	return http.responseText;
}

function ValidateEmail(emailID) {

	if ((emailID.value == null) || (emailID.value == "")) {
		alert("Please Enter your Email Address");
		emailID.focus();
		return false;
	}
	if (emailcheck(emailID.value) == false) {
		emailID.value = "";
		emailID.focus();
		return false;
	}
	return true;
}

function ValidateOctEmail(emailID, pass) {
	if ((emailID.value == null) || (emailID.value == "")) {
		alert("Please Enter your Email Address");
		emailID.focus();
		return false;
	}
	if (emailcheck(emailID.value) == false) {
		emailID.value = "";
		emailID.focus();
		return false;
	}
	if (getUrl('/OctazenEmailValidation?email=' + emailID.value) != "Valid Email") {
		alert("Please Enter a valid Email Address");
		emailID.focus();
		return false;
	}
	if (getUrl('/OctazenEmailValidation?email=' + emailID.value + '&password='
			+ pass.value) != "Valid Email") {
		alert("Bad email password combination");
		pass.value = "";
		pass.focus();
		return false;
	}
	return true;
}

function sellerSearchSubmit(theForm) {
	theForm.action = "/sellermarketsheet/" + escape(theForm.sellername.value);
	return true;

}