browser_name = navigator.appName;
browser_version = parseFloat(navigator.appVersion);
if (browser_name == "Netscape" && browser_version < 3.0)
{
     roll = 'false';
}
else if (browser_name == "Netscape" && browser_version >= 3.0)
{
     roll = 'true';
}
else if (browser_name == "Microsoft Internet Explorer" && browser_version < 4.0)
{
     roll = 'false';
}
else if (browser_name == "Microsoft Internet Explorer" && browser_version >= 4.0)
{
     roll = 'true';
}
else
{
     roll = 'false';
}
//end browser check

// VARIABLES FOR POPUP WINDOWS
var agt = navigator.userAgent.toLowerCase(); 
var is_mac = (agt.indexOf("mac")!=-1);
var childWindow = "";
//generic open popup window function
function openpopup(URL,Features,Width,Height) {
	childWindow = window.open(URL, "child_window", Features+Width+",height="+Height);
	if (document.images)
	{
		childWindow.focus();
	}
}
//function for simple text popup
function openMsg(messageURL,messageWidth,messageHeight)
{
	popURL = messageURL;
	popFeatures = "directory=no,location=no,toolbar=no,scrollbars=yes,status=no,resizable=yes,width="
	popWidth = messageWidth;
	popHeight = messageHeight;
	if (childWindow.closed == false) {
		childWindow.close();
		if (is_mac) {
			setTimeout('openpopup(popURL,popFeatures,popWidth,popHeight)',500);
			return;
		}
	}
	openpopup(popURL,popFeatures,popWidth,popHeight);
}
//function for visual details popup
function openVisualDetailsWin(visualDetailsURL)
{
	popURL = visualDetailsURL;
	popFeatures = "directory=no,location=no,toolbar=no,scrollbars=yes,status=no,resizable=yes,width="
	popWidth = 540;
	popHeight = 420;
	if (childWindow.closed == false) {
		childWindow.close();
		if (is_mac) {
			setTimeout('openpopup(popURL,popFeatures,popWidth,popHeight)',500);
			return;
		}
	}
	openpopup(popURL,popFeatures,popWidth,popHeight);
}
//function for Quick Time VR
function openVisualDetailsWin1(visualDetailsURL)
{
	popURL = visualDetailsURL;
	popFeatures = "directory=no,location=no,toolbar=no,scrollbars=yes,status=no,resizable=yes,width="
	popWidth = 540;
	popHeight = 440;
	if (childWindow.closed == false) {
		childWindow.close();
		if (is_mac) {
			setTimeout('openpopup(popURL,popFeatures,popWidth,popHeight)',500);
			return;
		}
	}
	openpopup(popURL,popFeatures,popWidth,popHeight);
}

function openVLPhotoWin(photoimgURL)
{
    popURL = photoimgURL;
	popFeatures = "directory=no,location=no,toolbar=no,scrollbars=yes,status=no,resizable=yes,width="
	popWidth = 350;
	popHeight = 250;
	if (childWindow.closed == false) {
		childWindow.close();
		if (is_mac) {
			setTimeout('openpopup(popURL,popFeatures,popWidth,popHeight)',500);
			return;
		}
	}
	openpopup(popURL,popFeatures,popWidth,popHeight);
}
//function for tech details popup
function openTechDetailsWin(techDetailsURL)
{
	popURL = techDetailsURL;
	popFeatures = "directory=no,location=no,toolbar=no,scrollbars=yes,status=no,resizable=yes,width="
	popWidth = 530;
	popHeight = 420;
	if (childWindow.closed == false) {
		childWindow.close();
		if (is_mac) {
			setTimeout('openpopup(popURL,popFeatures,popWidth,popHeight)',500);
			return;
		}
	}
	openpopup(popURL,popFeatures,popWidth,popHeight);
}
//function for ADAPTiQ popup
function openBundlepopup(AdaptiqURL)
{
	popURL = AdaptiqURL;
	popFeatures = "directory=no,location=no,toolbar=no,scrollbars=yes,status=no,resizable=yes,width="
	popWidth = 530;
	popHeight = 600;
	if (childWindow.closed == false) {
		childWindow.close();
		if (is_mac) {
			setTimeout('openpopup(popURL,popFeatures,popWidth,popHeight)',500);
			return;
		}
	}
	openpopup(popURL,popFeatures,popWidth,popHeight);
}

//function for product comparison chart popup
var compareURL = "/home_audio/wave_systems/cc_wave_systems.html";
var compareWidth = 475;
var compareHeight = 362;
function openCompareProducts(compareURL, compareWidth, compareHeight)
{
	var i = 45;
	var j = 30;
	popWidth = compareWidth + i;
	popHeight = compareHeight +j;
	popURL = compareURL;
	popFeatures = "directory=no,location=no,toolbar=no,scrollbars=yes,status=no,resizable=yes,width="
	if (childWindow.closed == false) {
		childWindow.close();
		if (is_mac) {
			setTimeout('openpopup(popURL,popFeatures,popWidth,popHeight)',500);
			return;
		}		
	}
	openpopup(popURL,popFeatures,popWidth,popHeight);
}


//double function for see it bigger popup
//---------------------------------------
function openSibWin(sibImageSource, sibImageTitle, sibImageWidth, sibImageHeight)
{
	Source = sibImageSource;
	Title = sibImageTitle
	Width = sibImageWidth;
	Height = sibImageHeight;
	if (childWindow.closed == false) {
		childWindow.close();
		if (is_mac) {
			setTimeout('openSibWinPartII(Source, Title, Width, Height)',500);
			return;
		}
	}
	openSibWinPartII(Source, Title, Width, Height);
}
function openSibWinPartII(ImageSource, ImageTitle, ImageWidth, ImageHeight) {
	var i = 45;
	var j = 30;
	popWidth = ImageWidth + i;
	popHeight = ImageHeight + j;
	header = "<HTML><HEAD><TITLE>"+ImageTitle+"</TITLE></HEAD>";
	body = "<BODY BGCOLOR=\"#FFFFFF\"><CENTER><IMG SRC=\""+ImageSource+"\" WIDTH=\""+ImageWidth+"\" HEIGHT=\""+ImageHeight+"\"></CENTER>";
	footer = "</BODY></HTML>";
	childWindow = window.open(ImageSource, "child_window", "directory=no,location=no,toolbar=no,scrollbars=yes,status=no,resizable=no,width="+popWidth+",height="+popHeight);
	if (!is_mac)
	{
		childWindow.document.open();
		childWindow.document.write(header);
		childWindow.document.write(body);
		childWindow.document.write(footer);
		childWindow.document.close();
	}
	if (document.images)
	{
		childWindow.focus();
	}
}


//function for product pulldown selection list
function formHandler()
{
	var URL = document.form.URL.options[document.form.URL.selectedIndex].value;
	//window.location.href = URL;
	if (URL != '') {
		window.location.href = URL;
	}
	else {
		document.form.URL.options[0].selected = true;
	}
}
//------------------------------------------------------------
//START FUNCTIONS AND SUBFUNCTIONS FOR TRANSACTION PROCESS
//------------------------------------------------------------

//MUST pass ProductID to product availability page
function productAvailRedirect(ProductID)
{
	window.location.href = "https://203.196.145.245/shopping/product_availability.asp?ProductId="+ProductID;
	//window.location.href = "https://secure-www2.bose.de/shopping/product_availability.asp?ProductId="+ProductID;

}

//MUST pass ProductID to product Nonavailability page
function productNonAvailRedirect(ProductID)
{
	window.location.href = "http://203.196.145.245/shopping/product_noavail.asp?ProductId="+ProductID;
	//window.location.href = "http://www.bose.de/shopping/product_noavail.asp?ProductId="+ProductID;
}

// This section is used for Search Functionality 

// Function to check if the search field is empty while searching
function check()
{
if (document.Search.SearchString.value=="")
  {
  alert("Please Enter in Suche")
  return false;
  }
 document.form.submit();
 }

// Function to jump to a particular page in the search results
function fnGoToPage(p)
{
  document.formSearch.pg.value = p;
  document.formSearch.submit();
}

// Function to jump to a particular page in the search results
function fnGoToPrevious()
{
  document.formSearch.pg.value = (document.formSearch.pg.value * 1) - 1;
  if (document.formSearch.pg.value < document.formSearch.pgStart.value)
  {
    document.formSearch.pg.value = 1
  }
  document.formSearch.submit();
}

// Function to jump to next page in search results 
function fnGoToNext()
{
  var iTmp
  iTmp = (document.formSearch.pgStart.value * 1) + 1 ;
  document.formSearch.pg.value = (document.formSearch.pg.value * 1) + 1; 
  if ((document.formSearch.pg.value > document.formSearch.pgCount.value) && (document.formSearch.pgCount.value < document.formSearch.pgEnd.value))
  { document.formSearch.pg.value = document.formSearch.pgCount.value; 
  }
  document.formSearch.submit();
}


//-----------------------------------------------------------------------------------------
//-----------------------Customer Preferences Form-----------------------------------------
//Email validation for the customer preferences form
var NoEmailIDEntered = "Invalid E-Mail Address";

//Function used to validate emails
function emailCheck (Objectname,Caption) {

Objectname = eval(Objectname);

/* The following variable tells the rest of the function whether or not
to verify that the address ends in a two-letter country or well-known
TLD.  1 means check it, 0 means don't. */

var emailStr 
emailStr = Objectname.value;
var checkTLD=0;


/* The following is the list of known TLDs that an e-mail address must end with. */

var knownDomsPat=/^(de|com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;

/* The following pattern is used to check if the entered e-mail address
fits the user@domain format.  It also is used to separate the username
from the domain. */

var emailPat=/^(.+)@(.+)$/;

/* The following string represents the pattern for matching all special
characters.  We don't want to allow special characters in the address. 
These characters include ( ) < > @ , ; : \ " . [ ] */

var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";

/* The following string represents the range of characters allowed in a 
username or domainname.  It really states which chars aren't allowed.*/

var validChars="\[^\\s" + specialChars + "\]";

/* The following pattern applies if the "user" is a quoted string (in
which case, there are no rules about which characters are allowed
and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
is a legal e-mail address. */

var quotedUser="(\"[^\"]*\")";

/* The following pattern applies for domains that are IP addresses,
rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
e-mail address. NOTE: The square brackets are required. */

var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;

/* The following string represents an atom (basically a series of non-special characters.) */

var atom=validChars + '+';

/* The following string represents one word in the typical username.
For example, in john.doe@somewhere.com, john and doe are words.
Basically, a word is either an atom or quoted string. */

var word="(" + atom + "|" + quotedUser + ")";

// The following pattern describes the structure of the user

var userPat=new RegExp("^" + word + "(\\." + word + ")*$");

/* The following pattern describes the structure of a normal symbolic
domain, as opposed to ipDomainPat, shown above. */

var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");

/* Finally, let's start trying to figure out if the supplied address is valid. */

/* Begin with the coarse pattern to simply break up user@domain into
different pieces that are easy to analyze. */

var matchArray=emailStr.match(emailPat);

if (matchArray==null) {

/* Too many/few @'s or something; basically, this address doesn't
even fit the general mould of a valid e-mail address. */

alert(Caption);
Objectname.focus();
Objectname.select();
return false;
}
var user=matchArray[1];
var domain=matchArray[2];

// Start by checking that only basic ASCII characters are in the strings (0-127).

for (i=0; i<user.length; i++) {
if (user.charCodeAt(i)>127) {
alert(Caption);
Objectname.focus();
Objectname.select();
return false;
   }
}
for (i=0; i<domain.length; i++) {
if (domain.charCodeAt(i)>127) {
alert(Caption);
Objectname.focus();
Objectname.select();
return false;
   }
}

// See if "user" is valid 

if (user.match(userPat)==null) {

// user is not valid

alert(Caption);
Objectname.focus();
Objectname.select();
return false;
}

/* if the e-mail address is at an IP address (as opposed to a symbolic
host name) make sure the IP address is valid. */

var IPArray=domain.match(ipDomainPat);
if (IPArray!=null) {

// this is an IP address

for (var i=1;i<=4;i++) {
if (IPArray[i]>255) {
alert(Caption);
Objectname.focus();
Objectname.select();
return false;
   }
}
return true;
}

// Domain is symbolic name.  Check if it's valid.
 
var atomPat=new RegExp("^" + atom + "$");
var domArr=domain.split(".");
var len=domArr.length;
for (i=0;i<len;i++) {
if (domArr[i].search(atomPat)==-1) {
alert(Caption);
Objectname.focus();
Objectname.select();
return false;
   }
}

/* domain name seems valid, but now make sure that it ends in a
known top-level domain (like com, edu, gov) or a two-letter word,
representing country (uk, nl), and that there's a hostname preceding 
the domain or country. */

if (checkTLD && domArr[domArr.length-1].length!=2 && 
domArr[domArr.length-1].search(knownDomsPat)==-1) {
alert(Caption);
Objectname.focus();
Objectname.select();
return false;
}

// Make sure there's a host name preceding the domain.

if (len<2) {
alert(Caption);
Objectname.focus();
Objectname.select();
return false;
}

// If we've gotten this far, everything's valid!
return true;
}

//Function to validate numbers in the telephone field
var InvalidNumeric = "Podano złą wartość dla pola: ";

function NumberValidate(objectName,ObjectCaption) 
{ 
	var numStr="1234567890 -()";
	var thisChar;
	var counter=0;
	var data = objectName.value;
	
	for(var i=0; i < data.length; i++)
		{
			thisChar=data.substring(i,i+1);
			if(numStr.indexOf(thisChar)!=-1)
			{counter++;}
		}
	if(counter==data.length)
	{return true;}
	else {
		alert(InvalidNumeric + ObjectCaption);
		objectName.focus();
		objectName.select();		
		return false;
	}
}

//Function used to validate form data for customer preferences form
function ValidateForm(input)
{
	var requiredFields
	var fieldNames

	/*
	if ((window.document.frmCustPref.optEMailPref[0].checked == true)&& (window.document.frmCustPref.cboCountry.options[document.frmCustPref.cboCountry.selectedIndex].value == "GB")){
		requiredFields = new Array("txtFirstName","txtSurname","txtAddress1","txtCity","txtCounty","txtPostalCode","txtEmail");
		fieldNames = new Array("First Name ","Surname","Address Line 1","Postal Town/City","County","Postal Code","Email Address");
	 }	
	else if ((window.document.frmCustPref.optEMailPref[0].checked == true) && (window.document.frmCustPref.cboCountry.options[document.frmCustPref.cboCountry.selectedIndex].value == "IE")){
		requiredFields = new Array("txtFirstName","txtSurname","txtAddress1","txtCity","txtCounty","txtEmail");
		fieldNames = new Array("First Name ","Surname","Address line one","Postal Town/City","County","Email Address");
	}
	else if ((window.document.frmCustPref.optEMailPref[0].checked == false) && (window.document.frmCustPref.cboCountry.options[document.frmCustPref.cboCountry.selectedIndex].value == "GB")){
		requiredFields = new Array("txtFirstName","txtSurname","txtAddress1","txtCity","txtCounty","txtPostalCode");
		fieldNames = new Array("First Name ","Surname","Address line one","Postal Town/City","County","Postal Code");
	 }	
	else if ((window.document.frmCustPref.optEMailPref[0].checked == false)&& (window.document.frmCustPref.cboCountry.options[document.frmCustPref.cboCountry.selectedIndex].value == "IE")){
		requiredFields = new Array("txtFirstName","txtSurname","txtAddress1","txtCity","txtCounty");
		fieldNames = new Array("First Name ","Surname","Address line one","Postal Town/City","County");
	}	
	*/
	
	if (window.document.frmCustPref.optEMailPref[0].checked == true){
		requiredFields = new Array("txtFirstName","txtSurname","txtAddress1","txtCity","txtPostalCode","txtEmail");
		fieldNames = new Array("First Name ","Surname","Address Line 1","Postal Town/City","Postal Code","Email Address");
	 }	
	else {
		requiredFields = new Array("txtFirstName","txtSurname","txtAddress1","txtCity","txtPostalCode");
		fieldNames = new Array("First Name ","Surname","Address line one","Postal Town/City","Postal Code");
	 }	
	 
	var fieldCheck = true;
	var fieldfocus = true;
	var setFieldNum =0 ;
	var nCounter =0;
	var showfieldNames;
	var fieldsNeeded = "\nInformation must be entered in the following fields:\n\n\t"
	
	showfieldNames = '';
    for(var fieldNum =0; fieldNum < requiredFields.length ; fieldNum++) {		
        if ((input.elements[requiredFields[fieldNum]].value == "") ||
            (input.elements[requiredFields[fieldNum]].value == " ")||
			(input.elements[requiredFields[fieldNum]].value.replace(/ /g,"")=="")) 
		{
		   	showfieldNames += fieldNames[fieldNum] + "\n\t";
				fieldCheck = false;
		   
            if (fieldfocus == true)
            {
				fieldfocus = false;
				setFieldNum = fieldNum;
            }
            nCounter++;
        }
        else fieldCheck = true;
    }
	
	if (fieldCheck == false || nCounter > 0)
    {		
		alert(fieldsNeeded + showfieldNames);
		input.elements[requiredFields[setFieldNum]].focus();
        return false;
    }
    else if (fieldCheck == true)
    {	
		if (window.document.frmCustPref.optEMailPref[0].checked == true && emailCheck("document.frmCustPref.txtEmail",NoEmailIDEntered)==false){
				window.document.frmCustPref.txtEmail.focus();
				return false; 
		}	
		else if (window.document.frmCustPref.optPhonePref[0].checked == true && window.document.frmCustPref.txtPhone.value == ""){
				alert("Please enter Phone Number.")
				window.document.frmCustPref.txtPhone.focus();
				return false; 
		}	
		else if ((document.frmCustPref.txtPhone.value != "") && (NumberValidate(document.frmCustPref.txtPhone,"Phone") == false))
		{
				window.document.frmCustPref.txtPhone.focus();
				return false;
		}
		else if ((window.document.frmCustPref.txtEmail.value != "") && (emailCheck("document.frmCustPref.txtEmail",NoEmailIDEntered) != true)){
				window.document.frmCustPref.txtEmail.focus();
				return false;
		}
		else {
			return true;
		}	
	}
	else {
		return true;
	}
	
}


//Function instantiated when the submit button is clicked in customer preferences form 
function MailSend()
{
	if (ValidateForm(document.frmCustPref)) {
		window.document.frmCustPref.hdSendMail.value = "1";
		window.document.frmCustPref.submit();
	}
	//else{return false;}
}

