﻿function changeImage(ImageName,SenderObj) {
newImage = "url(" + ImageName + ")";
SenderObj.style.backgroundImage = newImage;
}
        
Image111= new Image(127,17);
Image111.src = "../images/rejectinput.gif";

Image122 = new Image(127,17);
Image122.src = "../images/acceptinput.gif";

Image133 = new Image(127,17);
Image133.src = "images/pendinginput.gif";

var TimerIsOn=0;
var TimeoutID;

var TimeToFade = 1000.0;

function RegCloseform(targetframe)
{
var element = document.getElementById(targetframe)
element.innerHTML = '';
}

function URLEncode(ObjValue)
{
	// The Javascript escape and unescape functions do not correspond
	// with what browsers actually do...
	var SAFECHARS = "0123456789" +					// Numeric
					"ABCDEFGHIJKLMNOPQRSTUVWXYZ" +	// Alphabetic
					"abcdefghijklmnopqrstuvwxyz" +
					"-_.!~*'()";					// RFC2396 Mark characters
	var HEX = "0123456789ABCDEF";

	var plaintext = ObjValue;
	var encoded = "";
	for (var i = 0; i < plaintext.length; i++ ) {
		var ch = plaintext.charAt(i);
	    if (ch == " ") {
		    encoded += "+";				// x-www-urlencoded, rather than %20
		} else if (SAFECHARS.indexOf(ch) != -1) {
		    encoded += ch;
		} else {
		    var charCode = ch.charCodeAt(0);
			if (charCode > 255) 
			{
				encoded += encodeURI(ch);
			} 
			else {
				encoded += "%";
				encoded += HEX.charAt((charCode >> 4) & 0xF);
				encoded += HEX.charAt(charCode & 0xF);
			}
		}
	} 

	return encoded;
}

function GetXmlHttpObject()
{
if(TimerIsOn==1)
{
	clearTimeout(TimeoutID);
	TimeoutID = setTimeout("SessionExpireSoon()",1140000);
}
var xmlHttp=null;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
return xmlHttp;
}

function isLengthOK(StandardObj,NeededLength)
{
	str = StandardObj.value;
   if((str.length >= NeededLength))
   {
   StandardObj.className='accept';
   return true;
   }
   else
   {
   StandardObj.className='reject';
   return false;
   }


}

function checkNumber(val) {
  var strPass = val.value;
  var strLength = strPass.length;
  var lchar = val.value.charAt((strLength) - 1);
  var cCode = CalcKeyCode(lchar);

  /* Check if the keyed in character is a number
     do you want alphabetic UPPERCASE only ?
     or lower case only just check their respective
     codes and replace the 48 and 57 */

  if (cCode < 40 || cCode > 57 ) {
    var myNumber = val.value.substring(0, (strLength) - 1);
    val.value = myNumber;
  }
  return false;
}

function CalcKeyCode(aChar) {
  var character = aChar.substring(0,1);
  var code = aChar.charCodeAt(0);
  return code;
}


function checkStandardLetters(val) {
  var strPass = val.value;
  var strLength = strPass.length;
  var lchar = val.value.charAt((strLength) - 1);
  var cCode = CalcKeyCode(lchar);

  if ((cCode < 48 && cCode!=45) || (cCode > 57 && cCode < 65) || (cCode>90 && cCode!=95 && cCode < 97) || ( cCode > 122)) {
    var myNumber = val.value.substring(0, (strLength) - 1);
    val.value = myNumber;
  }
  
  return false;
}


function GetWidth() {
  var myWidth = 0
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
  } else if( document.documentElement && ( document.documentElement.clientWidth) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
  } else if( document.body && ( document.body.clientWidth ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
  }
  return myWidth;
}

function GetHeight() {
  var myHeight = 0;
  if( typeof( window.innerHeight) == 'number' ) {
    //Non-IE
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientHeight ) ) {
    //IE 4 compatible

    myHeight = document.body.clientHeight;
  }

  return myHeight;
}











function Sessionreconnect()
{
	var CurrSessionUser = document.getElementById("SessionEmail").value;
	var CurrSessionPass = document.getElementById("SessionPass").value;
	
	if(CurrSessionUser=="")
	{
		alert("You must enter Email");
		return false
	
	
	}
	if(CurrSessionPass=="")
	{
		alert("You must enter password");
		return false
	
	}
	
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	  {
	  alert ("Your browser does not support AJAX!");
	  return;
	 } 
	var url="../affiliates/reconnect.asp";
	url=url+"?pass="+ URLEncode(CurrSessionPass)+ "&email="+CurrSessionUser+"&sid="+Math.random();
	xmlHttp.onreadystatechange=SessionReConnect;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
	

}

function RefreshSession() 
{

	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	  {
	  alert ("Your browser does not support AJAX!");
	  return;
	 } 
	var url="../affiliates/inactivity.asp";
	url=url+"?sid="+Math.random();
	xmlHttp.onreadystatechange=SessionRefresh;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}



function SessionRefresh() 
{ 
var Screentouse; 
	if (xmlHttp.readyState==4)
	{ 
		if(xmlHttp.responseText=="1")
		{
			document.body.removeChild(document.getElementById("SessionForm"));
			document.body.removeChild(document.getElementById("LockMode"));
		}
		else if(xmlHttp.responseText=="2")
		{
			SessionEnded();
		}
		
	}
}


function SessionReConnect() 
{ 
var Screentouse; 
	if (xmlHttp.readyState==4)
	{ 
		if(xmlHttp.responseText=="1")
		{
			document.body.removeChild(document.getElementById("SessionForm"));
			document.body.removeChild(document.getElementById("LockMode"));
			alert("You logged in successfully")
		}
		else if(xmlHttp.responseText=="4")
		{
			alert("Please activate your account by verifying your email")
			location.href='../activateaccount.asp';
			
		}
		else if(xmlHttp.responseText=="2")
		{
			alert("Password incorrect");
		}
		else if(xmlHttp.responseText=="3")
		{
			alert("Email doesn't exist, please try again");
		}
		
	}
}




function SessionEnded()
{
	document.getElementById("SessionForm").innerHTML = '<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" style=\"border-collapse: collapse\" bordercolor=\"#111111\" width=\"210\" id=\"AutoNumber2\" height=\"89\" style=\"border:1px dotted #808080; border-collapse: collapse\" bgcolor=\"#FCF8EC\">      <tr>        	 <td width=\"500\" colspan=\"4\" class=\"logindesign\" align=\"center\" style=\"height: 33px\">Due to 20 minutes of inactivity,<BR>your connection has disconnected</td>      </tr>      <tr>        <td width=\"50\" rowspan=\"4\">	 &nbsp;</td><td width=\"200\" height=\"20\" class=\"logindesign\">Email:</td><td width=\"200\" height=\"20\"><input type=\"text\" id=\"SessionEmail\" name=\"SessionEmail\" size=\"15\" class=\"VeryShortfieldsSelects\"></td><td width=\"50\" rowspan=\"4\">	 &nbsp;</td></tr><tr>		 <td width=\"200\" class=\"logindesign\" style=\"height: 30px\">Password:</td>		 <td width=\"200\" style=\"height: 20px\"><input type=\"password\" name=\"SessionPass\" id=\"SessionPass\" size=\"15\" class=\"VeryShortfieldsSelects\"></td></tr><tr><td width=\"200\" height=\"20\">	 	<input type=\"button\" name=\"Exit\" value=\"Exit\" onclick=\"location.href=\'../default.asp\'\" class=\"VeryShortfieldsSelects\" style=\"width:60px;\"></td><td width=\"200\" height=\"30\"><input type=\"button\" onclick=\"Sessionreconnect()\" name=\"Re-Login\" value=\"Re-Login\" class=\"VeryShortfieldsSelects\"></td></tr></table>'
	document.getElementById("SessionForm").style.position="absolute"
	document.getElementById("SessionForm").style.left=((GetWidth()-250)/2);
	document.getElementById("SessionForm").style.top=(((GetHeight()-200)/2)+document.body.scrollTop)-20;
	document.getElementById("SessionForm").style.zIndex=100;
	
}

function sessionExpireCounter(CurrSec)
{
	if(document.getElementById("NoOfSecs"))
	{
		document.getElementById("NoOfSecs").innerHTML = CurrSec;
		CurrSec--;
		if(CurrSec>=0)
		{
		setTimeout("sessionExpireCounter('"+ CurrSec + "')",1000);
		}
		else
		{
			SessionEnded();
		}
	}
}

function SessionExpireSoon()
{

	var NewDiv = document.createElement("div");
	NewDiv.setAttribute('id','LockMode');
	document.body.appendChild(NewDiv);
	document.getElementById("LockMode").className="SessionEnd";
	var NewDivX = document.createElement("div");
	NewDivX.setAttribute('id','SessionForm');
	NewDivX.innerHTML = '<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" style=\"border-collapse: collapse\" bordercolor=\"#111111\" width=\"410\" id=\"AutoNumber2\" height=\"89\" style=\"border:1px dotted #808080; border-collapse: collapse\" bgcolor=\"#FCF8EC\">      <tr><td class=\"logindesign\" align=\"center\">Your connection will be disconnected in <font id=\"NoOfSecs\">60</font> Seconds<BR><a href=\"javascript:void RefreshSession()\" style=\"color:blue;text-decoration:underline\">Click here to continue working</a></td></tr></table>'
	document.body.appendChild(NewDivX);
	document.getElementById("SessionForm").style.position="absolute"
	document.getElementById("SessionForm").style.left=((GetWidth()-400)/2);
	document.getElementById("SessionForm").style.top=(((GetHeight()-100)/2)+document.body.scrollTop)-20;
	document.getElementById("SessionForm").style.zIndex=100;
	sessionExpireCounter('60')

}

TimerIsOn=0;
//TimeoutID = setTimeout("SessionExpireSoon()",1140000);

