/***********************************************************************
 @ filename            : js/register.js
 @ author              : MAlcolm Allaway
 @ description         : Regsitration js functions
 @ created             : 2008-08-26
 @ modified            :
 @ requires            :
 ***********************************************************************/
var xmlhttp;
/* * * * * * * * * * * * * * * * * * * * * * * * * * * *\
  ##  AJAX functions - dynamic population and updates ##
\* * * * * * * * * * * * * * * * * * * * * * * * * * * */
// check username is not already in use
function checkUserName() {
 if((document.getElementById("username").value) != (document.getElementById("oldusername").value) && (document.getElementById('register_new').checked)) {
   xmlhttp=null;
	if (window.XMLHttpRequest)
	  {// code for Firefox, Opera, IE7, etc.
	    xmlhttp=new XMLHttpRequest();
	  }
	else if (window.ActiveXObject)
  	{// code for IE6, IE5
  	  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  	}
	if (xmlhttp!=null) {
  	xmlhttp.onreadystatechange=check_user_list;
  	xmlhttp.open("GET",'../user/acheckuserlist.php',true);
  	xmlhttp.send('');
 	}
 }
}
function checkWizzardUserName() {
// if((document.getElementById("username").value) != (document.getElementById("oldusername").value) ) {
   xmlhttp=null;
	if (window.XMLHttpRequest)
	  {// code for Firefox, Opera, IE7, etc.
	    xmlhttp=new XMLHttpRequest();
	  }
	else if (window.ActiveXObject)
  	{// code for IE6, IE5
  	  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  	}
	if (xmlhttp!=null) {
  	xmlhttp.onreadystatechange=check_user_list;
  	xmlhttp.open("GET",'../user/acheckuserlist.php',true);
  	xmlhttp.send('');
 	}
 //}
}
function check_user_list()
{

if (xmlhttp.readyState==4)
  {// 4 = "loaded"
  if (xmlhttp.status==200)
    {// 200 = "OK"

	var nameList = xmlhttp.responseText;
	var myName   = $.trim(document.getElementById("username").value);
    var pattern  = eval("/" +  myName +  ":/i" );
	var result   = pattern.test(nameList);
	var regex=/^[0-9A-Za-z]+$/;
	var result2 = regex.test(myName);
	
	if (result == true && myName !='') {
		alert ('Sorry, the username name "' + myName + '" has already been chosen.\n\nPlease choose another name.');
		document.getElementById("username").focus()
	} 
	
	if (result2 == false) {
		alert ('Sorry, the username name "' + myName + '" can only contain alphanumeric characters.\n\nPlease choose another name.');
		document.getElementById("username").focus()
	}
	//else {
		//document.getElementById("").submit();
	//}
  }
  }
}
function addPaymentEmailAddress() {
var ename = document.getElementById("emailname").value;
var edom  = document.getElementById("emaildom").value;

   xmlhttp=null;
	if (window.XMLHttpRequest)
	  {// code for Firefox, Opera, IE7, etc.
	    xmlhttp=new XMLHttpRequest();
	  }
	else if (window.ActiveXObject)
  	{// code for IE6, IE5
  	  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  	}
	if (xmlhttp!=null) {
  	xmlhttp.onreadystatechange=check_email_list;
  	var url = '../user/acheckemailaddr.php?n=' + ename + '&d=' + edom
  	xmlhttp.open("GET",url,true);
  	xmlhttp.send('');
 	}

}

function check_email_list()
{
var ename = document.getElementById("emailname").value;
var edom  = document.getElementById("emaildom").value;
//alert ("value = " + document.getElementById("emaildom").value + ' seleIndex = ' + document.getElementById("emaildom").selectedIndex.value);
if (xmlhttp.readyState==4)
  {// 4 = "loaded"
  if (xmlhttp.status==200)
    {// 200 = "OK"
	var nameList = xmlhttp.responseText
	if (nameList == 'full') {
		alert('You have registered 10 email addresses for this domain already');
	} else {
	  var myName   = document.getElementById("emailname").value + '@' + document.getElementById("emaildom").value;
      var pattern  = eval("/" +  myName +  ":/i" );
	  var result   = pattern.test(nameList);

 	  if (result == true) {
	  	  alert ('Sorry, the email address "' + myName + '" is already in use.\n\nPlease choose another name.');
		  document.getElementById("emailname").value='';
		  document.getElementById("emailname").focus();
	  } else {
	  	var n = document.getElementById("emailname").value;
	  	var d = document.getElementById("emaildom").value;
	  	var f = document.getElementById("emailfwd").value;
		var u = document.getElementById("userid").value;
  		var url = '../user/aaddemailaddr.php?n=' + n + '&d=' + d + '&u=' + u + '&f=' + f;
  		xmlhttp.open("GET",url,true);
  		xmlhttp.send('');
  		showPendingEmails(n + '@' + d);
	  }
	}
  }
  }
}

function markEmailAcctForDelete(domainname) {
// if (document.getElementById(domainname).checked==true) {
   xmlhttp=null;
	if (window.XMLHttpRequest)
	  {// code for Firefox, Opera, IE7, etc.
	    xmlhttp=new XMLHttpRequest();
	  }
	else if (window.ActiveXObject)
  	{// code for IE6, IE5
  	  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  	}

	if (xmlhttp!=null && eval('document.getElementById("' + domainname + '").checked==true')) {
  	  xmlhttp.onreadystatechange=processMarkEmailAcctForDelete;

  	  var url = '../user/aupdatedeleteemail.php?d=' + domainname;
  	  xmlhttp.open("GET",url,true);
  	  xmlhttp.send('');
 	}
	else if (xmlhttp!=null && eval('document.getElementById("' + domainname + '").checked==false')) {
  	  xmlhttp.onreadystatechange=processUnmarkEmailAcctForDelete;
  	  var url = '../user/aupdatedeleteemail.php?d=' + domainname;
  	  xmlhttp.open("GET",url,true);
  	  xmlhttp.send('');
 	}

}

function processMarkEmailAcctForDelete()
{

if (xmlhttp.readyState==4)
  {// 4 = "loaded"
  if (xmlhttp.status==200)
    {// 200 = "OK"

	var emailList = xmlhttp.responseText;
	var aEmails  = emailList.split(",");
	for (i=0; i < aEmails.length; i++) {
		eval("document.getElementById('e-" + aEmails[i] + "').checked= true ");
		eval("document.getElementById('e-" + aEmails[i] + "').disabled= true ");
	}
  }
  }
}
function processUnmarkEmailAcctForDelete()
{

if (xmlhttp.readyState==4)
  {// 4 = "loaded"
  if (xmlhttp.status==200)
    {// 200 = "OK"

	var emailList = xmlhttp.responseText;
	var aEmails  = emailList.split(",");
	for (i=0; i < aEmails.length; i++) {
		eval("document.getElementById('e-" + aEmails[i] + "').checked=false");
		eval("document.getElementById('e-" + aEmails[i] + "').disabled=false");
	}
  }
  }
}



/* * * * * * * * * * * * * * * * * * * * * * * * * * * *\
  ##  << end AJAX functions >>
\* * * * * * * * * * * * * * * * * * * * * * * * * * * */

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\
  ##  Registration page 1 New user / Upgrade toggle functions
\* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */


function setRegisterNew(){
	document.getElementById('new_user_details').style.display="block";
	document.getElementById('btn_paynow').value="Pay Now";
	document.getElementById('lbl_choose_pwd').innerHTML="Choose a Password";
	document.getElementById('lbl_choose_username').innerHTML="Choose a username";
	document.getElementById('7day_trial_txt').style.display="block";
	document.getElementById("btn_trial").style.visibility="visible";
	document.getElementById("btn_upgnow").style.display="block";
}

function setRegisterDGU(){
	document.getElementById('new_user_details').style.display="none";
	document.getElementById('lbl_choose_pwd').innerHTML="Your Password";
	document.getElementById('lbl_choose_username').innerHTML="Your DG Username";
	document.getElementById('7day_trial_txt').style.display="none";
	document.getElementById("btn_trial").style.visibility="hidden";
//	document.getElementById("btn_trial").className="btn-register-disabled";
	document.getElementById('btn_paynow').value="Upgrade Now";

}


/* * * * * * * * * * * * * * * * * * * * * * * * * * * *\
  ##  Page checking and processing functions
\* * * * * * * * * * * * * * * * * * * * * * * * * * * */

// activate buttons on various webpages - set disabled by default until an entry has been made on the page
function activate_btn(webpage){
	if (webpage == "1") {  // order a new domain
		document.getElementById("btn_paynow").className="button";
		document.getElementById("btn_paynow").disabled=false;
		if (document.getElementById('register_new').checked) {
			document.getElementById("btn_trial").className="button";
			document.getElementById("btn_trial").disabled=false;
		}
	}
	if (webpage=="2") {   // transfer a domain
		window.opener.document.getElementById("btn_next").className="button";
		window.opener.document.getElementById("btn_next").disabled=false;
	}
	if (webpage=="3") {   // point a domain
		document.getElementById("btn_next").className="button";
		document.getElementById("btn_next").disabled=false;
	}
	if (webpage=="11") {  // payment system
		document.getElementById("btn_submit").className="button";
		document.getElementById("btn_submit").disabled=false;
	}
	if (webpage == "1a") {  // paynow
		document.getElementById("btn_paynow").className="button";
		document.getElementById("btn_paynow").disabled=false;
	}
	if (webpage == "1b") {  // trial
		//if (document.getElementById('register_new').checked) {
			document.getElementById("btn_trial_solo").className="button";
			document.getElementById("btn_trial_solo").disabled=false;

		//}
	}
	if (webpage == "4") {  // paynow
		document.getElementById("btn_submit").className="button";
		document.getElementById("btn_submit").disabled=false;
	}
}

//  show additional email input - unhide next input
function AddEmail(addrno) {
	eval('document.getElementById("emailinput' + addrno + '").style.display = "block"');
	eval('document.getElementById("ShowEmailBtnn' + addrno + '").style.display = "none"');
}
/**
 *
 * @access public
 * @return void
 **/
function paymentAddEmailSubmit(){
			document.getElementById("addEmailSubmit").disabled=false;
}
//  check format of domain entered for transfer and
//     then calls "HighlightTransferInstruction" to highlight user instructions
function CheckDomainTransferName_old(domtype){
// removed 9 Dec 09 - checking format was causing some problems for users who couldn't understand
// what they should enter. These are processed manually anyway so check is not essential
	var  domainname = document.getElementById("domain_name").value;
	var  domformat = /[a-z0-9]+(\.[a-z]{2,3})?\.[a-z]{2,3}/ig;
 if (! domformat.test(domainname)) {
 	alert (domainname + " is not a valid domain. Please re-enter domain.");
 } else {
 	if (domtype!='point') {
  		HighlightTransferInstruction(domainname);
 	}
	UpdateDomainTransferName(domainname);
 }
}
//  check format of domain entered for transfer and
//     then calls "HighlightTransferInstruction" to highlight user instructions
function CheckDomainTransferName(domtype){
// New 9 Dec 09 - does not validate the domain format - just forwards whatever to kinvara
	var  domainname = document.getElementById("domain_name").value;
 	if (domtype!='point') {
  		HighlightTransferInstruction(domainname);
 	}
	UpdateDomainTransferName(domainname);

}
// check user input on registration form
function CheckRegForm(){
	var err_msg = new Array();
	var error_msg = '';
	var error_message = '';
	var j=0;

	var fullname = document.getElementById("fullname").value;
	var email_1	 = document.getElementById("email_1").value;
	var phone	 = document.getElementById("telephone").value;
	//var postcode = document.getElementById("postcode").value;
	//var address  = document.getElementById("address").value;
	var username =$.trim(document.getElementById("username").value);
	var pwd_1	 = document.getElementById("passwd_new").value;
	var pwd_2	 = document.getElementById("passwd_confirm").value;

	if (fullname.length < 5) {
		err_msg[j] = "Your full name (min 5 characters)";
		j++;
	}
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (! filter.test(email_1)) {
		err_msg[j] = "Valid Primary email address";
		j++;
	}
	if (phone.length < 7) {
		err_msg[j] = "Telephone number (including code)";
		j++;
	}
//	if (postcode.length < 4) {
//		err_msg[j] = "A valid postcode";
//		j++;
//	}
//	if (address.length < 10) {
	//	err_msg[j] = "A full mailing address";
	//	j++;
	//}
	if (username.length < 4) {
		err_msg[j] = "Your chosen username is too short";
		j++;
	}
	if (username.indexOf(' ') > 0) {
		err_msg[j] = "You may not have spaces in your username";
		j++;
	}
	if (pwd_1.length < 4) {
		err_msg[j] = "A valid password (minimum 4 characters)";
		j++;
	} else {
		if (pwd_1 != pwd_2) {
			err_msg[j] = "Password entries do not match";
			j++;
		}
	}
 	for (i=0; i < err_msg.length; i++) {
 		error_msg += err_msg[i] + ', ';
 	}

	error_message = error_msg.substr(0,(error_msg.length)-2);


	if (error_message.length > 0) {
		error_msg = "Please check the following fields:\n\n" + error_message;
 		alert (error_msg);
	} else {
		//document.getElementById("btn_paynow").className="button";
		//document.getElementById("btn_paynow").disabled=false;
		//document.getElementById("btn_trial").className="button";
		//document.getElementById("btn_trial").disabled=false;
		return true;
	}
}

//  opens the domain checker in a pop-up window
function DomainPopup(){
	window.open('../domain/whois.php','DomainCheck','width=800,height=350,location=no');
}

function DomainPopupCoUk(){
	window.open('../domain/whoisCoUk.php','DomainCheck','width=800,height=350,location=no');
}

// select and highlight pertinent intructions for domain transfer
function HighlightTransferInstruction(domainname){
	domainname= domainname + '_';
	if ((domainname.indexOf('.co.uk_') > 0)  || (domainname.indexOf('.org.uk_') >0) || (domainname.indexOf('.me.uk_')>0)) {
			 document.getElementById('couk_instruction').style.fontWeight="bold";
			 document.getElementById('com_instruction').style.fontWeight="normal";
	}
	else if ((domainname.indexOf('.com_') >0) || (domainname.indexOf('.net_') >0) || (domainname.indexOf('.org_')>0)) {
			 document.getElementById('com_instruction').style.fontWeight="bold";
			 document.getElementById('couk_instruction').style.fontWeight="normal";
	}
	else {
			 document.getElementById('com_instruction').style.fontWeight="normal";
			 document.getElementById('couk_instruction').style.fontWeight="normal";
	}
}

function RegisterCancel(){   // process cancel button
	document.location='http://www.wizz-it.com';
}

//  select step to navigate between register and payment pages
function  SelectStep(fVal) {

	if (fVal == "register_full") {
		if ( document.getElementById('register_new').checked) {
			if (CheckRegForm()) {
 				eval("document.getElementById('mode').value='" + fVal + "'");
 				document.getElementById("setting_personal_form").submit();
			}
		} else {
 				eval("document.getElementById('mode').value='dg_upgrade'");
				document.getElementById("setting_personal_form").submit();
		}
	} else if ( fVal == "register_trial" || fVal == "register_wizzard") {

			if (CheckRegForm()) {
 				eval("document.getElementById('mode').value='" + fVal + "'");
 				document.getElementById("setting_personal_form").submit();
			}

	} else {
 			eval("document.getElementById('mode').value='" + fVal + "'");
 			document.getElementById("setting_personal_form").submit();
	}

}


function CheckFirstWizzard(){
			if (CheckRegForm()) {
 				document.getElementById("setting_personal_form").submit();
			}
}


// disply email addresses previously entered - registration page revisit
function ShowEmailRevisit(){
  if (document.getElementById("emailn1") != null) {
	var email;
	var forwardto;
 	document.getElementById("email_header").innerHTML = "Please enter your email addresses below:";

	for (i=1;i<11;i++) {
		  email = eval('document.getElementById("emailn' + i + '").value');
		  forwardto = eval('document.getElementById("forward_email' + i + '_to").value');
		  if (email.length > 1) {
			eval('document.getElementById("emailinputn' + i + '").style.display = "block"');
			eval('document.getElementById("ShowEmailBtnn' + ((i*1) + 1) + '").style.display = "block"');
			if (i > 1) {
				eval('document.getElementById("ShowEmailBtnn' + i + '").style.display = "none"');
			}

			if (forwardto.length > 1) {
				eval('document.getElementById("email_forward' + i + 'f").checked="true"');
				ShowHideForwardEmail(i,'s');
			}
		  }
	 }
  }
}

// display text box for email forwards when appropriate
function ShowHideForwardEmail(itemno,showval){
	if (showval == "s") {
		eval('document.getElementById("emailforwardaddr' + itemno + '").style.display = "block"');
	} else {
		eval('document.getElementById("emailforwardaddr' + itemno + '").style.display = "none"');
		eval('document.getElementById("forward_email' + itemno + '_to").value=""');
	}
}

//  reads a list of email addresses marked as pending - and appends the latest request to the list
function showPendingEmails(newaddr){
	var pendlist = document.getElementById("pendinglist").innerHTML;
	// remove "-- none --"
	if (pendlist.substr(0,10) == "-- none --") {
		pendlist = '';
	}
	if (pendlist.length > 0) {
		newpendlist = pendlist + ', ' + newaddr;
	} else {
		newpendlist = newaddr;
	}
	eval("document.getElementById('pendinglist').innerHTML='" + newpendlist + "'");
	document.getElementById("pendinglist").style.display = "block";

}

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\
 **  functions to handle the closing of accounts and domain transfer **
\* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
// set a radio button as selected if a domain checkbox is ticked
function SetISPCancelBtn(itemid){
	if (eval('document.getElementById("process_' + itemid + '").checked')) {
		eval('document.getElementById("expire_' + itemid + '").checked=true');
		activate_btn('11');
	} else {
		eval('document.getElementById("expire_' + itemid + '").checked=false');
		eval('document.getElementById("transfer_' + itemid + '").checked=false');
		eval('document.getElementById("ipstag_' + itemid + '").value=""');
	}

}

// tick a domain checkbox if a domain transfer/expire radio button is clicked
//   and clear an IPS tag if the domain is to expire
function SetISPCancelTick(itemid){
	eval('document.getElementById("process_' + itemid + '").checked=true');
	activate_btn('11');
	if (eval('document.getElementById("expire_' + itemid + '").checked==true')) {
		// only clear an IPS tag if one exists!
		if(eval('document.getElementById("ipstag_' + itemid + '") != null')) {
		 eval('document.getElementById("ipstag_' + itemid + '").value=""');
		}
	}
}

// set tick box and radio buttons if an IPS tag has been entered
function SetISPRadioTransfer(itemid){
//	eval('document.getElementById("process_' + itemid + '").checked=true');
	eval('document.getElementById("transfer_' + itemid + '").checked=true');
	activate_btn('11');
}

// if a date is entered - check the cancel on a date button
function SetDomainCancelDateBtn(){
	document.getElementById("cancel_date").checked=true;
}
// if cancel now is clicked - delete the date (if any)
function UnsetDomainCancelDate(){
	document.getElementById("cancel_ondate").value='';
}

function ConfirmRemoveDomain(){
	var domainDelList='';
	var email = document.getElementById('contact_email').value;
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	var transdate = document.getElementById('cancel_ondate').value;
	if (! filter.test(email)) {
		alert ("Please enter a valid email address");
	} else {
		var domlist = document.getElementById('domain_list').value;
		var aDom = domlist.split(',');
		var edom = email.split("@");
		var pattern = new RegExp(edom[1],'i');
		if (pattern.test(domlist) && eval("document.getElementById('process_" + edom[1] + "')") != null && eval("document.getElementById('process_" + edom[1] + "').checked==true")) {   // check box has been ticked too
			alert ("The email address '" + email + "' is on the list to be removed!");
		} else {

			for (i=0;i< aDom.length;i++) {

			//	if ( eval("document.getElementById('process_" + aDom[i] + "').checked")) {
									 domainDelList =  domainDelList + aDom[i] + ', ';
			//	}
			}
			var confirmtransfer = "You have requested to cancel / transfer the following accounts: \n\n";
			confirmtransfer +=  domainDelList.substring(0,domainDelList.length -2) + ".\n\n";
			if (transdate.length > 1) {
				confirmtransfer += "These will be processed on " + transdate;
			} else {
				confirmtransfer += "These will be processed today.";
			}
			confirmtransfer += "\n\n" + "PLEASE NOTE: all email accounts associated with these domains will cease to be managed by wizz-it.com, and will not work unless transferred to a new provider.";

		  if (confirm (confirmtransfer)) {
			 document.getElementById('setting_payment_form').submit();
		  }
		}
	}
}

function ConfirmCloseAccount(){
	var domainDelList='';
	var email = document.getElementById('contact_email').value;
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	var transdate = document.getElementById('cancel_ondate').value;
	if (! filter.test(rightTrim(email))) {
		alert ("Please enter a valid email address");
	} else {
		var domlist = document.getElementById('domain_list').value;
		var aDom = domlist.split(',');
		var edom = email.split("@");
		var pattern = new RegExp(edom[1],'i');
		if (pattern.test(domlist)) {   // make sure the email give is not on the list of domains to be cancelled
			alert ("The email address '" + email + "' is on the list to be removed!");
		} else {
			for (i=0;i< aDom.length;i++) {
				domainDelList =  domainDelList + aDom[i] + ', ';
			}
			var confirmtransfer = "You have requested to close your account  and cancel / transfer the following accounts: \n\n";
			confirmtransfer +=  domainDelList.substring(0,domainDelList.length -2) + ".\n\n";
			if (transdate.length > 1) {
				confirmtransfer += "These will be processed on " + transdate;
			} else {
				confirmtransfer += "These will be processed today.";
			}
			confirmtransfer += "\n\n" + "PLEASE NOTE: all email accounts associated with these domains will cease to be managed by wizz-it.com, and will not work unless transferred to a new provider.";

		  if (confirm (confirmtransfer)) {
			 document.getElementById('setting_payment_form').submit();
		  }
		}
	}
}

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **\
 **  END functions to handle the closing of accounts and domain transfer **
\* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */



// legacy functions - maybe not in use anymore 15/10/08
/*
function UpdateAdditionalWebspace(){
	var extrameg = document.register_paypalform.additional_webspace_mb.value;
	var addmeg = document.register_paypalform.add_mb_val.value;
	var total = document.register_paypalform.amount.value;
	var amtdue
	if ((extrameg * 1) > (addmeg * 1)) {
	  amtdue = (total * 1) + ((extrameg * 1) - (addmeg * 1))
	} else {
	  amtdue = (total * 1) - ((addmeg * 1) - (extrameg * 1))
	}
	var addmeg = document.register_paypalform.add_mb_val.value = extrameg;
	document.register_paypalform.amount.value = (amtdue *1);
//	document.register_paypalform.a3.value=(extrameg * 1) + (amtdue *1);
	eval('document.getElementById("pmt_amount_due").innerHTML="' + number_format_post(amtdue *1) + '"');
}
function UpdateDomainTransfer(updtval){
	var  amtdue = document.register_paypalform.amount.value;
	if (updtval==1) {   // add £10 if box is checked
	 		document.register_paypalform.amount.value=(amtdue *1) + (10 * 1);
			eval('document.getElementById("pmt_amount_due").innerHTML="' + number_format_post(((amtdue *1) + (10 * 1))) + '"');
			UpdateDomainTransferName();
	 }
			document.getElementById("emailInputt").style.display = "none";

}
*/
function UpdateDomainTransferName(domainname){
	//var  domainname = document.setting_personal_form.transfer_domain_name.value;
			// remove http or www from domains
			if (domainname.substr(0,5)=="http:") {
				domainname = domainname.substr(7);
			}

			if (domainname.substr(0,4)=="www.") {
				domainname = domainname.substr(4);
			}
		for (i=1;i<11;i++) {
			eval('document.getElementById("emaildom' + i + '").innerHTML = "' + domainname + '"');
		}
 	document.getElementById("email_header").innerHTML = "Please enter your email addresses below:";
	document.getElementById("email_details1").style.display = "block";
	document.getElementById("emailtransfer_warning").style.display = "block";
	activate_btn('3');
}





function UpdateNewDomain() {
	var  domainname = document.domainSuccessForm.domainName.value;
			// remove http or www from domains
			if (domainname.substr(0,7)=="http://") {
				domainname = domainname.substr(7);
			}
			if (domainname.substr(0,4)=="www.") {
				domainname = domainname.substr(4);
			}
	eval('window.opener.document.getElementById("DomainToRegister").innerHTML = "' + domainname + '"');
	window.opener.document.getElementById("registeredDomainConfirm").style.display = "block";
	window.opener.document.getElementById("DomainOrderBtn").value = "Change Domain";
	window.opener.document.getElementById("domain_name").value = domainname;
	if (window.opener.document.getElementById("btn_submit") != null) {
		window.opener.document.getElementById("btn_submit").className="button";
		window.opener.document.getElementById("btn_submit").disabled=false;
	}
	if (window.opener.document.getElementById("email_header") != null) {
 	  window.opener.document.getElementById("email_header").innerHTML = "Please enter your email addresses below:";
	  window.opener.document.getElementById("email_details1").style.display = "block";
	   for (i=1; i < 11; i++) {
		eval('window.opener.document.getElementById("emaildom' + i + '").innerHTML = "' + domainname + '"');
	   }

	  activate_btn('2');
	}
	window.close();
}




function CheckPaypalForm(){
	if (document.register_paypalform.domain_transfer.checked) {
		var trandomain = document.register_paypalform.domain_transfer_name.value;
		if (trandomain < 3|| (trandomain.indexOf(".",trandomain.length-4) == -1) ) {
			alert ("Please enter a valid Domain to transfer or un-check the tick box");
		} else {
			document.getElementById("register_paypalform").submit();
		}
	} else {
		document.getElementById("register_paypalform").submit();
	}
}

/* general functions used when altering items in the CMS */
function reorderMenu2318(move_dir,item_id,start_pos) {
	eval("document.getElementById('menu_item_id').value='" + item_id + "'");
	eval("document.getElementById('menu_item_pos').value='" + start_pos + "'");
	eval("document.getElementById('menu_item_dir').value='" + move_dir + "'");
	document.content_menu_ordering_form.submit();
}


function reorderMenu(parentmenu,move_dir,item_id,start_pos) {

	document.getElementById("menu"+parentmenu).load("../user/menu.php?mode=ajax_menu_order",{parent_menu :parentmenu,menu_item_id:item_id,menu_item_pos : start_pos,menu_item_dir:move_dir } ,
	      function(data)
          {


         });


}

function expandsubmenupotion(parent_menu)
{


		var hdnstate1=document.getElementById("hdn_state1_"+parent_menu).val();
		var hdnstate2=document.getElementById("hdn_state2_"+parent_menu).val();
		//alert(hdnstate2)
		if(hdnstate1==1)
		{
			document.getElementById("menu"+parent_menu).hide();
			document.getElementById("hdn_state1_"+parent_menu).val('0');
			document.getElementById('expand_img_'+parent_menu).removeClass('removesign');
			document.getElementById('expand_img_'+parent_menu).addClass('addsign');

		}
		if(hdnstate1==0)
		{
			document.getElementById("menu"+parent_menu).show();
			document.getElementById("hdn_state1_"+parent_menu).val('1');
			document.getElementById('expand_img_'+parent_menu).removeClass('addsign');
			document.getElementById('expand_img_'+parent_menu).addClass('removesign');

		}
		if(hdnstate2==0)
		{
			document.getElementById("menu"+parent_menu).load("../user/menu.php?mode=expand_submenu",{parent_menu :parent_menu } ,
			  function(data)
			  {
				document.getElementById("menu"+parent_menu).hide();
				document.getElementById("menu"+parent_menu).show();
				document.getElementById("hdn_state2_"+parent_menu).val('1');
			   //alert(data)
			 });
		}

}

function changemenu(oldparentid,id,newparentid)
	{
		//alert(oldparentid);
		//alert(newparentid);
		//alert(id);
		document.getElementById("menu"+oldparentid).load("../user/menu.php?mode=ajax_change_menu",{old_menu :oldparentid,menu_id:id,parent_id:newparentid } ,
			  function(data)
			  {
				//alert(data);
			   //alert(data)
			 });
	}
/**
 *
 * @access public
 * @return void
 **/
function confirmContentDeletion(format){

	var delitems = 0;
	var args = arguments;
	for (var i=1; i < args.length; i++) {
		if (document.getElementById('content_' + args[i]).checked) {
			delitems ++;
		}
	}
    var conf = "You have chosen to delete " + delitems + " page" ;
	if ((delitems * 1) != 1 ) {
	 	conf += 's';
	 }
	/*if (format=="gallery") {
	  if ((delitems * 1) != 1) {
		conf = conf.substr(0,conf.length-1) + 'ies'
		var multi = " these galleries "
	  } else {
		var multi = " this gallery "
	  }
		conf += "\n\nAll images linked to" + multi + "will also be deleted.\n";
	}*/


	conf += "\n All images linked to gallery will also be deleted.\n This cannot be undone. Are you sure you want to continue?";
	if (confirm(conf)) {
		document.content_list_form.submit();
	}
}


function confirmContentDelete(){
	conf = "Warning: all content will be deleted from the page(s), including images if its a gallery. This can't be undone.  Are you sure you want to continue?";
	if (confirm(conf)) {
		document.content_list_form.submit();
		return true;
	} else {
	return false;
	}

}


/* * * * * * * * * * * * * * * * * * * * * * * * *\
  ##  	generic fuctions
\* * * * * * * * * * * * * * * * * * * * * * * * */
function number_format_post(mynumber) {
	var newno = ((mynumber * 1)) + .001;
	var tempno = newno.toString();
	var aNum = tempno.split(".");
	return (aNum[0] + '.' +  aNum[1].substr(0,2));
}

function rightTrim(sString)
{
while (sString.substring(sString.length-1, sString.length) == ' ')
{
sString = sString.substring(0,sString.length-1);
}
return sString;
}

function defaulttemplatesetting()
{

	document.getElementById('color').value="";
	document.getElementById('color_fg').value="";
	//document.getElementById('transparent').value = 0;
	document.getElementById("design-bg-form").submit();
	//document.design-bg-form.submit();
}

function transparentbackground()
{
	//document.getElementById('color').value=document.getElementById('hdnbgcolor').value;
	document.getElementById('color_fg').value="";
	document.getElementById('transparent').value = 1;
	$('#transparent_html').html("(currently set to transparent)");
	$('#color_fg').css('background-color', '#ffffff');
	$('#default_fg_html').html("");
	//document.getElementById("design-bg-form").submit();
}

function defaultfontsetting()
{
	document.getElementById('color').value="";
	document.getElementById("family").value = 0;
	document.getElementById("design-logo-form").submit();
}

function defaultbackgroundsetting()
{
	var radioObj=document.forms['design-bg-form'].elements['use_bg_image'];
	var newValue="yes";
	setCheckedValue(radioObj, newValue);
	document.getElementById('url').value="";
	document.getElementById('pos_x').value=document.getElementById('hdnpos_x').value;
	document.getElementById('pos_y').value=document.getElementById('hdnpos_y').value;
	document.getElementById('repeat').value=document.getElementById('hdnrepeat').value;
	document.getElementById("design-bg-form").submit();
	//document.getElementById('use_bg_image_y').checked="true";
	//document.getElementById('color_fg').value=document.getElementById('hdnforgroundcolor').value;
	//document.getElementById("design-bg-form").submit();
}

function setCheckedValue(radioObj, newValue) {
	if(!radioObj)
		return;
	var radioLength = radioObj.length;
	if(radioLength == undefined) {
		radioObj.checked = (radioObj.value == newValue.toString());
		return;
	}
	for(var i=0; i < radioLength; i++) {
		radioObj[i].checked = false;
		if(radioObj[i].value == newValue.toString()) {
			radioObj[i].checked = true;
		}
	}
}

function checkthumbsize()
{
	//alert(document.forms['content-page-form'].thumb_size.length);
for (var i=0; i < document.forms['content-page-form'].thumb_size.length; i++)
   {
   if (document.forms['content-page-form'].thumb_size[i].checked)
      {
      	var rad_val = document.forms['content-page-form'].thumb_size[i].value;
	  	if(rad_val=="standard")
				document.getElementById('display-sub-options').style.visibility="visible";
		else
				document.getElementById('display-sub-options').style.visibility="hidden";
      }
   }
   //alert("Hello");
}


function checkwizzardthumbsize()
{
	//alert(document.forms['content-page-form'].thumb_size.length);
for (var i=0; i < document.forms['content-form2'].thumb_size.length; i++)
   {
   if (document.forms['content-form2'].thumb_size[i].checked)
      {
      	var rad_val = document.forms['content-form2'].thumb_size[i].value;
	  	if(rad_val=="7519")
				document.getElementById('display-sub-options').style.visibility="visible";
		else
				document.getElementById('display-sub-options').style.visibility="hidden";
      }
   }
   //alert("Hello");
}

function displayBackground()
{
	//alert(document.forms['content-page-form'].thumb_size.length);
for (var i=0; i < document.forms['design-bg-form'].use_bg_image.length; i++)
   {
   if (document.forms['design-bg-form'].use_bg_image[i].checked)
      {
      	var rad_val = document.forms['design-bg-form'].use_bg_image[i].value;
	  	if(rad_val=="yes"){
				document.getElementById('display-bg-options').style.visibility="visible";
				document.getElementById('display-bg-options').style.height = "auto";
				document.getElementById('display-bg-options').style.overflow="visible";
		}
		else {
				document.getElementById('display-bg-options').style.visibility="hidden";
				document.getElementById('display-bg-options').style.height = "20px";
				document.getElementById('display-bg-options').style.overflow="hidden";
		}
      }
   }
   //alert("Hello");
}


function updatewidgetstatus(id,status,widname)
{
	//alert(widname);
	document.getElementById('id').value=id;
	document.getElementById('status').value=status;
	document.getElementById('widname').value=widname;
	document.getElementById('feature-widget-form').submit();

}


function updatewidgetstatus2(id,status,widname)
{
	//alert(widname);
	document.getElementById('id').value=id;
	document.getElementById('status').value=status;
	document.getElementById('widname').value=widname;
	setCookie('alink',id,1);
	document.getElementById('feature-widget-form').submit();

}

function setCookie(c_name,value,expiredays)
{
var exdate=new Date();
exdate.setDate(exdate.getDate()+expiredays);
document.cookie=c_name+ "=" +escape(value)+
((expiredays==null) ? "" : ";expires="+exdate.toUTCString());
}

function getCookie(c_name)
{
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=");
  if (c_start!=-1)
    {
    c_start=c_start + c_name.length+1;
    c_end=document.cookie.indexOf(";",c_start);
    if (c_end==-1) c_end=document.cookie.length;
    return unescape(document.cookie.substring(c_start,c_end));
    }
  }
return "";
}

function clslink()
{
	//alert("Hello");
	parent.$.fn.colorbox.close();
}


