// RM tools script file
// By Andy Driver 1/12/99
// andy@rivred.freeserve.co.uk

var namelistWindow ;
var namesearchWindow ;
var helpWindow ;

// namelist()
//  creates a popup window with list of readymade company names
function namelist() {
	if( namelistWindow == null ) {
		namelistWindow = open( "co_name_list.html", "namelistWindow", "directories=no,height=400,location=no,menubar=no,personalbar=no,resizable=yes,scrollbars=yes,status=no,toolbar=no,width=650" ) ;
		namelistWindow.scrollbars.visible = true ;
	}
	namelistWindow.focus() ;
}

// nameListItem( string )
//  loads the ready made company order form into the main window with
//  preinitialised fields
function nameListItem( item ) {
	bakeCookie( "coname", item ) ;
	top.opener.location.href = "co_order_ready_made.html" ;
	self.close() ;
}

function preinitializeForm() {
    var coname = tasteCookie( "coname" ) ;
    if( coname == null ) {
      	coname = " " ;
    }
	self.document.forms["form1"].coname.value = coname ;
	eatCookie( "coname" ) ;
}

// help( string )
//  creates a popup window with a document specified in the parameter
//  calls to this function while the window is still open change the
//  document within
function help( href ) {
	if( helpWindow != null ) {
		helpWindow.close() ;
	}
	helpWindow = open( href, "helpWindow", "directories=no,height=400,location=no,menubar=no,personalbar=no,resizable=yes,scrollbars=visible,status=no,toolbar=no,width=650" ) ;
	helpWindow.focus() ;
}

// namesearch()
//  calls up the companies house name search facility in a popup window
function namesearch() {
	if( namesearchWindow != null ) {
		namesearchWindow.close() ;
	}
	namesearchWindow = open( "co_name_search_frm.html", "namesearchWindow", "directories=no,height=480,location=no,menubar=no,personalbar=no,resizable=yes,scrollbars=visible,status=no,toolbar=no,width=640" ) ;
//	namesearchWindow = open( "http://www.companieshouse.co.uk/search/promo_cs_entry.ow", "namesearchWindow", "directories=no,outerheight=600,location=no,menubar=no,personalbar=no,resizable=yes,status=no,toolbar=no,width=800" ) ;
	namesearchWindow.focus() ;
}

// Cookie functions by Andy Driver 1/6/97
// bakeCookie( string, string, Date )
//  set a cookie - expiry date is one year from current time
function bakeCookie( name, value ) {
	sellByDate = new Date() ;
	sellByDate.setTime( sellByDate.getTime() + 365 * 24 * 60 * 60 * 1000 ) ; 
	document.cookie = name + "="
                           + escape( value )
                           + "; expires="
                           + sellByDate.toGMTString()
                           + "; path=/" ;
}

// eatCookie( string )
//  delete a cookie with the specified name
function eatCookie( name ) {
    var stale = new Date() ;
    stale.setTime( stale.getTime() - 1 ) ;
    document.cookie = name + "="
                           + "; expires="
                           + stale.toGMTString()
                           + "; path=/" ;
}

// tasteCookie( string )
//  get the value of the specified cookie
function tasteCookie( name ) {
    var cookieSize = document.cookie.length ;
    var i = 0 ;
    while( i < cookieSize ) {
        var valueBegin = i + name.length + 1 ;
        if( document.cookie.substring( i, valueBegin ) == name + "=" ) {
            var valueEnd = document.cookie.indexOf( ";", valueBegin ) ;
            if( valueEnd == -1 ) {
				valueEnd = document.cookie.length ;
			}
            return unescape( document.cookie.substring( valueBegin, valueEnd ) ) ;
        }
        i = document.cookie.indexOf( " ", i ) + 1 ;
        if( i == 0 ) {
			break ;
		}
    }
    return null ;
}

// companyPriceCalculate()
//  work out the price of the selected company formation
var rm_limited_liability = 135 ;
var rm_public = 350 ;
var change_of_name = 45 ;
var same_day_con = 210 ;
var tm_limited_liability = 138 ;
var tm_public = 350 ;
var tm_guarantee = 350 ;
var tm_property_management = 300 ;
var tm_same_day_incorporation = 295 ;

