var detect = navigator.userAgent.toLowerCase();
var registerheight,loginheight,forgotheight;
var OS,browser,version,total,thestring;
if (checkIt('safari')) {
if (detect.indexOf("version/3") == -1) {
	document.write('<link href="altcss/safari.css" rel="stylesheet" type="text/css">');
	registerheight = 280;
	loginheight = 90;
	forgotheight = 68;
}
} else {
	registerheight = 270;
	loginheight = 90;
	forgotheight = 68;}
function checkIt(string)
{
	place = detect.indexOf(string) + 1;
	thestring = string;
	return place;
}

var timerlen = 5;
var slideAniLen = 350;
var timerID = new Array();
var startTime = new Array();
var obj = new Array();
var endHeight = new Array();
var moving = new Array();
var dir = new Array();
var startHeight = new Array();
function slidedown(objname,theend,toload){
moving[objname] = true;
startHeight[objname] = document.getElementById(objname).offsetHeight;
//alert (startHeight[objname] +" == "+ theend);
if (startHeight[objname] == theend) { }
else if (startHeight[objname] > theend) {
dir[objname] = "up";
}
else if (startHeight[objname] < theend) {
dir[objname] = "down";
}

startslide(objname,theend,toload);
}
function startslide(objname,thebit,toload){
obj[objname] = document.getElementById(objname);
endHeight[objname] = thebit;
startTime[objname] = (new Date()).getTime();
timerID[objname] = setInterval('slidetick(\'' + objname + '\',\'' + toload + '\');',timerlen);
}
function slidetick(objname,toload){
var elapsed = (new Date()).getTime() - startTime[objname];
if (elapsed > slideAniLen){
endSlide(objname)
if (document.getElementById(toload)) {
document.getElementById(toload).style.display="block";
}
}else {
if(dir[objname] == "up") {
var d =Math.round((elapsed / slideAniLen * (endHeight[objname]-startHeight[objname]))+startHeight[objname]);
} else {
var d =Math.round((elapsed / slideAniLen * (endHeight[objname]-startHeight[objname]))+startHeight[objname]);
}
obj[objname].style.height = d + "px";
}
return;
}
function endSlide(objname){
clearInterval(timerID[objname]);
obj[objname].style.height = endHeight[objname] + "px";
delete(moving[objname]);
delete(timerID[objname]);
delete(startTime[objname]);
delete(endHeight[objname]);
delete(obj[objname]);
delete(dir[objname]);
return;
}

function startpage2(section) {
	if (section == "login") {
	document.getElementById("templogin").style.display = "block";
	document.getElementById("registerform").style.backgroundImage = "url(image/form-top-login.png)";
	document.getElementById("submitlink").innerHTML = '<a href="javascript:;" onClick="gologin()"><img src="image/submit.gif" width="150" height="21" style="float:right; margin-top:10px; margin-right:35px;" border="0"></a>';
	document.getElementById("registerform").style.height="90px";
	document.getElementById("loginlink").innerHTML = '<table width="100%" border="0" cellspacing="3" cellpadding="5"><tr><td width="50%"><strong>Not got a login?</strong><br>Signing up for Scotimage is fast and free.<br><strong><a href="javascript:;" onClick="toregister()">Click here to register</a></strong> </td><td width="50%"><strong>Forgotten your Password?</strong><br>If you can\'t remember your Scotimage password,<br><a href="javascript:;" onClick="toforgot()"><strong>Click here to retrieve it</strong></a></td></tr></table>';
	document.getElementById("leftcontent").innerHTML = '<h1><strong>Login</strong></h1><p>Login to  your Scotimage account by filling in your email address and password in the  Login form to the right</p><p> If you have  forgotten your password, or have yet to register for a Scotimage account,  follow the links underneath the Login Form to navigate to the correct page.</p>';
} else if (section == "register") {
	document.getElementById("tempregister").style.display = "block";
	document.getElementById("registerform").style.backgroundImage = "url(image/form-top-reg.png)";
	document.getElementById("submitlink").innerHTML = '<a href="javascript:;" onClick="goregister()"><img src="image/submit.gif" width="150" height="21" style="float:right; margin-top:10px; margin-right:35px;" border="0"></a>';
	document.getElementById("registerform").style.height="270px";
	document.getElementById("loginlink").innerHTML = '<table width="100%" border="0" cellspacing="3" cellpadding="5"><tr><td width="50%"><strong>Already signed up?</strong><br>If you already have an account with Scotimage<br><strong><a href="javascript:;" onClick="tologin()">Click here to login</a></strong> </td><td width="50%"><strong>Forgotten your Password?</strong><br>If you can\'t remember your Scotimage password,<br><a href="javascript:;" onClick="toforgot()"><strong>Click here to retrieve it</strong></a></td></tr></table>';
	document.getElementById("leftcontent").innerHTML = '<h1><strong>Editor Registration</strong></h1><p>        Scotimage  accounts are available to professional users only. Accounts will not be opened  for private individuals, and password details will not be sent to private email  addresses, under any circumstances.</p><p> The content  of the Scotimage database is visible without visitors having to log in,  although should you wish to view larger versions of the images, or download  images, you require a username and password.</p><p> It is  important that you do not give your Scotimage account password information to a  third party, or permit anyone else to use it.&nbsp;  A strict record of every image download is kept and logged for each  account.<br>To register  for a Scotimage Account, please complete the form on the right. </p><p> Alternatively,  email your details to <a href="mailto:register@scotimage.com">register@scotimage.com</a> <br>As soon as  you use your password to log onto the scotimage.com website, you are deemed  to have accepted the Scotimage Terms and Conditions. </p><p><strong>Scotimage will not share your personal  details with a third party, for any purpose.</strong></p><h2>Photographer Registration</h2><p>If you are a photographer and you wish to use Scotimage to submit your photos for newspaper consideration, please contact us at <a href="mailto:photographer@scotimage.com">photographer@scotimage.com</a> or 0131 208 00 31.</p>';
} else 	if (section == "signedin") {
	document.getElementById("registerform").style.backgroundImage = "url(image/form-top-login.png)";
	document.getElementById("submitlink").innerHTML = '';
	document.getElementById("registerform").style.height="90px";
	document.getElementById("registerform").innerHTML = "<p>&nbsp;</p><table width=\"80%\" border=\"0\" align=\"center\" cellpadding=\"3\" cellspacing=\"3\"><td > You are already logged in.</td></table>";
	document.getElementById("loginlink").innerHTML = '';
	document.getElementById("leftcontent").innerHTML = '<h1><strong>Login</strong></h1><p>Login to  your Scotimage account by filling in your email address and password in the  Login form to the right</p><p> If you have  forgotten your password, or have yet to register for a Scotimage account,  follow the links underneath the Login Form to navigate to the correct page.</p>';
} else {
	document.getElementById("tempforgot").style.display = "block";
	document.getElementById("registerform").style.backgroundImage = "url(image/form-top-forgot.png)";
	document.getElementById("submitlink").innerHTML = '<a href="javascript:;" onClick="goforgot()"><img src="image/submit.gif" width="150" height="21" style="float:right; margin-top:10px; margin-right:35px;" border="0"></a>';
	document.getElementById("registerform").style.height="68px";
	document.getElementById("loginlink").innerHTML = '<table width="100%" border="0" cellspacing="3" cellpadding="5"><tr><td width="50%"><strong>Not got a login?</strong><br>Signing up for Scotimage is fast and free.<br><strong><a href="javascript:;" onClick="toregister()">Click here to register</a></strong> </td><td width="50%"><strong>Already signed up?</strong><br>If you already have an account with Scotimage<br><strong><a href="javascript:;" onClick="tologin()">Click here to login</a></strong> </td></tr></table>';
	document.getElementById("leftcontent").innerHTML = '<h1><strong>Forgotten Password</strong></h1><p>If you  require a password reminder, please complete the form on the right, using your  registered email address. Your password will immediately be sent to your email  inbox. </p>';
}}
function tologin() {
	document.getElementById("tempregister").style.display = "none";
	document.getElementById("tempforgot").style.display = "none";
	document.getElementById("registerform").style.backgroundImage = "url(image/form-top-login.png)";
	document.getElementById("submitlink").innerHTML = '<a href="javascript:;" onClick="gologin()"><img src="image/submit.gif" width="150" height="21" style="float:right; margin-top:10px; margin-right:35px;" border="0"></a>';
	slidedown("registerform",loginheight,"templogin");
	document.getElementById("loginlink").innerHTML = '<table width="100%" border="0" cellspacing="3" cellpadding="5"><tr><td width="50%"><strong>Not got a login?</strong><br>Signing up for Scotimage is fast and free.<br><strong><a href="javascript:;" onClick="toregister()">Click here to register</a></strong> </td><td width="50%"><strong>Forgotten your Password?</strong><br>If you can\'t remember your Scotimage password,<br><a href="javascript:;" onClick="toforgot()"><strong>Click here to retrieve it</strong></a></td></tr></table>';
	document.getElementById("leftcontent").innerHTML = '<h1><strong>Login</strong></h1><p>Login to  your Scotimage account by filling in your email address and password in the  Login form to the right</p><p> If you have  forgotten your password, or have yet to register for a Scotimage account,  follow the links underneath the Login Form to navigate to the correct page.</p>';
}
function toregister() {
	document.getElementById("templogin").style.display = "none";
	document.getElementById("tempforgot").style.display = "none";
	document.getElementById("registerform").style.backgroundImage = "url(image/form-top-reg.png)";
	document.getElementById("submitlink").innerHTML = '<a href="javascript:;" onClick="goregister()"><img src="image/submit.gif" width="150" height="21" style="float:right; margin-top:10px; margin-right:35px;" border="0"></a>';
	slidedown("registerform",registerheight,"tempregister");
	document.getElementById("loginlink").innerHTML = '<table width="100%" border="0" cellspacing="3" cellpadding="5"><tr><td width="50%"><strong>Already signed up?</strong><br>If you already have an account with Scotimage<br><strong><a href="javascript:;" onClick="tologin()">Click here to login</a></strong> </td><td width="50%"><strong>Forgotten your Password?</strong><br>If you can\'t remember your Scotimage password,<br><a href="javascript:;" onClick="toforgot()"><strong>Click here to retrieve it</strong></a></td></tr></table>';
	document.getElementById("leftcontent").innerHTML = '<h1><strong>Editor Registration</strong></h1><p>        Scotimage  accounts are available to professional users only. Accounts will not be opened  for private individuals, and password details will not be sent to private email  addresses, under any circumstances.</p><p> The content  of the Scotimage database is visible without visitors having to log in,  although should you wish to view larger versions of the images, or download  images, you require a username and password.</p><p> It is  important that you do not give your Scotimage account password information to a  third party, or permit anyone else to use it.&nbsp;  A strict record of every image download is kept and logged for each  account.<br>To register  for a Scotimage Account, please complete the form on the right. </p><p> Alternatively,  email your details to <a href="mailto:register@scotimage.com">register@scotimage.com</a> <br>As soon as  you use your password to log onto the scotimage.com website, you are deemed  to have accepted the Scotimage Terms and Conditions. </p><p><strong>Scotimage will not share your personal  details with a third party, for any purpose.</strong></p><h2>Photographer Registration</h2><p>If you are a photographer and you wish to use Scotimage to submit your photos for newspaper consideration, please contact us at <a href="mailto:photographer@scotimage.com">photographer@scotimage.com</a> or 0131 208 00 31.</p>';
}
function toforgot() {
	document.getElementById("tempregister").style.display = "none";
	document.getElementById("templogin").style.display = "none";
	document.getElementById("registerform").style.backgroundImage = "url(image/form-top-forgot.png)";
	document.getElementById("submitlink").innerHTML = '<a href="javascript:;" onClick="goforgot()"><img src="image/submit.gif" width="150" height="21" style="float:right; margin-top:10px; margin-right:35px;" border="0"></a>';
	slidedown("registerform",forgotheight,"tempforgot");
	document.getElementById("loginlink").innerHTML = '<table width="100%" border="0" cellspacing="3" cellpadding="5"><tr><td width="50%"><strong>Not got a login?</strong><br>Signing up for Scotimage is fast and free.<br><strong><a href="javascript:;" onClick="toregister()">Click here to register</a></strong> </td><td width="50%"><strong>Already signed up?</strong><br>If you already have an account with Scotimage<br><strong><a href="javascript:;" onClick="tologin()">Click here to login</a></strong> </td></tr></table>';
	document.getElementById("leftcontent").innerHTML = '<h1><strong>Forgotten Password</strong></h1><p>If you  require a password reminder, please complete the form on the right, using your  registered email address. Your password will immediately be sent to your email  inbox. </p>';
}
var verifyReQ = getXmlHttpRequestObject();
var regReQ = getXmlHttpRequestObject();
var logReQ = getXmlHttpRequestObject();
var forReQ = getXmlHttpRequestObject();
function getXmlHttpRequestObject() {
	if (window.XMLHttpRequest) {
		return new XMLHttpRequest();
	} else if(window.ActiveXObject) {
		return new ActiveXObject("Microsoft.XMLHTTP");
	} 
}
function refreshcode(type,bit) {
	if (verifyReQ.readyState == 4 || verifyReQ.readyState == 0) {
		day = new Date();
		id = day.getTime();
		verifyReQ.open("GET", 'includes/new-verify.php', true);
		verifyReQ.onreadystatechange = refrehcode2; 
		verifyReQ.send(null);
	}			
}
function refrehcode2 () {
	  if (verifyReQ.readyState == 4) {
		  image = "ca2.jpg";
		  tmp = new Date(); 
		  tmp = "?"+tmp.getTime();
		  document.getElementById("verify").src = image+tmp;
		  adDelay();
      } 
}
function goregister() {
	if (regReQ.readyState == 4 || regReQ.readyState == 0) {
		day = new Date();
		id = day.getTime();
		if (document.getElementById("siterms").checked) {
			var terms = 1;
		} else {
			var terms = "";
		}
		document.getElementById("uplink6").style.display = "none";	
		document.getElementById("uplink7").style.display = "none";	
		document.getElementById("uplink8").style.display = "none";	
		document.getElementById("uplink9").style.display = "none";	
		document.getElementById("uplink10").style.display = "none";	
		document.getElementById("uplink11").style.display = "none";	
		var siname = document.getElementById("siname").value;
		var siemail = document.getElementById("siemail").value;
		var siconfirm = document.getElementById("sicemail").value;
		var sipublication = document.getElementById("sipublication").value;
		var sitel = document.getElementById("sitel").value;
		var sicode = document.getElementById("code").value;
		regReQ.open("GET", 'includes/register.php?name='+siname+'&email='+siemail+'&confirm='+siconfirm+'&publication='+sipublication+'&tel='+sitel+'&code='+sicode+'&siterms='+terms+'&time='+id, true);
		regReQ.onreadystatechange = goregister2; 
		regReQ.send(null);
	}			
}
function goregister2 () {
	  if (regReQ.readyState == 4) {
		 if (regReQ.responseText) {
			// alert(regReQ.responseText);
			 var x;
			 var bits = regReQ.responseText.split("|^|");
			 var subbit;
			 for (x in bits) {
				 subbit = bits[x].split("|*|");
				 if (subbit[1] && subbit[1] == "1") {
					 document.getElementById("uplink"+subbit[0]).style.display = "inline";
				 } else if (subbit[1] && subbit[1] != "1") {
					 document.getElementById("subupinfo"+subbit[0]).innerHTML = subbit[1];
					 document.getElementById("uplink"+subbit[0]).style.display = "inline";
				 } else {
				 	document.getElementById("uplink"+subbit[0]).style.display = "none";
				 }
			 }
		 } else {
	document.getElementById("templogin").style.display = "none";
	document.getElementById("tempforgot").style.display = "none";
	document.getElementById("tempregister").style.display = "none";
	document.getElementById("registerform").innerHTML = "<p>&nbsp;</p><table width=\"80%\" border=\"0\" align=\"center\" cellpadding=\"3\" cellspacing=\"3\"><td > You are now registered. This is now put to one of Scotimage's customer support team who will verify your account shortly.<br><br> Once your account has been created, you will receive an email containing your password and details of how to login.<br><br>Thank you for choosing Scotimage.</td></table>";
	document.getElementById("submitlink").innerHTML = "";
	document.getElementById("loginlink").innerHTML = "";
	slidedown("registerform",200);
		 }
      } 
}
function gologin() {
	if (logReQ.readyState == 4 || logReQ.readyState == 0) {
		day = new Date();
		id = day.getTime();
		document.getElementById("uplink12").style.display = "none";		
		document.getElementById("uplink13").style.display = "none";
		var silogin = document.getElementById("silogin").value;
		var sipass = document.getElementById("sipass").value;
		logReQ.open("GET", 'includes/login.php?pass='+sipass+'&login='+silogin+'&time='+id, true);
		logReQ.onreadystatechange = gologin2; 
		logReQ.send(null);
	}			
}
function gologin2 () {
	  if (logReQ.readyState == 4) {
		 if (logReQ.responseText) {

			 if (logReQ.responseText.indexOf("|^|") != -1) {
			 var x;
			 var bits = logReQ.responseText.split("|^|");
			 var subbit;
			 for (x in bits) {
				 subbit = bits[x].split("|*|");
				// alert (subbit[0]);
				 if (subbit[1] && subbit[1] == "1") {
					 document.getElementById("uplink"+subbit[0]).style.display = "inline";
				 } else if (subbit[1] && subbit[1] != "1") {
					 document.getElementById("subupinfo"+subbit[0]).innerHTML = subbit[1];
					 document.getElementById("uplink"+subbit[0]).style.display = "inline";
				 } else {
				 	document.getElementById("uplink"+subbit[0]).style.display = "none";
				 }
			 } 
		 } else {
				 window.location.href = logReQ.responseText;
			 }
		 }else {
	document.getElementById("templogin").style.display = "none";
	document.getElementById("tempforgot").style.display = "none";
	document.getElementById("tempregister").style.display = "none";
	document.getElementById("registerform").innerHTML = "<p>&nbsp;</p><table width=\"80%\" border=\"0\" align=\"center\" cellpadding=\"3\" cellspacing=\"3\"><td > You have logged in successfully. <br><br>You may now use the search above to search, view, add to lightbox or download photographs. Alternitivley, you can <a href=\"account.php\" style=\"font-weight:bold; color:#ffffff\">Click here to go to you account control</a></td></table>";
	document.getElementById("submitlink").innerHTML = "";
	document.getElementById("loginlink").innerHTML = "";
	slidedown("registerform",137);
		 }
      } 
}
function goforgot() {
	if (forReQ.readyState == 4 || forReQ.readyState == 0) {
		day = new Date();
		id = day.getTime();
		document.getElementById("uplink5").style.display = "none";	
		var siforgot = document.getElementById("siforgot").value;
		forReQ.open("GET", 'includes/forgot.php?login='+siforgot+'&time='+id, true);
		forReQ.onreadystatechange = goforgot2; 
		forReQ.send(null);
	}			
}
function goforgot2 () {
	  if (forReQ.readyState == 4) {
		 if (forReQ.responseText) {
			// alert(forReQ.responseText);
			 var x;
			 var bits = forReQ.responseText.split("|^|");
			 var subbit;
			 for (x in bits) {
				 subbit = bits[x].split("|*|");
				// alert (subbit[0]);
				 if (subbit[1] && subbit[1] == "1") {
					 document.getElementById("uplink"+subbit[0]).style.display = "inline";
				 } else if (subbit[1] && subbit[1] != "1") {
					 document.getElementById("subupinfo"+subbit[0]).innerHTML = subbit[1];
					 document.getElementById("uplink"+subbit[0]).style.display = "inline";
				 } else {
				 	document.getElementById("uplink"+subbit[0]).style.display = "none";
				 }
			 }
		 } else {
	document.getElementById("templogin").style.display = "none";
	document.getElementById("tempforgot").style.display = "none";
	document.getElementById("tempregister").style.display = "none";
	document.getElementById("registerform").innerHTML = "<p>&nbsp;</p><table width=\"80%\" border=\"0\" align=\"center\" cellpadding=\"3\" cellspacing=\"3\"><td > Your password has been sent to your email inbox. Please allow up to 10 minutes for it to arrive in your inbox.<br></td></table>";
	document.getElementById("submitlink").innerHTML = "";
	document.getElementById("loginlink").innerHTML = "";
	slidedown("registerform",90);
		 }
      } 
}
function window_onblur() {
	intWindow = window.setInterval("closeme()", 1000)
}

function window_onfocus() {
	self.focus();
}

function closeme()
{
	window.clearInterval(intWindow)
	window.close();
}