var images = new Array();

function imageLoader()
{
    images[0] = new Image();
    images[0].src = 'http://www.resales-online.com/images/bigbuttonroll.jpg';
    images[1] = new Image();
    images[1].src = 'http://www.resales-online.com/images/bigbutton.jpg';
    images[2] = new Image();
    images[2].src = 'http://www.resales-online.com/images/freetrial.jpg';
    images[3] = new Image();
    images[3].src = 'http://www.resales-online.com/images/freetrialroll.jpg';
    images[4] = new Image();
    images[4].src = 'http://www.resales-online.com/images/freetrialbutton.jpg';
    images[5] = new Image();
    images[5].src = 'http://www.resales-online.com/images/freetrialbuttonr.jpg';
    images[6] = new Image();
    images[6].src = 'http://www.resales-online.com/DEV/images/watchdemobutton.jpg';
    images[7] = new Image();
    images[7].src = 'http://www.resales-online.com/DEV/images/watchdemobuttonr.jpg';
    images[8] = new Image();
    images[8].src = 'http://www.resales-online.com/images/joinnowbutton.jpg';
    images[9] = new Image();
    images[9].src = 'http://www.resales-online.com/images/joinnowbuttonr.jpg';
	images[10] = new Image();
    images[10].src = 'http://www.resales-online.com/images/discountstag2.jpg';
    images[11] = new Image();
    images[11].src = 'http://www.resales-online.com/images/discountstag2roll.jpg';
	images[12] = new Image();
    images[12].src = 'http://www.resales-online.com/images/discountsbutton.jpg';
    images[13] = new Image();
    images[13].src = 'http://www.resales-online.com/images/discountsbuttonR.jpg';
	images[14] = new Image();
    images[14].src = 'http://www.resales-online.com/images/livechatbutton.jpg';
    images[15] = new Image();
    images[15].src = 'http://www.resales-online.com/images/livechatbuttonR.jpg';
	images[16] = new Image();
    images[16].src = 'http://www.resales-online.com/images/discountsrollR.jpg';
    images[17] = new Image();
    images[17].src = 'http://www.resales-online.com/images/discountsroll.jpg';
	images[18] = new Image();
    images[18].src = 'http://www.resales-online.com/images/livechatroll.jpg';
    images[19] = new Image();
    images[19].src = 'http://www.resales-online.com/images/livechatrollR.jpg';
	images[20] = new Image();
    images[20].src = 'images/videobutton.jpg';
    images[21] = new Image();
    images[21].src = 'images/videobuttonR.jpg';

}

function buttonOver(divId,buttonId,imageId)
{
    document.getElementById(divId).style.backgroundImage = "url(" + images[imageId].src + ")";
	if ( document.getElementById("buttonLink"+buttonId) ) document.getElementById("buttonLink"+buttonId).className = 'buttonlink texthighlight';
}

function buttonOut(divId,buttonId,imageId)
{
    document.getElementById(divId).style.backgroundImage = "url(" + images[imageId].src + ")";
	if ( document.getElementById("buttonLink"+buttonId) ) document.getElementById("buttonLink"+buttonId).className = 'buttonlink textnormal';
}

function menuOver(menuId)
{
	if ( document.getElementById(menuId) )
	{
		if ( menuId == 'option1' )
			document.getElementById(menuId).className = 'leftmenuitemtophighlight'
		else
			document.getElementById(menuId).className = 'leftmenuitemhighlight' ;
	}
}

function menuOut(menuId)
{
	if ( document.getElementById(menuId) )
	{
		if ( menuId == 'option1' )
			document.getElementById(menuId).className = 'leftmenuitemtop'
		else
			document.getElementById(menuId).className = 'leftmenuitem' ;
	}
}

function viewDemo(vidId)
{
	var x = window.open("video/resales" + vidId + ".asp", "winDemo", "left=5,top=5,width=1000,height=750,scrollbars=yes" );
}

function checkAllSpaces( strVal )
{
	var spCount = 0 ;

	for ( i = 0;  i < strVal.length;  i++ )
	{
		var ch = strVal.charAt(i);
		
        if ( ch == " ")
		{
			spCount++;
		}
	}
  
	if ( spCount == strVal.length )
	{
		return true;
	}
	else
	{
		return false;
	}
}

function checkFields()
{
	if ( document.Contact.CompanyName )
	{
		if ( checkAllSpaces( document.Contact.CompanyName.value ) == true )
		{
		  alert("Please enter your Company Name.  ")
		  document.Contact.CompanyName.focus()
		  return false
		}
	}

	if ( document.Contact.EmailAddress )
	{
		if ( checkAllSpaces( document.Contact.EmailAddress.value ) == true )
		{
		  alert("Please enter your Email Address ")
		  document.Contact.EmailAddress.focus()
		  return false
		}
	}

	if ( document.Contact.FirstName )
	{
		if ( checkAllSpaces( document.Contact.FirstName.value ) == true )
		{
		  alert("Please enter your First Name ")
		  document.Contact.FirstName.focus()
		  return false
		}
	}

	if ( document.Contact.SurName )
	{
		if ( checkAllSpaces( document.Contact.SurName.value ) == true )
		{
		  alert("Please enter your Surname ")
		  document.Contact.SurName.focus()
		  return false
		}
	}

	if ( document.Contact.PhoneNumber )
	{
		if ( checkAllSpaces( document.Contact.PhoneNumber.value ) == true )
		{
		  alert("Please enter your Phone Number")
		  document.Contact.PhoneNumber.focus()
		  return false
		}
	}

	if ( document.Contact.CompanyCif )
	{
		if ( checkAllSpaces( document.Contact.CompanyCif.value ) == true )
		{
		  alert("Please enter your Company CIF or Personal NIE Number ")
		  document.Contact.CompanyCif.focus()
		  return false
		}
	}

	return true
}

function loginButton(ROLsystem)
{
	if ( checkAllSpaces( document.Login.UserName.value ) == true )
	{
	  alert("Please enter your UserName ")
	  document.Login.UserName.focus()
	  return false
	}

	if ( checkAllSpaces( document.Login.UserPass.value ) == true )
	{
	  alert("Please enter your Password ")
	  document.Login.UserPass.focus()
	  return false
	}

	var x = document.Login.UserName.value ;
	document.Login.UserName.value = "" ;
	var y = document.Login.UserPass.value ;
	document.Login.UserPass.value = "" ;

	document.getElementById("Login").action = "http://"+ ROLsystem +"-0.resales-online.com/live/UserLoginValidate.asp?P1="+x+"&P2="+y+"&P3=0";
	document.getElementById("Login").submit();

//	document.location = "http://"+ROLsystem+"-0.resales-online.com/live/UserLoginValidate.asp?P1="+x+"&P2="+y+"&P3=0";

// The code below was the old login using popups. THis is now not used.

//	MyString = new String(x);
//	if ( MyString.indexOf(".") == -1 )
//	{
//		var newWin = window.open("http://"+ROLsystem+"-0.resales-online.com/live/UserLoginValidate.asp?P1="+x+"&P2="+y+"&P3=0", "winResalesOnline", "top=0, left=0, width=800, height=550, titlebar=no, location=0, menubar=0, status=1, resizable=1");
//	}
//	else
//	{
//		document.location = "http://"+ROLsystem+"-0.resales-online.com/live/UserLoginValidate.asp?P1="+x+"&P2="+y+"&P3=0";
//	}

}
function ChatPopup() {
	window.open( "https://hosted6.whoson.com/chat/chatstart.htm?domain=www.resales-online.com", "ChatWindow", "top=0, left=0, width=550, height=450, titlebar=no, location=0, menubar=0, status=1, resizable=1") 
}

function CheckEmailIsUnique(ROLsystem)
{
	Email = document.getElementById("EmailAddress").value ;
	if ( Email == "" )
	{
		return true;
	}
	
	var url = "ServerValidate/ValidateEmail.asp?P1=" + Email + "&P2=" + ROLsystem ;
	if ( window.XMLHttpRequest )
	{
		xmlhttp2 = new XMLHttpRequest();
		xmlhttp2.onreadystatechange = CheckResultEmail; // Must Match Function Name Below
		xmlhttp2.open("GET",url,true);
		xmlhttp2.send(null);
	}
	// code for IE
	else if ( window.ActiveXObject )
	{
		xmlhttp2 = new ActiveXObject("Microsoft.XMLHTTP");
		if (xmlhttp2)
		{
			xmlhttp2.onreadystatechange = CheckResultEmail;  // Must Match Function Name Below
			xmlhttp2.open("GET",url,true);
			xmlhttp2.send(null);
		}
	}
}


function CheckResultEmail()  // Must be referenced twice in the function above
{
	// if xmlhttp shows "loaded"
	if ( xmlhttp2.readyState == 4 )
	{
		// if "OK"
		if ( xmlhttp2.status == 200 )
		{
			var retString = xmlhttp2.responseText ;
			
			if ( retString == "1" )
			{
				// All OK. the email is unique
			}
			else
			{
				alert("This Email address is already registered. Please choose a new one");
				document.getElementById("EmailAddress").value = "";
			}
		}
		else
		{
			alert("System Error Email!");
		}
	
		xmlhttp2 = null ;
	}
}


function CheckCompanyNameIsUnique(ROLsystem)
{

	CompanyName = document.getElementById("CompanyName").value ;
	if ( CompanyName == "" )
	{
		return true;
	}
	
	var url = "ServerValidate/ValidateCompanyName.asp?P1=" + CompanyName + "&P2=" + ROLsystem ;

	if ( window.XMLHttpRequest )
	{
		xmlhttp2 = new XMLHttpRequest();
		xmlhttp2.onreadystatechange = CheckResultCompanyName; // Must Match Function Name Below
		xmlhttp2.open("GET",url,true);
		xmlhttp2.send(null);
	}
	// code for IE
	else if ( window.ActiveXObject )
	{
		xmlhttp2 = new ActiveXObject("Microsoft.XMLHTTP");
		if (xmlhttp2)
		{
			xmlhttp2.onreadystatechange = CheckResultCompanyName;  // Must Match Function Name Below
			xmlhttp2.open("GET",url,true);
			xmlhttp2.send(null);
		}
	}
}


function CheckResultCompanyName()  // Must be referenced twice in the function above
{
	// if xmlhttp shows "loaded"
	if ( xmlhttp2.readyState == 4 )
	{
		// if "OK"
		if ( xmlhttp2.status == 200 )
		{
			var retString = xmlhttp2.responseText ;
			
			if ( retString == "1" )
			{
				// All OK. the email is unique
			}
			else
			{
				alert("This Company Name is already registered. Please choose a new one");
				document.getElementById("CompanyName").value = "";
			}
		}
		else
		{
			alert("System Error CompanyName!");
		}
	
		xmlhttp2 = null ;
	}
}

var sysParam = '';

function CheckEmailExists(ROLsystem)
{
	var Email = document.getElementById("EmailAddress").value ;
	if ( Email == "" )
	{
		return true;
	}
	
	sysParam = ROLsystem;
	var d = new Date() ;
	var m = d.getTime() ;

	var url = "ServerValidate/ValidateEmail.asp?P1=" + Email + "&P2=" + ROLsystem + "&P3=" + m;

	if ( window.XMLHttpRequest )
	{
		xmlhttp2 = new XMLHttpRequest();
	}
	// code for IE
	else if ( window.ActiveXObject )
	{
		xmlhttp2 = new ActiveXObject("Microsoft.XMLHTTP");
	}

	if (xmlhttp2)
	{
		xmlhttp2.onreadystatechange = CheckResultEmail2;  // Must Match Function Name Below
		xmlhttp2.open("GET",url,true);
		xmlhttp2.send(null);
	}
}

function CheckActiveEmailExists(ROLsystem)
{
	var Email = document.getElementById("EmailAddress").value ;
	if ( Email == "" )
	{
		return true;
	}
	
	sysParam = ROLsystem;
	var d = new Date() ;
	var m = d.getTime() ;

	var url = "ServerValidate/ValidateActiveEmail.asp?P1=" + Email + "&P2=" + ROLsystem + "&P3=" + m;

	if ( window.XMLHttpRequest )
	{
		xmlhttp2 = new XMLHttpRequest();
	}
	// code for IE
	else if ( window.ActiveXObject )
	{
		xmlhttp2 = new ActiveXObject("Microsoft.XMLHTTP");
	}

	if (xmlhttp2)
	{
		xmlhttp2.onreadystatechange = CheckResultEmail2;  // Must Match Function Name Below
		xmlhttp2.open("GET",url,true);
		xmlhttp2.send(null);
	}
}


function CheckResultEmail2()
{
	// if xmlhttp shows "loaded"
	if ( xmlhttp2.readyState == 4 )
	{
		// if "OK"
		if ( xmlhttp2.status == 200 )
		{
			var retString = xmlhttp2.responseText ;
			
			if ( retString == "0" )
			{
				PasswordReminder()
			}
			else
			{
				alert("This Username / Email Address could not be found please check and try again");
				document.getElementById("EmailAddress").value = "";
			}
		}
		else
		{
			alert("System Error Email!" + xmlhttp2.statusText);
		}
	
		xmlhttp2 = null ;
	}
}

function PasswordReminder()
{
	var z = document.Reminder.EmailAddress.value ;
	document.Reminder.EmailAddress.value = "" ;
	var url = "http://"+sysParam+"-0.resales-online.com/live/resales/adminagent/SendPasswordReminder.asp?P1="+z;
	document.location = url;
}


var pollFunction ;
var pageName = "" ;
var emailId = "" ;
var pollCount = 0 ;
var httpRequestPageCookie ;

var urlWeb = "http://www.resales-online.com/UpdateLeadTrackerWeb.asp" ;

function processReturn()
{
	if ( httpRequestPageCookie.readyState == 4 )
	{
		if ( httpRequestPageCookie.status == 200 )
		{
			var retValue = parseInt(httpRequestPageCookie.responseText) ;
			if ( retValue == 1 ) alert( "Error updating database  ");
		}
		else
		{
			alert( "Error updating database \n\n" + httpRequestPageCookie.statusText );
		}

		httpRequestPageCookie = null ;
	}
}

function sendHttpRequest(httpUrl)
{
	if ( window.XMLHttpRequest )
	{
		httpRequestPageCookie = new XMLHttpRequest();
	}
	else if ( window.ActiveXObject )
	{
		httpRequestPageCookie = new ActiveXObject("Microsoft.XMLHTTP");
	}

	if ( httpRequestPageCookie )
	{
		httpRequestPageCookie.onreadystatechange = processReturn;
		httpRequestPageCookie.open("GET",httpUrl,true);
		httpRequestPageCookie.send(null);	
	}
	else
	{
		alert("ERROR");
	}
}

function startPageAction()
{
	pollFunction = setInterval("updateVideoRuntime()",10000); // every 10 seconds
}

function updateVideoRuntime()
{
	if ( pollCount == 1  ) pageName = "Video End" ;
	pollCount++ ;

	var url = urlWeb + "?Id=" + emailId + "&Page=" + pageName ;
	sendHttpRequest(url)
}

function processUserCookie(cookieId,pageId)
{
	pageName = pageId ;
	emailId = cookieId ;

	if ( pageName == "Video Begin" ) {
		startPageAction() ;
	} else {
		var url = urlWeb + "?Id=" + emailId + "&Page=" + pageName ;
		sendHttpRequest(url)
	}
}

function toggleDisplay(itemNo)
{
	document.getElementById('area'+itemNo).style.display = document.getElementById('area'+itemNo).style.display=='none' ? 'table' : 'none';
	var tempImageURL = document.getElementById('img' + itemNo).src
	var tempImagePosition = tempImageURL.indexOf("pos")
	if (tempImagePosition >= 0)
	{
		document.getElementById('img' + itemNo).src = '../../images/neg.gif';
	}
	else
	{
		document.getElementById('img' + itemNo).src = '../../images/pos.gif';
	}
}
