// Flash Version Detector  v1.1.5
// http://www.dithered.com/javascript/flash_detect/index.htm
// code by Chris Nott
// with VBScript code from Alastair Hamilton

var flashVersion = 0;
function getFlashVersion() {
	var agent = navigator.userAgent.toLowerCase(); 
	
   // NS3 needs flashVersion to be a local variable
   if (agent.indexOf("mozilla/3") != -1 && agent.indexOf("msie") == -1) {
      flashVersion = 0;
   }
   
	// NS3+, Opera3+, IE5+ Mac (support plugin array):  check for Flash plugin in plugin array
	if (navigator.plugins != null && navigator.plugins.length > 0) {
		var flashPlugin = navigator.plugins['Shockwave Flash'];
		if (typeof flashPlugin == 'object') { 
			if (flashPlugin.description.indexOf('9.') != -1) flashVersion = 9;
			else if (flashPlugin.description.indexOf('8.') != -1) flashVersion = 8;
			else if (flashPlugin.description.indexOf('7.') != -1) flashVersion = 7;
			else if (flashPlugin.description.indexOf('6.') != -1) flashVersion = 6;
			else if (flashPlugin.description.indexOf('5.') != -1) flashVersion = 5;
			else if (flashPlugin.description.indexOf('4.') != -1) flashVersion = 4;
			else if (flashPlugin.description.indexOf('3.') != -1) flashVersion = 3;
		}
	}

	// IE4+ Win32:  attempt to create an ActiveX object using VBScript
	else if (agent.indexOf("msie") != -1 && parseInt(navigator.appVersion) >= 4 && agent.indexOf("win")!=-1 && agent.indexOf("16bit")==-1) {
	   document.write('<scr' + 'ipt language="VBScript"\> \n');
		document.write('on error resume next \n');
		document.write('dim obFlash \n');
		document.write('set obFlash = CreateObject("ShockwaveFlash.ShockwaveFlash.9") \n');
		document.write('if IsObject(obFlash) then \n');
		document.write('flashVersion = 9 \n');
		document.write('else set obFlash = CreateObject("ShockwaveFlash.ShockwaveFlash.8") end if \n');
		document.write('if flashVersion < 9 and IsObject(obFlash) then \n');
		document.write('flashVersion = 8 \n');
		document.write('else set obFlash = CreateObject("ShockwaveFlash.ShockwaveFlash.7") end if \n');
		document.write('if flashVersion < 8 and IsObject(obFlash) then \n');
		document.write('flashVersion = 7 \n');
		document.write('else set obFlash = CreateObject("ShockwaveFlash.ShockwaveFlash.6") end if \n');
		document.write('if flashVersion < 7 and IsObject(obFlash) then \n');
		document.write('flashVersion = 6 \n');
		document.write('else set obFlash = CreateObject("ShockwaveFlash.ShockwaveFlash.5") end if \n');
		document.write('if flashVersion < 6 and IsObject(obFlash) then \n');
		document.write('flashVersion = 5 \n');
		document.write('end if');
		document.write('</scr' + 'ipt\> \n');
	}
		
	// WebTV 2.5 supports flash 3
	else if (agent.indexOf("webtv/2.5") != -1) flashVersion = 3;

	// older WebTV supports flash 2
	else if (agent.indexOf("webtv") != -1) flashVersion = 2;

	// Can't detect in all other cases
	else {
		flashVersion = flashVersion_DONTKNOW;
	}

	return flashVersion;
}

flashVersion_DONTKNOW = -1;function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
	var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
	if (a[i].indexOf('#')!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function MM_findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf('?'))>0&&parent.frames.length) {
	d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function show_help(page){
	var myWin = open('help.pl?page=' + page, 'HelpWin','menubar=no,toolbar=no,status=no,dependent=yes,scrollbars=no,resizable=no,width=500,height=400');
	myWin.focus();
}
function password_reminder(email) {
	if (email == '') {
		alert('Please enter your email address');
	} else {
		var myWin = open('member_password_reminder.pl?ordPurEmail=' + email, 'Pass','menubar=no,toolbar=no,status=no,dependent=yes,scrollbars=yes,resizable=no,width=400,height=300');
		myWin.focus();
	}
}
function login_popup(frame) {
	var myWin = open('member_login_popup.pl?frame=' + frame, 'Login','menubar=no,toolbar=no,status=no,dependent=yes,scrollbars=yes,resizable=no,width=400,height=300');
	myWin.focus();
}
function frame_login() {
	var myWin = open('member_frame_login.pl', 'Login','menubar=no,toolbar=no,status=no,dependent=yes,scrollbars=yes,resizable=no,width=400,height=300');
	myWin.focus();
}
function show_image(strImage){
	// Open a window to show the image.
	var myWin = open("", "win1","dependent=yes,scrollbars=yes,width=630,height=540");
	myWin.focus();
	// Write the header info.
	myWin.document.open();
	myWin.document.write('<html><head><title>Image</title></head>');
	myWin.document.write('<body marginwidth="0" marginheight="0" leftmargin="0" topmargin="0"><table width="620" border="0" cellspacing="0" cellpadding="0">');
	myWin.document.write('<tr><td><img src="../images/',strImage,'" border="0"></td></tr>');
	myWin.document.write('<tr><td align="right"><a href="javascript:window.close();"><img src="../images/image_close.gif" border="0"></a>&nbsp;&nbsp;</td></tr>');
	myWin.document.write('</table>');
	myWin.document.write('</body></html>');
}
function show_photo(strImage){
	// Open a window to show the image.
	var myWin = open("", "win1","dependent=yes,scrollbars=yes,resizable=yes,width=800,height=600");
	myWin.focus();
	// Write the header info.
	myWin.document.open();
	myWin.document.write('<html><head><title>Photo</title></head>');
	myWin.document.write('<body marginwidth="0" marginheight="0" leftmargin="0" topmargin="0"><table border="0" cellspacing="0" cellpadding="0">');
	myWin.document.write('<tr><td><img src="',strImage,'" border="0"></td></tr>');
	myWin.document.write('<tr><td align="right"><a href="javascript:window.close();"><img src="../images/image_close.gif" border="0"></a>&nbsp;&nbsp;</td></tr>');
	myWin.document.write('</table>');
	myWin.document.write('</body></html>');
}
function show_flash(strSRC,strWidth,strHeight){
	document.write('<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0\" width=\"' + strWidth + '\" height=\"' + strHeight + '\">');
	document.write('<param name=movie value=\"' + strSRC + '\">');
	document.write('<param name=quality value=high>');
	document.write('<embed src=\"' + strSRC + '\" width=\"' + strWidth + '\" height=\"' + strHeight + '\" quality=high pluginspage=\"http://www.macromedia.com/go/getflashplayer\" type=\"application/x-shockwave-flash\"></embed></object>');
}
function Restrict_Chars(txtbox,size){
	var invalid=false;
	var count=0;
	var strExp;
	var txtExclude=new String('\"\%');    
	var txtComments=new String(txtbox.value);    
	var txtValidText= '';    
	var b=txtComments.length  
	for (var i=0; i<b; i++) {
		a1=txtComments.substr(i,1)
		if (a1 == "n" || a1 == "r" || a1 == "t") {
			strExp = "\\" + a1;
		} else {
			strExp = a1;
		}
		count++;
		if (count < size+1 && (txtExclude.search(strExp) == -1 || a1 == '.')) {
			txtValidText=txtValidText.concat(a1);
		} else if (txtExclude.search(strExp) != -1 ) {
			alert(" You cannot enter the character: " + a1);
			invalid=true;
		} else {
			alert("The text must not contain more than " + size + " characters.");
			invalid=true;
		}
	}
	if (invalid == true) {
		txtbox.value=txtValidText;
	}
}     
function getCookieVal (offset)
		{
   		var endstr = document.cookie.indexOf (";", offset);
   		if (endstr == -1)
      		endstr = document.cookie.length;
   		return unescape(document.cookie.substring(offset, endstr));
		}

function GetCookie (name)
		{
        var arg = name + "=";
        var alen = arg.length;
        var clen = document.cookie.length;
        var i = 0;
        while (i < clen)
        		{
                var j = i + alen;
                if (document.cookie.substring(i, j) == arg)
                        return getCookieVal (j);
                i = document.cookie.indexOf(" ", i) + 1;
                        if (i == 0)
                                break;
                }
        return null;
		}

function SetCookie (name, value)
		{
        var argv = SetCookie.arguments;
        var argc = SetCookie.arguments.length;
        var expires = (argc > 2) ? argv[2] : null;
        var path = (argc > 3) ? argv[3] : null;
        var domain = (argc > 4) ? argv[4] : null;
        var secure = (argc > 5) ? argv[5] : false;
        document.cookie = name + "=" + escape (value) + ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) + ((path == null) ? "" : ("; path=" + path)) + ((domain == null) ? "" : ("; domain=" + domain)) + ((secure == true) ? "; secure" : "");
		}

function UpdateLanguageCookie(strLangID)
		{
		// Get cookie details
        strMyDomain = '/';
        // set expiry date to 1 year from now.
        var dteLargeExpDate = new Date ();
        dteLargeExpDate.setTime(dteLargeExpDate.getTime() + (365 * 24 * 3600 * 1000));
        SetCookie('LanguageID',strLangID,dteLargeExpDate,strMyDomain);
        change_language(strLangID);
        }

function GetLanguage()
		{
		var strLanguage = GetCookie('LanguageID');
		if (strLanguage == null)
			{
			return null;
			}
		else
			{
		    change_language(strLanguage);
		    }
		}

var booAreaSpecific;
var strNameReferrerID;
var strValueReferrerID;
var booNameSetReferrer;
var booValueSetReferrer;
var booNameMemberID;
var booValueMemberID;
var strNameLanguageID;
var strValueLanguageID;
var strURLData;
var strURLDataVariables;
var strURL;
var arrSplitURL = new Array();
var arrSplitValiables = new Array();
var arrSplitNameValue = new Array();

function set_variables(strURL,func) {
	booAreaSpecific = false;
	strNameReferrerID = '';
	strValueReferrerID = '';
	booNameSetReferrer = '';
	booValueSetReferrer = false;
	booNameMemberID = '';
	booValueMemberID = '';
	strNameLanguageID = '';
	strValueLanguageID = '';
	strURLData = '';
	strURLDataVariables = '';

	arrSplitURL = strURL.split('?');
	var NameValueArray = new Array();
	if (arrSplitURL.length == 2) {
		strURL = arrSplitURL[1];
		arrSplitValiables = strURL.split('&');
		for (i=0;i<arrSplitValiables.length;i++) {
			strURL = arrSplitValiables[i];
			arrSplitNameValue = strURL.split('=');
			strName = arrSplitNameValue[0];
			strValue = arrSplitNameValue[1];
			NameValueArray[i]=[strName,strValue];
			tmpPage = 'N';
			if (strName == 'referrerID') {
				strNameReferrerID = arrSplitNameValue[0];
				strValueReferrerID = arrSplitNameValue[1];
				strURLDataVariables=strURLDataVariables + arrSplitNameValue[0] + '=' + arrSplitNameValue[1] + '&';
			} else if (strName == 'setstat') {
				booNameSetReferrer = arrSplitNameValue[0];
				booValueSetReferrer = arrSplitNameValue[1];
				strURLDataVariables=strURLDataVariables + arrSplitNameValue[0] + '=' + arrSplitNameValue[1] + '&';
			} else if (strName == 'transID' && func != 'no_user') {
				booNameMemberID = arrSplitNameValue[0];
				booValueMemberID = arrSplitNameValue[1];
				strURLDataVariables=strURLDataVariables + arrSplitNameValue[0] + '=' + arrSplitNameValue[1] + '&';
			} else if (strName == 'langID') {
				strNameLanguageID = arrSplitNameValue[0];
				if (func != 'set_lang') {
					strValueLanguageID = arrSplitNameValue[1];
					strURLDataVariables=strURLDataVariables + arrSplitNameValue[0] + '=' + arrSplitNameValue[1] + '&';
				}
			} else if (strName == 'page') {
				strPageName = arrSplitNameValue[1];
				tmpPage = 'Y';
			}
		}
		if (strURLDataVariables.substr(strURLDataVariables.length - 1,strURLDataVariables.length) == '&') {
			strURLDataVariables=strURLDataVariables.substr(0,strURLDataVariables.length - 1)
		}
	}
	if (strNameLanguageID == '') {
		strNameLanguageID = 'langID';
		strValueLanguageID = 'GB';
		if (strURLDataVariables != '') {
			strURLDataVariables = strURLDataVariables + '&' + strNameLanguageID + '=' + strValueLanguageID;
		} else {
			strURLDataVariables = strNameLanguageID + '=' + strValueLanguageID;
		}
	}
	if (strURLDataVariables != '') {
		strURLData = '?' + strURLDataVariables;
	}
}
if (document.URL == parent.document.URL) {
	set_variables(document.URL,'');
} else {
	set_variables(parent.document.URL,'');
}

function change_language(langID) {
	set_variables(document.URL,'set_lang');
	if (strURLData == '') {
		strURLData = '?' + strNameLanguageID + '=' + langID;
	} else {
		strURLData = strURLData + '&' + strNameLanguageID + '=' + langID;
	}
	document.location=arrSplitURL[0] + strURLData;
}

function login(page) {
	if (page == 'http://test.penwizard.co.uk/cgi-bin/member_reminder.pl') {
		if (strURLData == '') {
			document.location = 'http://test.penwizard.co.uk/cgi-bin/member_login.pl' + '?page=http://test.penwizard.co.uk/cgi-bin/member_reminder.pl';
		} else {
			if (booNameMemberID != '') {
				document.location=page + strURLData;
			} else {
				document.location='http://test.penwizard.co.uk/cgi-bin/member_login.pl' + strURLData + '&page=http://test.penwizard.co.uk/cgi-bin/member_reminder.pl';
			}
		}
	} else {
		if (arrSplitURL[0] == 'http://test.penwizard.co.uk/cgi-bin/member_login.pl' || arrSplitURL[0] == 'http://test.penwizard.co.uk/cgi-bin/member_registration.pl' || arrSplitURL[0] == 'http://test.penwizard.co.uk/cgi-bin/member_comp_register.pl') {
			arrSplitURL[0] = 'http://test.penwizard.co.uk/cgi-bin/index.pl';
		}
		if (strURLData == '') {
			document.location=page + '?page=' + arrSplitURL[0];
		} else {
			document.location=page + strURLData + '&page=' + arrSplitURL[0];
		}
	}
}

function logout() {
	if (parent.document.URL == document.URL) {
		set_variables(document.URL,'no_user');
		if (arrSplitURL[0] == 'http://test.penwizard.co.uk/cgi-bin/basket.pl' || arrSplitURL[0] == 'http://test.penwizard.co.uk/cgi-bin/paymentconfirmation.pl' || arrSplitURL[0] == 'http://test.penwizard.co.uk/cgi-bin/member_account.pl' || arrSplitURL[0] == 'http://test.penwizard.co.uk/cgi-bin/member_amend.pl' || arrSplitURL[0] == 'http://test.penwizard.co.uk/cgi-bin/member_reminder.pl' || arrSplitURL[0] == 'http://test.penwizard.co.uk/books/book_info.pl' || arrSplitURL[0] == 'http://test.penwizard.co.uk/cards/card_info.pl') {
			arrSplitURL[0] = 'http://test.penwizard.co.uk/cgi-bin/index.pl';
		}
		document.location=arrSplitURL[0] + strURLData;
	} else {
		set_variables(parent.document.URL,'no_user');
		parent.window.frames['Hidden'].document.forms['frmOrder'].ordSetReferer.value = booValueSetReferrer;
		parent.window.frames['Hidden'].document.forms['frmOrder'].ordReferer.value = strValueReferrerID;
		parent.window.frames['Hidden'].document.forms['frmOrder'].ordMemberID.value = '';
		parent.window.frames['Hidden'].document.forms['frmOrder'].ordPurEmail.value = '';
		parent.window.frames['Hidden'].document.forms['frmOrder'].action = document.URL;
		parent.window.frames['Hidden'].document.forms['frmOrder'].submit();
	}
}

function gotoPage(page,variables) {
	if (page == 'basket.pl' && variables != '') {
		arrVariables = variables.split('&');
		arrVariables = arrVariables[0].split('=');
		if (arrVariables[0] != 'ordID') {
			set_variables(document.URL,'no_user');
		}
	}
	if (strURLData == '' && variables != '') {
		strURLData = '?';
	} else if (strURLData != '' && variables != '') {
		strURLData = strURLData + '&';
	}
	document.location=page + strURLData + variables;
}

function gotoPageFromForm(form,page) {
	form.action=page + strURLData;
	form.submit();
}

function gotoPageFromProcess(page,variables) {
	set_variables(parent.document.URL,'');
	strURLData = '';
	strValueReferrerID = parent.window.frames['Hidden'].document.forms['frmOrder'].ordReferer.value;
	booValueSetReferrer = parent.window.frames['Hidden'].document.forms['frmOrder'].ordSetReferer.value;
	strValueMemberID = parent.window.frames['Hidden'].document.forms['frmOrder'].ordMemberID.value;
	if (booValueSetReferrer == 'true') {
		if (strValueMemberID == '') {
			strURLData = '?referrerID=' + strValueReferrerID + '&setstat=' + booValueSetReferrer;
		} else {
			strURLData = '?referrerID=' + strValueReferrerID + '&setstat=' + booValueSetReferrer + '&transID=' + strValueMemberID;
		}
	} else {
		if (strValueMemberID != '') {
			strURLData = '?transID=' + strValueMemberID;
		}
	}
	if (strURLData == '' && strValueLanguageID != '') {
		strURLData = '?' + strNameLanguageID + '=' + strValueLanguageID
	} else if (strURLData != '' && strValueLanguageID != '') {
		strURLData = strURLData + '&' + strNameLanguageID + '=' + strValueLanguageID
	}
	if (strURLData == '' && variables != '') {
		strURLData = '?';
	} else if (strURLData != '' && variables != '') {
		strURLData = strURLData + '&';
	}
	parent.document.location=page + strURLData + variables;
}

if (strValueReferrerID == '20519') {
	booAreaSpecific = true;
}
