function jLaunchWindow( sURL, sWidth, sHeight ){
	sParams = "'directories=no,height=300,location=no,menubar=no,resizable=yes,scrollbars=yes,status=no,width=" + sWidth + ",height=" + sHeight + ",toolbar=no'"
	 newWin = window.open( sURL,'Help', sParams);
}

function jfIsValid( sValue, strValidChars  ) {
	var isValid = new Boolean()
	isValid=true
	var myChar=""
	var myInt=0

	if (sValue!="" && typeof(sValue)=="string") {
		for (i=0;i<sValue.length;i++) {
			myChar=sValue.charAt(i)
			myInt=strValidChars.indexOf(myChar)

			if (myInt == -1) {
				isValid=false
				break;
			}
		}
	}
	else {
		isValid=false
	}

	return isValid
}

function jfIsDate(data,datename)
{

// function created : 31.12.03
// created by 		: Farrakh Aslam
// input paramaters : data     - the formname
//datename - the fieldname specified when calling the vbscript date box function
// description      : Can be used to validate any of the vbscript date box functions
data = "document." + data + "."

var day   = eval( data + datename + "_d.value")
var month = eval( data + datename + "_m.value")
var year  = eval( data + datename + "_y.value")

var calcYear = (year % 4 == 0)
if (!calcYear)
	{
	leapDays = 28
	}
else
	{
	leapDays = 29
	}

if (month == 02)
	{
	if (day > leapDays)
	   {
	   return false;
	   }


	}
else if (month == 04 || month == 06 || month == 09 || month == 11)
	{
	if (day > 30)
	   {
	   return false;
	   }

	}
return true;
}

function jfIsEmail(incoming) {

	var emailstring = incoming;
	var ampIndex = emailstring.indexOf("@");
	var afterAmp = emailstring.substring((ampIndex + 1), emailstring.length);
		// find a dot in the portion of the string after the ampersand only
	var dotIndex = afterAmp.indexOf(".");
		// determine dot position in entire string (not just after amp portion)
	dotIndex = dotIndex + ampIndex + 1;
		// afterAmp will be portion of string from ampersand to dot
	afterAmp = emailstring.substring((ampIndex + 1), dotIndex);
		// afterDot will be portion of string from dot to end of string
	var afterDot = emailstring.substring((dotIndex + 1), emailstring.length);
	var beforeAmp = emailstring.substring(0,(ampIndex));

	var email_regex = /^\w(?:\w|-|\.(?!\.|@))*@\w(?:\w|-|\.(?!\.))*\.\w{2,3}/
		// index of -1 means "not found"
	if ((emailstring.indexOf("@") != "-1") &&
		(emailstring.length > 5) &&
		(afterAmp.length > 0) &&
		(beforeAmp.length > 1) &&
		(afterDot.length > 1) &&
		(email_regex.test(emailstring)) ) {
		  return true;
	} 
	else {
			return false;
	}
}

function jfIsPhoneNum( sValue ) {

	var isPhoneNum = new Boolean()
	isPhoneNum=true
	var myChar=""
	var myInt=0
	var strValidChars = "0123456789 ";

	if (sValue!="" && typeof(sValue)=="string") {
		for (i=0;i<sValue.length;i++) {
			myChar=sValue.charAt(i)
			myInt=strValidChars.indexOf(myChar)

			if (myInt == -1) {
				isPhoneNum=false
			}
		}

	} else {
		isPhoneNum=false
	}
	
	return isPhoneNum
}

function jfIsInt( sValue ) {
	var isInteger = new Boolean()
	isInteger=true
	var myChar=""
	var myInt=0

	if (sValue!="" && typeof(sValue)=="string") {
		for (i=0;i<sValue.length;i++) {
			myChar=sValue.charAt(i)
			myInt=parseInt(myChar)

			if (isNaN(myInt)) {
				isInteger=false
			}
		}

	} else {
		isInteger=false
	}

	return isInteger
}

function jsubmitnews(){
	frm = document.frmNews

	if( frm.txtNewsEmail.value == "" ){
		alert("Please enter a valid email address.")
	}
	else if( jfIsEmail(frm.txtNewsEmail.value) == false ){
		alert("Please enter a valid email address.")
	}
	else{
		frm.submit()
	}
}

function jcharacterlimit( iMax ){
	frm = document.frmComment
	if( frm.txtComment.value.length > iMax ){
		alert("The comment can not be greater than " + iMax + " charcters in length.")
	}
}

function jsumbitcomment( iMax ){
	frm = document.frmComment
	if( frm.txtComment.value.length > iMax ){
		alert("The comment can not be greater than " + iMax + " charcters in length.")
	}
	else{
		frm.submit()
	}
}

//	////////
//	DEAL.ASP
//	////////

function jSwapImage( iView ){

	if(document.images) {
		var swapImage = document.getElementById('img_product');
		swapImage.src = eval("lrg_"+iView+".src");
	}
}

function jsubmitdeal( iProduct, iAction ){
	frm = document.frmBuy

	iDealType = frm.txtDealType.value

	iProduct1 = frm.txtProduct1.value
	sItem1 = frm.txtItemName1.value

	if ( frm.optColor1.value == 0 ){
		alert("Please select a colour for " + sItem1 + ".")
		return;
	}

	if ( iProduct1 == 1){
		if ( frm.optSize1.value == 0 && iProduct1 == 1){
			alert("Please select a size for " + sItem1 + ".")
			return;
		}
	}

	if ( iDealType == 2 ){
		iProduct2 = frm.txtProduct2.value
		sItem2 = frm.txtItemName2.value

		if ( frm.optColor2.value == 0 ){
			alert("Please select a colour for " + sItem2 + ".")
			return;
		}
		if( iProduct2 == 1){
			if ( frm.optSize2.value == 0){
				alert("Please select a size for " + sItem2 + ".")
				return;
			}
		}
	}

	if ( iAction == 1 ) {
		frm.action ="basket.asp"
	}
	else if ( iAction == 2 ) {
		frm.action ="favourites.asp?txtMode=2"
	}
	frm.submit()
}


//	////////
//	ITEM.ASP
//	////////

//	also uses jSwapImge from deal.asp

function jsubmititem( iProduct, iAction ){
	frm = document.frmBuy
	iProduct = frm.txtProduct.value

	if ( frm.optColor.value == 0 ){
		alert("Please select a colour.")
		return;
	}

	if(iProduct==1){
		if ( frm.optSize.value == 0 ){
			alert("Please select a size.")
			return;
		}
	}

	if ( iAction == 1 ) {
		frm.action ="basket.asp"
	}
	else if ( iAction == 2 ) {
		frm.action ="favourites.asp?txtMode=1"
	}
	frm.submit()


}

function jchangecolor(){
	frm = document.frmBuy
	frm.action ="item.asp"
	frm.submit()
}



//	//////////////
//	BASKET.ASP
//	//////////////

function jsubmitbasket(){
	frm = document.frmOrder
	//frm.action="https://www.secure-server-hosting.com/secutran/secuitems.php"

	frm.submit()
}

//	//////////////
//	SEARCH.ASP
//	//////////////

function jMovePage( iPage ){
	frm = document.frmSearch
	iMaxPage = frm.txtMaxPage.value
	if ( iPage == 0 ){
		iPage = 1
	}
	else if ( iPage >= iMaxPage ){
		iPage = iMaxPage
	}
	frm.txtPage.value = iPage
	frm.submit();
}


//	//////////////
//	CONTACTUS.ASP
//	//////////////

function jsubmitcontactus(){
	frm = document.frmContactUs
	var iError = -1
	cssNormal = "textnormal"
	cssRequired =  'textred'
	cssInvalid =  'textblue'

	sAlpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz- '()"


	// First Name //
	if (frm.txtName.value ==""){
		if ( iError == -1 ){ frm.txtName.focus()}
		iError = 1
		document.getElementById( 'tr_1' ).className = cssRequired
		alert("Please enter your first name.")
		return;
	}
	else if (frm.txtName.value.length < 3){
		if ( iError == -1 ){ frm.txtName.focus()}
		iError = 1
		document.getElementById( 'tr_1' ).className = cssInvalid
		alert("Your first name must be greater than 3 characters in length.")
		return;
	}
	else if (jfIsValid (frm.txtName.value, sAlpha) == false){
		if ( iError == -1 ){frm.txtName.focus()}
		iError = 1
		document.getElementById( 'tr_1' ).className = cssInvalid
		alert("Your first name must contain alphabetic characters only.")
		return;
	}
	else {
		document.getElementById( 'tr_1' ).className = cssNormal
	}

// Home Tel //
	if ( frm.txtHomeTel.value.length < 11 ){
		if ( iError == -1 ){ frm.txtHomeTel.focus()}
		iError = 9
		document.getElementById( 'tr_2' ).className = cssRequired
		alert("Please enter a valid home phone number.")
		return;
	}
	else if ( jfIsPhoneNum(frm.txtHomeTel.value) == false){
		if ( iError == -1 ){ frm.txtHomeTel.focus()}
		iError = 9
		document.getElementById( 'tr_2' ).className = cssInvalid
		alert("Please enter a valid home phone number.")
		return;
	}
	else {
		document.getElementById( 'tr_2' ).className = cssNormal
	}

	// Email Address //
	if ( frm.txtEmail.value == ""){
		if ( iError == -1 ){ frm.txtEmail.focus()}
		iError = 8
		document.getElementById( 'tr_4' ).className = cssRequired
		alert("Please enter your email address.")
		return;
	}
	else if ( jfIsEmail(frm.txtEmail.value) == false){
		if ( iError == -1 ){ frm.txtEmail.focus()}
		iError = 8
		document.getElementById( 'tr_4' ).className = cssInvalid
		alert("Please enter a valid email address.")
		return;
	}
	else {
		document.getElementById( 'tr_4' ).className = cssNormal
	}

//===Submit form if no errors found ===/

	if ( iError == -1 ){
		frm.submit();
	}

}


//	//////////////
//	ACCOUNT.ASP
//	//////////////

function jNext( iMode ){
	frm = document.frmAccount
	frm.txtMode.value = iMode
	frm.submit();
}

function jBack( iMode ){
	frm = document.frmAccount
	frm.txtMode.value = iMode
	frm.txtStep.value = 1

	frm.submit();
}

function jfHelp( iHelp ){

}

function jsubmitaccount( iMode ){
	frm = document.frmAccount
	var iError = -1
	cssNormal = "textnormal"
	cssRequired =  'textred'
	cssInvalid =  'textblue'

	sAlpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz- '()"

// ==== Personal Details ==== //
	// Title //
	if (frm.optTitle.value ==0){
		if ( iError == -1 ){frm.optTitle.focus()}
		iError = 0
		document.getElementById( 'tr_1' ).className = cssRequired
		alert("Please select your title.")
		return;
	}
	else {
		document.getElementById( 'tr_1' ).className = cssNormal
	}


	// First Name //
	if (frm.txtFirstName.value ==""){
		if ( iError == -1 ){ frm.txtFirstName.focus()}
		iError = 1
		document.getElementById( 'tr_2' ).className = cssRequired
		alert("Please enter your first name.")
		return;
	}
	else if (frm.txtFirstName.value.length < 3){
		if ( iError == -1 ){ frm.txtFirstName.focus()}
		iError = 1
		document.getElementById( 'tr_2' ).className = cssInvalid
		alert("Your first name must be greater than 3 characters in length.")
		return;
	}
	else if (jfIsValid (frm.txtFirstName.value, sAlpha) == false){
		if ( iError == -1 ){frm.txtFirstName.focus()}
		iError = 1
		document.getElementById( 'tr_2' ).className = cssInvalid
		alert("Your first name must contain alphabetic characters only.")
		return;
	}
	else {
		document.getElementById( 'tr_2' ).className = cssNormal
	}

	// Surname //
	if (frm.txtLastName.value ==""){
		if ( iError == -1 ){ frm.txtLastName.focus()}
		iError = 2
		document.getElementById( 'tr_3' ).className = cssRequired
		alert("Please enter your last name.")
		return;
	}
	else if (frm.txtLastName.value.length < 3){
		if ( iError == -1 ){ frm.txtLastName.focus()}
		iError = 2
		document.getElementById( 'tr_3' ).className = cssInvalid
		alert("Your last name must be greater than 3 characters in length.")
		return;
	}
	else if (jfIsValid (frm.txtLastName.value, sAlpha) == false){
		if ( iError == -1 ){ frm.txtLastName.focus()}
		iError = 2
		document.getElementById( 'tr_3' ).className = cssInvalid
		alert("Your last name must contain alphabetic characters only.")
		return;
	}
	else {
		document.getElementById( 'tr_3' ).className = cssNormal
	}

	// Email Address //
	if ( frm.txtEmail.value == ""){
		if ( iError == -1 ){ frm.txtEmail.focus()}
		iError = 8
		document.getElementById( 'tr_4' ).className = cssRequired
		alert("Please enter your email address.")
		return;
	}
	else if ( jfIsEmail(frm.txtEmail.value) == false){
		if ( iError == -1 ){ frm.txtEmail.focus()}
		iError = 8
		document.getElementById( 'tr_4' ).className = cssInvalid
		alert("Please enter a valid email address.")
		return;
	}
	else {
		document.getElementById( 'tr_4' ).className = cssNormal
	}
// Home Tel //
	if ( frm.txtPhone.value.length < 11 ){
		if ( iError == -1 ){ frm.txtPhone.focus()}
		iError = 9
		document.getElementById( 'tr_5' ).className = cssRequired
		alert("Please enter a valid phone number.")
		return;
	}
	else if ( jfIsPhoneNum(frm.txtPhone.value) == false){
		if ( iError == -1 ){ frm.txtPhone.focus()}
		iError = 9
		document.getElementById( 'tr_5' ).className = cssInvalid
		alert("Please enter a valid phone number.")
		return;
	}
	else {
		document.getElementById( 'tr_5' ).className = cssNormal
	}

// House Number //
	if ( frm.txtAdd1.value == ""){
		if ( iError == -1 ){ frm.txtAdd1.focus()}
		iError = 12
		document.getElementById( 'tr_6' ).className = cssRequired
		alert("Please enter the first line of your address.")
		return;
	}
	else {
		document.getElementById( 'tr_6' ).className = cssNormal
	}
// City //
	if ( frm.txtCity.value == "" ){
		if ( iError == -1 ){ frm.txtCity.focus()}
		iError = 14
		document.getElementById( 'tr_8' ).className = cssRequired
		alert("Please enter your town/city.")
		return;
	}
	else {
		document.getElementById( 'tr_8' ).className = cssNormal
	}

// County //
	if ( frm.txtCounty.value == "" ){
		if ( iError == -1 ){ frm.txtCounty.focus()}
		iError = 15
		document.getElementById( 'tr_9' ).className = cssRequired
		alert("Please enter your county.")
		return;
	}
	else {
		document.getElementById( 'tr_9' ).className = cssNormal
	}

// Postcode //
	if ( frm.txtPostcode.value == "" ){
		if ( iError == -1 ){ frm.txtPostcode.focus()}
		iError = 16
		document.getElementById( 'tr_10').className = cssRequired
		alert("Please enter your postcode.")
		return;
	}
	else if ( frm.txtPostcode.value.length < 6 ){
		if ( iError == -1 ){ frm.txtPostcode.focus()}
		iError = 16
		document.getElementById( 'tr_10').className = cssInvalid
		alert("Please enter a valid postcode.")
		return;
	}
	else {
		document.getElementById( 'tr_10' ).className = cssNormal
	}

//===Submit form if no errors found ===/

	if ( iError == -1 ){
		frm.txtMode.value = iMode
		frm.submit();
	}
}


function jfIsDate(data,datename)
{

// function created : 31.12.03
// created by 		: Farrakh Aslam
// input paramaters : data     - the formname
//					  datename - the fieldname specified when calling the vbscript date box function
// description      : Can be used to validate any of the vbscript date box functions

var day   = eval("data." + datename + "_d.value")
var month = eval("data." + datename + "_m.value")
var year  = eval("data." + datename + "_y.value")


var calcYear = (year % 4 == 0)
if (!calcYear)
	{
	leapDays = 28
	}
else
	{
	leapDays = 29
	}

if (month == 02)
	{
	if (day > leapDays)
	   {
	   return false;
	   }
	}
else if (month == 04 || month == 06 || month == 09 || month == 11)
	{
	if (day > 30)
	   {
	   return false;
	   }

	}
return true;
}