var local_server_URL = "";

function sayDebugMessage(e) { }

function m_selectR(id, page_type)
{
	for (i=0; i<10; i++)
	{
		var A = document.getElementById("menu_R"+i); if (!A) break;
		
		A.className = (i == id) ? 'main_btn1 main_bt1_selected' : 'main_btn1';
	}

	var title = "", img = "", cont = "";

	var text = new Array(
		// - - - - - - - - - - - - - - -
		new Array(
			new Array("Create your own website in minutes",
					"0px -585px",
					"With BlinkWeb's super easy editor, you can create your own professional looking website and have it on the web for your friends and family to see in a matter of a few minutes.</p><p>If you can use notepad, you can now create your own fully featured website using a free BlinkWeb account!"),
			new Array("Interact with friends and family",
					"0px 0px",
					"<br/><br/>Add your very own blog and make daily, weekly, or monthly posts to your blog. Get feedback from friends and family as 	they read your blog.</p><p>Never before has blogging been so fast and easy!"),
			new Array("Add videos and pictures",
					"0px -195px",
					"<br/><br/>Keep your friends and family updated by adding pictures and videos to your website.</p><p>You'll be able to add both Google or Youtube videos, as well as personal pictures and even Flickr images!"),
			new Array("Make your site look impressive",
					"0px -390px",
					"<br/><br/>Never before has it been so easy to create an attractive looking website. With BlinkWeb, you'll be able to select 		from hundreds of different website designs, ensuring that you get the exact look and feel you want for your website.")
		// - - - - - - - - - - - - - - -
		), new Array (
			new Array("Create your own website in minutes",
					"0px -390px",
					"<br/><br/>With BlinkWeb's super easy editor, you can create your own professional looking website or salesletter and have it on the web for prospective customers to see in a matter of a few minutes."),
			new Array("Increase your conversions",
					"0px -780px",
					"Never before has it been so easy to create an attractive looking website... that converts to sales. With BlinkWeb, you'll be able to select from TONS of different sales letter designs, ensuring that you get the exact look and feel you want for your website.<br/>Add checkmarks, testimonial boxes, purchase buttons and more!"),
			new Array("Interact with prospective customers",
					"0px 0px",
					"<br/><br/>Add your very own blog and make daily, weekly, or monthly posts. Build a network of loyal \"fans\" as they read your blog each day.<br/><br/>Never before has blogging been so fast and easy!"),
			new Array("Add videos and pictures",
					"0px -195px",
					"<br/><br/>Easy drag and drop interface lets you add pictures and videos to your website.<br/><br/>You'll be able to add both Google or Youtube videos, as well as product or personal pictures and even Flickr images!")
		));

	if (typeof page_type == 'undefined') page_type = 0;
	title = text[page_type][id][0];
	img   = text[page_type][id][1];
	cont  = text[page_type][id][2];

	A = document.getElementById("menu_RR"       ); if (A) A.style.top = (id*52 + 15) + "px";		if (typeof default_cant_use_PNGs == "undefined" || !default_cant_use_PNGs) A.style.background = "url(images/main_ui/btn1.png) no-repeat 0px 0px";
	A = document.getElementById("main_title_id" ); if (A) A.innerHTML = (id+1);
	A = document.getElementById("main_title"    ); if (A) A.innerHTML = title;
	A = document.getElementById("main_demo_bg"  ); if (A) A.style.backgroundPosition = img;
	A = document.getElementById("main_demo_text"); if (A) A.innerHTML = "<p>"+cont+"</p>";

	return false;
}


function go_EditSite(id)
{
	document.location =  local_server_URL+"?goEdit="+id;
}

function go_MoneySite(id)
{
	document.location =  local_server_URL+"site_info.html?"+id;
}

function go_EditSubscription(id, op)
{
	document.location =  local_server_URL+"subscription.html?"+id+(!op ? "" : "#"+op);
}

function go_DeleteSite(id)
{
	endModalDlg();
	var modalClient  = document.getElementById("modal-client");		if (modalClient.firstNode) return;

	modalClient.innerHTML = "<img src='images/modal_ui/modal_del.jpg' style='float:left; margin-left:10px;'>"+
			"<p style='margin-left: 90px;'>This action in permanent - if you delete this site, there is no way to retrieve it.</p>"+
			"<p style='margin-left: 90px;'>If you are sure you want to delete this site, type \"DELETE\" in the box below:<br/>"+
			"<input type='text' id='go_DeleteSite_inp' style='width: 100px; margin-left: 160px; margin-top: 5px;'></p>";

	addModalBtn("Delete", "go_DeleteSite_check("+id+");");
	addModalBtn("Cancel" , "");
	startModalDlg(600, 80, "Are you sure you want to delete this site?", 4, 1);
}

function go_DeleteSite_check(id)
{
	var inp = document.getElementById('go_DeleteSite_inp');
	if (inp && inp.value.match(/^delete$/i)) document.location = local_server_URL+"/?goDelete="+id;
	else return 1;
}


var m_goCreateSite = {
	siteType: 0,
	siteTitle: 0,
	siteDomain: 0,
	create_style: 0,
	dialogTitle:0
};


function go_CreateSite()
{
	m_goCreateSite.siteType = 's';
	m_goCreateSite.siteTitle = '';
	m_goCreateSite.siteDomain = '';
	m_goCreateSite.create_style = 'create';
	m_goCreateSite.dialogTitle = 'Create a new site';
	
	go_CreateSite_step1();
}


function go_CreateSite_step1()
{
	var el;
	if (el = document.getElementById('site_title')) m_goCreateSite.siteTitle = el.value;
	if (el = document.getElementById('site_domain')) m_goCreateSite.siteDomain = el.value;

	endModalDlg();
	var modalClient  = document.getElementById("modal-client");		if (modalClient.firstNode) return;

	modalClient.innerHTML = "<img src='images/modal_ui/modal_new.jpg' style='float:left; margin-left:10px;'>"+
			"<table style='padding: 10px 20px;'><tbody>"+
			"<tr><td style='font-size: 15px; font-weight: bold; padding-bottom: 15px;' colspan='3'>What type of website would you like to create?</td></tr>"+
			"<tr valign='middle'><td style='padding-left: 30px; width: 10px; height: 25px' valign='top'>"+
					"<input type='radio' name='site_type' id='site_type_s' value='s' class='home_table_check'"+(m_goCreateSite.siteType == 's' ? " checked='checked'" : "")+"/></td>"+
					"<td style='width: 200px'><a href='#' onclick='document.getElementById(\"site_type_s\").click(); return false;'>Salesletter style website</a></td>"+
					"<td><a href='learn_more.html?new_sales' onclick='return new_window_open(this.href, \"_learnmore\")'>Learn more</a></td></tr>"+
			"<tr valign='middle'><td style='padding-left: 30px; width: 10px; height: 25px' valign='top'>"+
					"<input type='radio' name='site_type' id='site_type_p' value='p' class='home_table_check'"+(m_goCreateSite.siteType == 'p' ? " checked='checked'" : "")+"/></td>"+
					"<td><a href='#' onclick='document.getElementById(\"site_type_p\").click(); return false;'>Content style website</a></td>"+
					"<td><a href='learn_more.html?new_page' onclick='return new_window_open(this.href, \"_learnmore\")'>Learn more</a></td></tr>"+
			"<tr valign='middle'><td style='padding-left: 30px; width: 10px; height: 25px' valign='top'>"+
					"<input type='radio' name='site_type' id='site_type_b' value='b' class='home_table_check'"+(m_goCreateSite.siteType == 'b' ? " checked='checked'" : "")+"/></td>"+
					"<td><a href='#' onclick='document.getElementById(\"site_type_b\").click(); return false;'>Blog style website</a></td>"+
					"<td><a href='learn_more.html?new_blog' onclick='return new_window_open(this.href, \"_learnmore\")'>Learn more</a></td></tr>"+
			"<tr><td colspan='3' style='padding-top: 15px'>Tip: You can change your website type at any time.</td></tr>"+
			"</tbody></table></form>";

	if (m_goCreateSite.create_style == 'transfer')	addModalBtn("<< Back" , "go_TransferDomain_step1(); 1");
	else											addModalBtn("Cancel" , "");
	
	addModalBtn("Next >>", "go_CreateSite_step2(); 1");
	startModalDlg(550, 170, m_goCreateSite.dialogTitle, 4, 1);


	document.getElementById("modal-buttons").style.width = '430px';
	var div = document.createElement("DIV");
	document.getElementById("modal-buttons").appendChild(div);

	div.style.padding = '15px 0px 0px 360px';
	div.style.font = 'bold 12px Arial';
	if (m_goCreateSite.create_style == 'create'  ) div.innerHTML = "Step 1/2";
	if (m_goCreateSite.create_style == 'transfer') div.innerHTML = "Step 2/3";


	return true;
}

function go_CreateSite_step2()
{
	var newType = 'p', el;
	if ((el = document.getElementById('site_type_s')) && el.checked) newType = 's';
	if ((el = document.getElementById('site_type_p')) && el.checked) newType = 'p';
	if ((el = document.getElementById('site_type_b')) && el.checked) newType = 'b';
	if (newType != '-') m_goCreateSite.siteType = newType;
	else newType = m_goCreateSite.siteType;

	endModalDlg();
	var modalClient  = document.getElementById("modal-client");		if (modalClient.firstNode) return;


	modalClient.innerHTML = "<img src='images/modal_ui/modal_new.jpg' style='float:left; margin-left:10px;'>"+
			"<form id='create_site_form' action='"+local_server_URL+"/?goCreate' method='post'>"+
			"<table style='padding: 10px 20px;'><tbody>"+
			"<tr><td style='font-size: 15px; font-weight: bold'>Enter a title for your website.</td></tr>"+
			"<tr><td><br/>Tip: The title for your website should be a word or phrase that helps you remember which website you're creating."+
					"<p>(Example: Weight Loss Made Easy)</p></td></tr>"+
			"<tr><td style='padding: 10px 40px; line-height: 30px;'>"+
					"<input type='text' name='site_title' id='site_title' class='home_table_input' style='width:350px' value='"+m_goCreateSite.siteTitle+"' />"+
					"<input type='hidden' name='site_type' value='"+newType+"'/>"+
			"</td></tr>"+
			"</tbody></table></form>";

	addModalBtn("<< Back" , "go_CreateSite_step1(); 1");
	if (m_goCreateSite.create_style == 'transfer')	addModalBtn("Next >>", "go_TransferDomain_step2(); 1");
	else											addModalBtn("Next >>", "document.getElementById('create_site_form').submit()");
	startModalDlg(550, 170, m_goCreateSite.dialogTitle, 4, 1);

	document.getElementById("modal-buttons").style.width = '430px';
	var div = document.createElement("DIV");
	document.getElementById("modal-buttons").appendChild(div);

	div.style.padding = '15px 0px 0px 360px';
	div.style.font = 'bold 12px Arial';
	if (m_goCreateSite.create_style == 'create'  ) div.innerHTML = "Step 2/2";
	if (m_goCreateSite.create_style == 'transfer') div.innerHTML = "Step 3/3";

	return true;
}


function go_TransferDomain()
{
	m_goCreateSite.siteType = 's';
	m_goCreateSite.siteTitle = '';
	m_goCreateSite.siteDomain = '';
	m_goCreateSite.create_style = 'transfer';
	m_goCreateSite.dialogTitle = 'Transfer a domain';
	
	go_TransferDomain_step1();
}

function go_TransferDomain_step1()
{
	var newType = '-', el;
	if ((el = document.getElementById('site_type_s')) && el.checked) newType = 's';
	if ((el = document.getElementById('site_type_p')) && el.checked) newType = 'p';
	if ((el = document.getElementById('site_type_b')) && el.checked) newType = 'b';
	if (newType != '-') m_goCreateSite.siteType = newType;

	endModalDlg();
	var modalClient  = document.getElementById("modal-client");		if (modalClient.firstNode) return;


	modalClient.innerHTML = "<img src='images/modal_ui/modal_new.jpg' style='float:left; margin-left:10px;'>"+
			"<table style='padding-left: 20px;'><tbody>"+
			"<tr><td style='font-size: 15px; font-weight: bold'>Enter the domain name you wish to transfer.</td></tr>"+
			"<tr><td>Tip: By transfering your domain name to BlinkWeb, you will be able to use the BlinkWeb page builder to create that website. <br/>"+
					"<p>* It is extremely important to input your domain name correctly below."+
					"<p><small>(Example: <span style=' font-weight: bold'><span style='color:green; text-decoration: underline'>website.com</span> is correct</span>;"+
	//					"<br/>"+
						" <span style='color:red'>www.website.com</span> or <span style='color:red'>subdomain.website.com</span> are both incorrect)</small></p></td></tr>"+
			"<tr><td style='padding: 5px 0px; line-height: 30px; font-size: 16px;'>"+
					"http://www. <input type='text' name='site_domain' id='site_domain' class='home_table_input' style='width:320px; display: inline' value='"+m_goCreateSite.siteDomain+"' />"+
			"</td></tr>"+
			"</tbody></table>";

	addModalBtn("Cancel" , "");
	addModalBtn("Next >>", "go_TransferDomain_step1_check(); 1");
	startModalDlg(550, 170, m_goCreateSite.dialogTitle, 4, 1);

	document.getElementById("modal-buttons").style.width = '430px';
	var div = document.createElement("DIV");
	document.getElementById("modal-buttons").appendChild(div);

	div.style.padding = '15px 0px 0px 360px';
	div.style.font = 'bold 12px Arial';
	div.innerHTML = "Step 1/3";

	return true;
}


function go_TransferDomain_step1_check()
{
	var el;
	if (el = document.getElementById('site_domain')) m_goCreateSite.siteDomain = el.value;

	
	if (!m_goCreateSite.siteDomain.match(/^([0-9a-z\-]+)(([\.]{1})([a-z]{2,4})){1,2}$/) || 
		 m_goCreateSite.siteDomain.toLowerCase().indexOf('www.') !== -1)
	{
		alert("Domain name formatting doesn't seem to be correct !");
		el.focus();
	} else go_CreateSite_step1();
}


function go_TransferDomain_step2()
{
	var el;
	if (el = document.getElementById('site_title')) m_goCreateSite.siteTitle = el.value;

	var extraStr = "create_site="+m_goCreateSite.siteType+"&create_title="+escape(m_goCreateSite.siteTitle);

	editor_publish_purchase('hosting', m_goCreateSite.siteDomain, extraStr);
}