// JavaScript Document
var chat;
var first_name, last_name, email_addr, sel_country, msg;

function SetupChat(first, last, email, country, message) {
 

  if (ValidateFields(first, email, country, message))
  {
    first_name = first.value;
    email_addr = email.value;
    last_name = last.value;
	sel_country = country.options[country.selectedIndex].text;
    msg = message.value;
    
    chat = Wt.chat.PublicChat;
    chat.init ({
        //site: 'Test Chat', 
        //site: 'test', 
        statusCallback: testStatus,
        startOptions: {
            window: {
                top: 100,
                left: 100,
                width: 360,
                height: 500,
                cssUrl: 'http://images.revlon.com/css/chat.css',
                logoUrl: 'http://images.revlon.com/images/chatheader.jpg',
                //headerHtml: "<img src='http://revlondev.squeaky.com/images/title-chat.gif' alt='CHAT WITH US'/><br><img src='http://revlondev.squeaky.com/images/chatroom-blurb.gif' class='blurb' alt='To start a Live Chat, enter your message below and we will be happy to answer your questions.'/>",
                //footerHtml: '<b>This is the customizable footer</b>',
                title: 'Revlon Chat'
            }
        }
    });  
  }
}

function doit()
{
  chat.start({
      	initialText: 'message',
          info: {
              'Name_First': WTfname(),
              'Name_Last': WTlname(),
              'email': WTemail(),
			  'country' : WTcountry(),
              'message' : WTinittest()             
          }
  });
} 

function WTfname()
{
  return first_name;
}

function WTlname()
{
  return last_name;
}

function WTemail()
{
  return email_addr;
}

function WTcountry()
{
	return sel_country;
}

function WTinittest()
{
  return msg;
}

  
cmdChat_onClick = function () {   
    chat.start({
        info: {
            'product': 'Tester'
        }
    });
};

testStatus = function () {
    if (chat.status === 'ready') {
      doit();
    }
    else
    {
      //alert("Chat is currently " + chat.status + ".");
      if (chat.msg == null)
      {
        alert("We are very sorry but Chat is temporarily unavailable.  Please contact us later or send your comments using this form.");
      }
      else
      {
        alert(chat.msg);
      }
    }
};

function ValidateFields(first, email, country, message)
{
  var f_name, e_mail, msg;
  f_name = first.value;
  e_mail = email.value;
  msg = message.value;

  if (f_name.length > 0 && e_mail.length > 0 && msg.length > 0 && country.selectedIndex >= 0)
  {
    return true;
  }
  else
  {
    if (f_name.length == 0)
    {
      first.style.backgroundColor = "#FCC";
      first.focus();
    }
    
    if (e_mail.length == 0)
    {
      email.style.backgroundColor = "#FCC";
      if (f_name.length > 0)
      {
        email.focus();
      }
    }
    
	if (country.selectedIndex < 0){
		country.style.backgroundColor = "#FCC";
		if (f_name.length > 0)
		{
			if (e_mail.length > 0)
			{
				country.focus();
			}
		}
	}
	
    if (msg.length == 0)
    {
      message.style.backgroundColor = "#FCC";
      if (f_name.length > 0)
      {
        if (e_mail.length > 0)
        {
			if(country.selectedIndex > 0)
			{
				message.focus();
			}
        }
      }
    }
    
    alert("Please enter your first name, email, country and message before clicking 'Chat Now'.");
    return false;
  }
}

function CheckLength(obj, maxchar)
{
	if (obj.value.length > maxchar)
	{
	 alert("Your message has been limited to " + maxchar + " characters, please click the appropriate button now to submit.");
	 var msg = obj.value;
	 obj.value = msg.substring(0, maxchar);
	 obj.style.backgroundColor = "#FCC";
	 obj.focus();
	}
}

