/*
 * Disable the mouse hover effects to show/hide the submenus
 * To enable this effect, just delete the code below.
 */
$(document).ready(function() {
	$('ul#nav a').unbind('mouseover');
	
	if ((!Browser.ie) || (Browser.version > 7)) {
		$('#menu').unbind('mouseleave');
	}
});


/*
 * Login functions
 */
function www_panellogin_signin() {
	var objAccountIdInput = document.getElementById("www_panellogin_accountid");
	var objPasswordInput = document.getElementById("www_panellogin_password");

	window.location.href = "https://panel.ihostnetworks.com/Panel/SignIn.aspx?" +
		"idtype=SiteName" + 
		"&showwarnings=true" + 
		"&accountid=" + escape(objAccountIdInput.value) +
		"&password=" + escape(objPasswordInput.value);
}

// "Submit the form on enter" functionality
function www_panellogin_onenter(in_objEvent) {
	var intKeyCode = -1;

	if(in_objEvent.which) {
			intKeyCode = in_objEvent.which;
	} else if(in_objEvent.keyCode) {
			intKeyCode = in_objEvent.keyCode;
	}

	if(intKeyCode == 13) {
		www_panellogin_signin();
		return false;
	}

	return true;
}


/*
 * Domain Search and Signup Function
 */
function www_signup_domainsearch() {
	var intAppID = '3'
	var objSearchDomainNameInput = document.getElementById("www_signup_domainsearch_domainname");

	window.location.href = "https://signup.ihostnetworks.com/_branding/ihostnet/signup.asp?id=" + intAppID + "&chrome=0&plan=Domain+Only&d1=n&checkdomain=" + escape(objSearchDomainNameInput.value);
}

// "Submit the form on enter" functionality
function www_signup_domainsearch_onenter(in_objEvent) {

	var intKeyCode = -1;

	if (in_objEvent.which) {
		intKeyCode = in_objEvent.which;
	}
	else if (in_objEvent.keyCode) {
		intKeyCode = in_objEvent.keyCode;
	}

	if (intKeyCode == 13) {
		www_signup_domainsearch();
		return false;
	}

	return true;
}

/* Start promo domain search */
function www_signup_promodomainsearch() {
	var intAppID = '3'
	var objSearchDomainNameInput = document.getElementById("www_signup_promodomainsearch_domainname");

	window.location.href = "https://signup.ihostnetworks.com/_branding/ihostnet/signup.asp?id=" + intAppID + "&chrome=0&promos=SAVETHEELEPHANTS&plan=Pro-plus+Web+Hosting&checkdomain=" + escape(objSearchDomainNameInput.value);
}

// "Submit the form on enter" functionality
function www_signup_promodomainsearch_onenter(in_objEvent) {

	var intKeyCode = -1;

	if (in_objEvent.which) {
		intKeyCode = in_objEvent.which;
	}
	else if (in_objEvent.keyCode) {
		intKeyCode = in_objEvent.keyCode;
	}

	if (intKeyCode == 13) {
		www_signup_promodomainsearch();
		return false;
	}

	return true;
}
/* end promo domain search*/


function www_signuplink_signup() {
	var intAppID = '3'
	var intSignupAppIDInput = document.getElementById('www_signuplink_appid');
	if (intSignupAppIDInput != null) {
		intAppID = escape(intSignupAppIDInput.value);
	}

	var objPlanInput = document.getElementById('www_signuplink_plan')
	var objPrepay1Yr = document.getElementById('www_signuplink_prepay1yr')
	var objPromos = document.getElementById('www_signuplink_promos')
	var objSignupDomainName = document.getElementById('www_signuplink_newdomain');

	var strSignupPromos = "";
	if (objPromos != null) {
		strSignupPromos = "&promos=" + escape(objPromos.value);
	}

	var strSignupDomainName = "";
	if (objSignupDomainName != null) {
		strSignupDomainName = "&d1=n&checkdomain=" + escape(objSignupDomainName.value);
	}

	if (objPrepay1Yr.checked == true) {
		window.location.href = "https://signup.ihostnetworks.com/_branding/ihostnet/signup.asp?id=" + intAppID + "&plan=" + escape(objPlanInput.value) + "&prepay1yr=true" + strSignupPromos + strSignupDomainName;
	}
	else {
		window.location.href = "https://signup.ihostnetworks.com/_branding/ihostnet/signup.asp?id=" + intAppID + "&plan=" + escape(objPlanInput.value) + "&prepay1yr=false" + strSignupPromos + strSignupDomainName;
	}
}

// "Submit the form on enter" functionality
function www_signuplink_onenter(in_objEvent) {
	var intKeyCode = -1;

	if (in_objEvent.which) {
		intKeyCode = in_objEvent.which;
	}
	else if (in_objEvent.keyCode) {
		intKeyCode = in_objEvent.keyCode;
	}

	if (intKeyCode == 13) {
		www_signuplink_signup();
		return false;
	}

	return true;
}

/*
* Template color variations
*/
function open_template_color(color, filePath) {
	$('#TemplateSelected').attr('src', filePath);

	$('a.thumbnail_color').each(function(i) {
		if ($(this).attr("id") == "thumbnail_color_" + color) {
			$(this).addClass("selected");
		} else {
			$(this).removeClass("selected");
		}
	});

	$('a.button-big').each(function(i) {
		var href = $(this).attr("href");
		if (href.indexOf("LiveDemo") < 0) {
			var pos = href.indexOf(";");
			var param = ";" + color;

			if (href.indexOf("trialsignup") > 0) {
				pos = href.indexOf("&site_skin=");
				param = "&site_skin=" + color;
			}

			if (pos < 0) {
				href = href + param;
			} else {
				href = href.substr(0, pos) + param;
			}

			$(this).attr("href", href);
		}
	});
}


/*
* Inverse tabs
*/
function open_content(link, className) {

	$('a.inverse_tab').each(function(i) { 
		if ($(this).hasClass(className+'_selected')) {
			$(this).removeClass(className+'_selected');
			$(this).addClass(className);
		}
		
	});


	$('div.content_inverse_tab').each(function(i) { 
		$(this).hide();
	});
	
	
	$('#'+link.id).addClass(className + '_selected');
	
	var content_height = '190px';
	var content = $('#content_' + link.id);
	content.show();
	
	if (content.css('height')!="auto") {
		content_height = content.css('height');
	}
	
	$('#content_inverse_tab').css('height', content_height);

}

/*
 * Validations
 */
function submitFormBuildSiteForMe() {

	var firstname = $get("form_firstname");
	var lastname = $get("form_lastname");
	var email = $get("form_email");
	
	fields = fieldsArray(3);
	fields[0][0]=firstname;
	fields[1][0]=lastname;
	fields[2][0]=email;

	varMessage = "";

	if (firstname.value=="") {
		varMessage = varMessage + "<li>The field First Name is required</li>";
		fields[0][1] = "field_error";
	}
	
	if (lastname.value=="") {
		varMessage = varMessage + "<li>The field Last Name is required</li>";
		fields[1][1] = "field_error";
	}	
	
	if (email.value=="") {
		varMessage = varMessage + "<li>The field E-mail is required</li>";
		fields[2][1] = "field_error";
	} else {
		emailx = email.value;
		if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(emailx))) {
			varMessage = varMessage + "<li>Invalid E-mail</li>";
			fields[2][1] = "field_error";
		}		
	}

	global_fields = fields;
	
	if (varMessage!="") {	
		checkValidation(varMessage);
	} else {
		// submit the form
		document.forms[0].target = '_blank';
		document.forms[0].action = 'http://www.ihost.net/contactform/send_buildasiteforme.asp';
		document.forms[0].method = 'POST';
		document.forms[0].submit();
	}
}

function submitFormFreeTrial() {

  	var FirstNameTextBox = $get("FirstNameTextBox");
  	var LastNameTextBox = $get("LastNameTextBox");
  	var EmailTextBox = $get("EmailTextBox");
  	var UsernameTextBox = $get("UsernameTextBox");
  	var PasswordTextBox = $get("PasswordTextBox");
  	var ConfirmPasswordTextBox = $get("ConfirmPasswordTextBox");
  	var TermsCheckBox = $get("TermsCheckBox");
	
	fields = fieldsArray(7);
	fields[0][0]=FirstNameTextBox;
	fields[1][0]=LastNameTextBox;
	fields[2][0]=EmailTextBox;
	fields[3][0]=UsernameTextBox;
	fields[4][0]=PasswordTextBox;
	fields[5][0]=ConfirmPasswordTextBox;
	fields[6][0]=TermsCheckBox;

	varMessage = "";

	if (FirstNameTextBox.value=="") {
		varMessage = varMessage + "<li>The field First Name is required</li>";
		fields[0][1] = "field_error";
	}
	
	if (LastNameTextBox.value=="") {
		varMessage = varMessage + "<li>The field Last Name is required</li>";
		fields[1][1] = "field_error";
	}	
	
	if (EmailTextBox.value=="") {
		varMessage = varMessage + "<li>The field E-mail is required</li>";
		fields[2][1] = "field_error";
	} else {
		emailx = EmailTextBox.value;
		if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(emailx))) {
			varMessage = varMessage + "<li>Invalid E-mail</li>";
			fields[2][1] = "field_error";
		}		
	}
	
	if (UsernameTextBox.value=="") {
		varMessage = varMessage + "<li>The field User Name is required</li>";
		fields[3][1] = "field_error";
	} 
	
	if (PasswordTextBox.value=="") {
		varMessage = varMessage + "<li>The field Password is required</li>";
		fields[4][1] = "field_error";
	} else if (PasswordTextBox.value.length < 7) {
		varMessage = varMessage + "<li>Password must be at least 7 characters</li>";
		fields[4][1] = "field_error";
	}
	
	if (ConfirmPasswordTextBox.value=="") {
		varMessage = varMessage + "<li>The field Confirm Password is required</li>";
		fields[5][1] = "field_error";
	} else if (ConfirmPasswordTextBox.value != PasswordTextBox.value) {
		varMessage = varMessage + "<li>Confirm Password must match Password</li>";
		fields[5][1] = "field_error";
	}
	
	if (TermsCheckBox.checked==false) {
		varMessage = varMessage + "<li> Please accept Terms and Conditions before publishing</li>";
		fields[6][1] = "field_error";
	}

	global_fields = fields;
	
	if (varMessage!="") {	
		return checkValidation(varMessage);
	} else {
		// submit the form
		//document.forms[0].target = '_blank';
		document.forms[0].action = 'http://ihost.net/trialsignup/publish.aspx';
		document.forms[0].method = 'POST';
		document.forms[0].submit();
	}
} 
