function replace_html(id, content) {
			document.getElementById(id).innerHTML = content;
		}
function show_progressbar(id) {
			replace_html(id, '<img src="images/loading.gif" border="0" alt="Loading, please wait..." />');
		}
		
		
function Set_Cookie( name, value, expires, path, domain, secure ) {
	// set time, it's in milliseconds
	var today = new Date();
	today.setTime( today.getTime() );
	// if the expires variable is set, make the correct expires time, the
	// current script below will set it for x number of days, to make it
	// for hours, delete * 24, for minutes, delete * 60 * 24
	if ( expires )
	{
		expires = expires * 1000 * 60 * 60 * 24;
	}
	//alert( 'today ' + today.toGMTString() );// this is for testing purpose only
	var expires_date = new Date( today.getTime() + (expires) );
	//alert('expires ' + expires_date.toGMTString());// this is for testing purposes only

	document.cookie = name + "=" +escape( value ) +
		( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + //expires.toGMTString()
		( ( path ) ? ";path=" + path : "" ) + 
		( ( domain ) ? ";domain=" + domain : "" ) +
		( ( secure ) ? ";secure" : "" );
}


function Delete_Cookie( name, path, domain ) {
	if ( Get_Cookie( name ) ) document.cookie = name + "=" +
			( ( path ) ? ";path=" + path : "") +
			( ( domain ) ? ";domain=" + domain : "" ) +
			";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}

/* Below is a function that will break the query string into pieces for you*/
function querySt(ji) {
hu = window.location.search.substring(1);
gy = hu.split("&");
for (i=0;i<gy.length;i++) {
ft = gy[i].split("=");
if (ft[0] == ji) {
return ft[1];
}
}
}


function emailGenerator() {
	var name = $("#fullname").val();
	var det = $("#detail").val();
	var email = $("#emailaddress").val();
	var phone = $("#telnumber").val();
	var selectedpref = $("#preffered").val();
	
    if (name == "") {
		alert("Please enter your name");
		return;}
	if (email.length == 0 && phone.length == 0) {
		alert("Please enter your email address and/or a phone number");
		return;	}
	name = '&name='+name;
	ddet= '&detail='+det;
	email = '&email='+email;
	phone = '&phone='+phone;
	preffer = '&preffer='+selectedpref;
var request = 'emailer.asp?submit=true'+name+ddet+email+phone+preffer;
	new Ajax.Request(request, {
	  onSuccess: function(transport) {
		  alert("Thank you " + $("#fullname").val() + ", your Request has been successfully Sent!");
	  },
	  onFailure: function(transport) {
		  alert("Sorry. Your Request could not be Send right now, please try again in a few seconds");
	  }
	});
}

function loginer() {
	
	var sPath = window.location.pathname;
//var sPage = sPath.substring(sPath.lastIndexOf('\\') + 1);
var thispage = sPath.substring(sPath.lastIndexOf('/') + 1);
	var name = $("#username").val();
	var passer = $("#passer").val();
	var therem=0;
	if ($("#rememberme").attr('checked') == true){
	   therem=1;
	}
    if (name == "") {
		alert("Please enter your User Name");
		return;}
	if (passer == "") {
		alert("Please enter your Password");
		return;	}
	//show_progressbar('loadingshower');
	name = '&username='+name;
	thepass= '&passer='+passer;
	therem='&rememberme='+therem
	
var request = 'loginer.asp?submit=true'+name+thepass+therem;

	//new Ajax.Request(request, {
	//  onSuccess: function(transport) {
	//	  var response = transport.responseText ;
    //      $("#screenname").text(response);
	//	  $("#username").val("");
	//	  $("#passer").val("");
	//	  showaccount();
	//	  alert("Hello, you logged in successfully");
	//	  //location.href  = thispage;
	//      //location.reload(true);
	//  },
	//  onFailure: function(transport) {
	//	  hideaccount();
	//	  alert("Email address and Password is not exist Or may not activated yet");
	//  }
	//}); 
location.href  = request;	
     
}
function logouter() {
	var request = 'logout2.asp';
	new Ajax.Request(request, {
	  onSuccess: function(transport) {
		   hideaccount();
		   alert("You logged out successfully");
	  },
	  onFailure: function(transport) {
		   showaccount();
		  alert("Sorry. You cannot logged out, please try again in a few seconds");
	  }
	});
}

function cookieschecker(boxname) {
cookie_set = false;
 if (boxname.checked == true) {
       document.cookie = "test=0" ;
	   a_all =  document.cookie.split( ';' );
	   
	   for ( k = 0; k < a_all.length; k++ )
		{
			a_all_cookies =  a_all[k].split( '=' );
			
			for ( i = 0; i < a_all_cookies.length; i++ )
			 {
				cookie_name = a_all_cookies[i].split( '=' );
				alert(typeof cookie_name);
				var isthere=cookie_name.IndexOf("test");
			    
				if ( isthere >= 0 )
					{
						cookie_set = true;
						break ;
					}
			 }
			if (cookie_set == true) break;
		}
		
		if (cookie_set==false)
		   {
		   alert("Please Enable Cookies");
		   boxname.checked = false;
		   }
		
}		
}


function showaccount()
{
 $("#logintable").addClass("hiddenrow");
  $("#rememberme").addClass("hiddenrow");
 $("#logouttable").removeClass("hiddenrow");
 $("#account").removeClass("hiddenrow");
}
function hideaccount()
{
  $("#logintable").removeClass("hiddenrow");
   $("#rememberme").removeClass("hiddenrow");
 $("#logouttable").addClass("hiddenrow");
 $("#account").addClass("hiddenrow");
}

/****************************************************
  http://www.codetoad.com/javascript/isnumeric.asp
                IsPhone
  The function check if the Tel entered in a tel field are numeric by loop through the string and compare each character to a pre-defined list of acceptable range. 
  *****************************************************/
  function IsPhone(sText)
{
   var theValidChars = "0123456789-";
   var  IsPhone=true;
   var theChar;
  for (i = 0; i < sText.length && IsPhone == true; i++) 
      { 
      theChar = sText.charAt(i); 
      if (theValidChars.indexOf(theChar) == -1) 
         {
          IsPhone = false;
         }
      }
   return  IsPhone;
   
   }
/****************************************************
http://www.developertutorials.com/tutorials/javascript/javascript-lower-case-upper-case-051019/page1.html
http://homepage.ntlworld.com/kayseycarvey/jss3p8.html
                IsEmail
  The function check if the Email entered in an Email field is valid by loop through the string and compare each character to a   pre-defined list of acceptable characters. 
  also check wether sequence of "@" and "." is acceptable
  *****************************************************/
  function IsEmail(sText)
{
   var theValidChars = "abcdefghijklmnopqrstuvwxyz123456789@._-";
   var IsEmail=true;
   var theChar;
   //change to lowercase
   sText=sText.toLowerCase(); 
   
   AtPos = sText.indexOf("@");
   
   secondPos=sText.lastIndexOf("@");
   StopPos = sText.lastIndexOf(".");
  
   for (i = 0; i < sText.length && IsEmail == true; i++) 
      { 
      theChar = sText.charAt(i); 
      if (theValidChars.indexOf(theChar) == -1) 
         {
         IsEmail = false;
         }
      }
	  
	 
	//check if email is not empty
	if (sText == "") {IsEmail = false}
    //for check if "@" and "." both are include at email add
	if (AtPos == -1 || StopPos == -1) {IsEmail = false}
	//for check if "@" is before any "."
	if (StopPos < AtPos) {IsEmail = false}
	 //for check if "." is not attached to "@"
    if (StopPos - AtPos == 1) {IsEmail = false}
	 //for check only one "@" is the email address
    if (secondPos != AtPos) {IsEmail = false} 
   
   return IsEmail;
   
 
 
 }
