﻿
function generateEmbedChatCodeFromForm()
{
	if(document.customForm.affiliateid.value != "" && !is_num(document.customForm.affiliateid.value))
	{
		alert("Affiliate id must be a number");
		return false;
	}
	
	var domain = encodeURIComponent(document.customForm.domain.value);
	var reg = /^[0-9a-zA-Z]([0-9a-zA-Z\-]+\.){1,3}[a-zA-Z]{2,4}?$/;
	if(!reg.test(domain))
	{
			alert("Please input a valid domain");
		return false;
	}
	


	var pre_header  = '<!-- 123FLASHCHAT FREE WEB MESSENGER & FREE CHAT ROOM CODE START --> \n';
	pre_header += '<div id="webmessenger_123flashchat" style="position:fixed;bottom:0;right:0;color:#111111;font-size:11px;height:25px;padding:0;width:100%;z-index:65535;"> \n';
  pre_header  += '<a href="http://www.123flashchat.com" style="border: medium none;"><img height="18px" width="18px" style="border: medium none;" src="http://free.123flashchat.com/images/webbar_logo.png" />web messenger</a>\n';
  pre_header  += '<a href="http://www.123flashchat.com/" style="border: medium none;"><img height="18px" width="18px" style="border: medium none;" src="http://free.123flashchat.com/images/friendlist.png" />facebook messenger</a>\n';
	pre_header  += '<a href="http://www.123flashchat.com/" style="border: medium none;"><img height="18px" width="18px" style="border: medium none;" src="http://free.123flashchat.com/images/shoppingcart.gif" />purchase instant messaging software</a>\n'
	pre_header  += '</div>';
	var pre_footer = '\n<!-- 123FLASHCHAT FREE WEB MESSENGER & FREE CHAT ROOM CODE END -->';
	
	
	var str = '<script language="javascript" src="http://free.123flashchat.com/wmjs.php#domain##af_id##freechat#"></' + 'script>';
	
	if(domain != "")
	{
		str = str.replace("#domain#","?domain=" + domain);
	}
	else
	{
		str = str.replace("#domain#","");
	}
	
	if(document.customForm.affiliateid.value != "")
	{
		var af_id = document.customForm.affiliateid.value;
		if(str.indexOf("?") != -1)
		{
			str = str.replace("#af_id#","&affid=" + af_id);
		}
		else
		{
			str = str.replace("#af_id#","?affid=" + af_id);
		}
	}
	else
	{
		str = str.replace("#af_id#","");
	}

	if(document.getElementById('enablechat').checked == true)
	{
		if(str.indexOf("?") != -1)
		{
			str = str.replace("#freechat#","&f=1");
		}
		else
		{
			str = str.replace("#freechat#","?f=1");
		}
	}
	else
	{
		str = str.replace("#freechat#","");
	}

	document.getElementById('code_javascript_value').value = pre_header + str + pre_footer;
	document.getElementById('code_javascript_value').select();
	if(domain != "")
	{
		var previewlink = "http://free.123flashchat.com/preview.php?d=" + domain;
		if(document.getElementById('enablechat').checked == true)
		{
			previewlink += "&f=1";
		}
	}
	else
	{
		var previewlink = document.getElementById('previewlink').href = "http://free.123flashchat.com/preview.php";
		if(document.getElementById('enablechat').checked == true)
		{
			if(previewlink.indexOf("?") != -1)
			{
				previewlink = previewlink += "&f=1";
			}
			else
			{
				previewlink = previewlink += "?f=1";
			}
		}
	}
	document.getElementById('previewlink').href = previewlink;
}
function copy(id) 
{
	var text2copy = document.getElementById(id).value;

	document.getElementById(id).select();
	if (window.clipboardData) {
          window.clipboardData.setData("Text",text2copy);
    } 
    else 
    {
		var flashcopier = 'flashcopier';
        if(!document.getElementById(flashcopier)) 
        {
			var divholder = document.createElement('div');
			divholder.id = flashcopier;
			document.body.appendChild(divholder);
      	}
     	document.getElementById(flashcopier).innerHTML = '';
       	var divinfo = '<embed src="_clipboard.swf" FlashVars="clipboard='+escape(text2copy)+'" width="0" height="0" type="application/x-shockwave-flash"></embed>';
   		document.getElementById(flashcopier).innerHTML = divinfo;
   		//alert(document.getElementById(flashcopier).innerHTML);
   }
}

function openChat()
{
		window.open(document.getElementById('previewlink').href, '_123flashchat', 'HEIGHT=500,resizable=yes,WIDTH=728');
}

function UrlEncode(str){
  var ret="";
  var strSpecial="!\"#$%&'()*+,/:;<=>?[]^`{|}~%";
  for(var i=0;i<str.length;i++){
   var chr = str.charAt(i);
    var c=str2asc(chr);
    if(parseInt("0x"+c) > 0x7f){
      ret+="%"+c.slice(0,2)+"%"+c.slice(-2);
    }else{
      if(chr==" ")
        ret+="+";
      else if(strSpecial.indexOf(chr)!=-1)
        ret+="%"+c.toString(16);
      else
        ret+=chr;
    }
  }
  return ret;
} 

function is_num(string)
{
	var   re=/^\d*$/;   
	return re.test(string);
}
