var agt=navigator.userAgent.toLowerCase();
var appVer = navigator.appVersion.toLowerCase();
var is_minor = parseFloat(appVer);
var is_major = parseInt(is_minor);
var iePos  = appVer.indexOf('msie');
if (iePos !=-1) {
   is_minor = parseFloat(appVer.substring(iePos+5,appVer.indexOf(';',iePos)))
   is_major = parseInt(is_minor);
}
var is_ie   = (iePos!=-1);
var is_ie3  = (is_ie && (is_major < 4));
var is_ie4   = (is_ie && is_major == 4);
var is_ie4up = (is_ie && is_minor >= 4);
var is_ie5   = (is_ie && is_major == 5);
var is_ie5up = (is_ie && is_minor >= 5);
var is_win   = ( (agt.indexOf("win")!=-1) || (agt.indexOf("16bit")!=-1) );
var is_java = (navigator.javaEnabled());

function compatabilityMessage(){
	var message = "";
	if (is_ie5up == true && is_win == true && is_java == true){
		message += "<b>Your machine is compatible with our design system</b>";
	} else {
		Needs_count = 0;
		message += "<br><b>To use our site you require a :-</b><br><br>";
		if (is_win != true){
			Needs_count++;
			message += Needs_count + ") PC running windows.<br>";
		}
		if (is_ie5up != true){
			Needs_count++;
			message += Needs_count + ") <A href=\"http://www.microsoft.com/ie/default.htm\" target=\"_blank\" onmouseover=\"window.status='Get Microsoft IE 5.5 & JVM';return true;\" onmouseout=\"window.status='Card Corporation Online Printing';return true;\"><b>Internet Explorer 5</b></a> or above.<br>";
		}
		if (is_java != true){
		Needs_count++;
			message += Needs_count + ") Java Enabled Browser. <a href='http://download.windowsupdate.com/msdownload/update/v3-19990518/cabpool/MSJavWU_8073687b82d41db93f4c2a04af2b34d.exe'>Click here to download Microsofts Java Plugin</a>. Select 'Open' when asked whether to 'Save' or 'Open' this will install the plugin straight after download.<br>";
		}
		message += "<br>";
	}
	document.write(message);
}

function CCheader(prefix) {
	//CC BODY START
	document.write("<script>window.status=\"Card Corporation Online Printing\";</script><center><table cellpadding='0' cellspacing='0' border='0' width='100%' height='100%'>");
	//CC BODY START
	
	//PORTAL HEADER
	document.write("<tr><td>");
	document.write("</td></tr>");
	//PORTAL HEADER
	
	//CC HEADER
	document.write("<tr height=5><td><img src=\"" + prefix + "images/spacer.gif\" height=5></td></tr><tr><td height=77><table border=0 cellpadding=0 cellspacing=0 width=100%><tr><td width=214 height=77><a href=\"http://www.cardcorp.co.uk/Card_Corporation/index.html\"><img alt=\"Card Corporation Home Page\" border=\"0\" src=\"" + prefix + "images/header_01.gif\" width=212 height=77></a></td><td width=9 height=77><img src=\"images/header_02.gif\" width=9 height=77></td><td width=100% height=77 background=\"images/header_03.gif\" valign=top><center><img src=\"" + prefix + "images/header_text_01.gif\" width=385 height=9><br><img src=\"" + prefix + "images/spacer.gif\" width=1 height=15><br><img src=\"" + prefix + "images/header_banner_01b.gif\" width=385 height=42></center></td><td width=15 height=77><img src=\"images/header_04.gif\" width=13 height=77></td></tr></table></td><tr><td valign='top' height='16'><center><table cellpadding='0' cellspacing='0' border='0' width='100%'><tr><td class='ProdInd' width='20%'><center><A href='" + prefix + "index.html' onmouseover=\"window.status='Home Page';return true;\" onMouseout=\"window.status='Card Corporation Online Printing'\";return true;>Home</a></center></td><td class='ProdInd' width='20%'><center><A href='" + prefix + "prodind.html' onmouseover=\"window.status='Product Index';return true;\" onMouseout=\"window.status='Card Corporation Online Printing'\";return true;>Products</a></center></td><td class='ProdInd' width='20%'><center><A href='" + prefix + "news.html' onmouseover=\"window.status='News';return true;\" onMouseout=\"window.status='Card Corporation Online Printing'\";return true;>News</a></center></td><td class='ProdInd' width='20%'><center><A href='" + prefix + "help.html' onmouseover=\"window.status='Help';return true;\" onMouseout=\"window.status='Card Corporation Online Printing'\";return true;>Help</a></center></td><td class='ProdInd' width='20%'><center><A href='" + prefix + "contacts.html' onmouseover=\"window.status='Contacts';CCshowTooltip('dHTMLToolTip',event,'<center><b>Tech Help Line:</b> +44 (0)113 224 8600<br>ask for Card Corp Technical Help</center>', '#ffffE1', '#000000', '#000000', '6000', 20); return true;\" >Contacts</a></center></td></tr></table></center></td></tr><tr><td valign='top'><center>");
	//CC HEADER
}
function CCfooter(prefix) {
	//CC FOOTER
	document.write("<DIV id=dHTMLToolTip style=\"HEIGHT: 10px; LEFT: 0px; POSITION: absolute; TOP: 0px; WIDTH: 10px; Z-INDEX: 1000\"></DIV></center></td></tr><tr><td height='16' valign='bottom'><center><table cellpadding='0' cellspacing='0' border='0' width='100%'><tr><td class='ProdInd' width='20%'><center><A href='" + prefix + "index.html' onmouseover=\"window.status='Home Page';return true;\" onMouseout=\"window.status='Card Corporation Online Printing'\";return true;>Home</a></center></td><td class='ProdInd' width='20%'><center><A href='" + prefix + "prodind.html' onmouseover=\"window.status='Product Index';return true;\" onMouseout=\"window.status='Card Corporation Online Printing'\";return true;>Products</a></center></td><td class='ProdInd' width='20%'><center><A href='" + prefix + "news.html' onmouseover=\"window.status='News';return true;\" onMouseout=\"window.status='Card Corporation Online Printing'\";return true;>News</a></center></td><td class='ProdInd' width='20%'><center><A href='" + prefix + "help.html' onmouseover=\"window.status='Help';return true;\" onMouseout=\"window.status='Card Corporation Online Printing'\";return true;>Help</a></center></td><td class='ProdInd' width='20%'><center><A href='" + prefix + "contacts.html' onmouseover=\"window.status='Contacts';CCshowTooltip('dHTMLToolTip',event,'<center><b>Tech Help Line:</b> +44 (0)113 224 8600<br>ask for Card Corp Technical Help</center>','#ffffE1','#000000','#000000','6000',-50);return true;\">Contacts</a></center></td></tr>");
	//CC FOOTER
	
	//PORTAL FOOTER
	document.write("<tr><td>");
	document.write("</td></tr>");
	//PORTAL FOOTER
	
	//CC BODY END
	document.write("</table>");
	//CC BODY END
}
function CCfindObj(n, d) { //v3.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=CCfindObj(n,d.layers[i].document); return x;
}

function CCSHLayers() { //v3.0
  var i,p,v,obj,args=SHLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=CCfindObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v='hide')?'hidden':v; }
    obj.visibility=v; }
}
//Tooltip Timer Variable
var tipTimer;
function CClocateObject(n, d) { //v3.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=CClocateObject(n,d.layers[i].document); return x;
}

function CChideTooltip(object)
{
	if (document.all)
	{
		CClocateObject(object).style.visibility="hidden"
		CClocateObject(object).style.left = 1;
		CClocateObject(object).style.top = 1;
	return false
	}
	else if (document.layers)
	{
		CClocateObject(object).visibility="hide"
		CClocateObject(object).left = 1;
		CClocateObject(object).top = 1;
		return false
	}
	else
	return true
}
function CCshowTooltip(object,e, tipContent, backcolor, bordercolor, textcolor, displaytime, offset)
{
	//window.clearTimeout(tipTimer)

	if (document.all)
		{
			CClocateObject(object).style.top=document.body.scrollTop+event.clientY+offset

			CClocateObject(object).innerHTML='<table style="font-family: Tahoma, Arial, Helvetica, sans-serif; font-size: 11px; border: '+bordercolor+'; border-style: solid; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; background-color: '+backcolor+'" width="10" border="0" cellspacing="1" cellpadding="1"><tr><td nowrap><font style="font-family: Tahoma, Arial, Helvetica, sans-serif; font-size: 11px; color: '+textcolor+'">'+unescape(tipContent)+'</font></td></tr></table> '

			if ((e.x + CClocateObject(object).clientWidth) > (document.body.clientWidth + document.body.scrollLeft))
				{
					CClocateObject(object).style.left = (document.body.clientWidth + document.body.scrollLeft) - CClocateObject(object).clientWidth-10;
				}
			else
			{
			CClocateObject(object).style.left=document.body.scrollLeft+event.clientX
			}
		CClocateObject(object).style.visibility="visible"
		window.setTimeout("CChideTooltip('"+object+"')", displaytime);
		}
	else if (document.layers)
		{
		CClocateObject(object).document.write('<table width="10" border="0" cellspacing="1" cellpadding="1"><tr bgcolor="'+bordercolor+'"><td><table width="10" border="0" cellspacing="0" cellpadding="2"><tr bgcolor="'+backcolor+'"><td nowrap><font style="font-family: Tahoma, Arial, Helvetica, sans-serif; font-size: 11px; color: '+textcolor+'">'+unescape(tipContent)+'</font></td></tr></table><td></tr></table>')
		CClocateObject(object).document.close()
		CClocateObject(object).top=e.y+20

		if ((e.x + CClocateObject(object).clip.width) > (window.pageXOffset + window.innerWidth))
			{
				CClocateObject(object).left = window.innerWidth - CClocateObject(object).clip.width-10;
			}
		else
			{
			CClocateObject(object).left=e.x;
			}
		CClocateObject(object).visibility="show"
		window.setTimeout("CChideTooltip('"+object+"')", displaytime);
	}
	else
	{
		return true
	}
}
// SEARCH FUNCTION FOR CHECKING STRINGS FOR A SPECIFIC 'search' CHARACTER
function CCcheck(input, search)
{
	var ok = true;
	for (var i = 0; i < input.length; i++)
	{
		var chr = input.charAt(i);

		 if (chr == search)
				ok = false;
    }
	return ok;
}

// CHECK USER LOGIN DETAILS
function CCValidateUserSignOn(){
	if(CCCheckField("user","CUSTID","Please enter Company name.","Type Company Name Here")){return false}
	if(CCCheckField("user","USERID","Please enter User name.","Type UserName Here")){return false}
	
}

// CHECK ADMIN LOGIN DETAILS
function CCValidateCustSignOn(){
	if(CCCheckField("cust","CUSTID","Please enter Company name.","Type Company Name Here")){return false}
}

//DESIGN TABLE CODE
//The first design of the page must set ALL the parameters if it will be wrapped with a form.ie. Modes D & R.
//Modes Available :- D=Demo R=Register E=ExampleThumbnail
loc = "" + window.location;
locIndex =  loc.lastIndexOf('/');
var FolderRoot = loc.substring(0,locIndex+1);
var DisplayMode;
var ProductGroup;
var ReturnPage = "";
var ImageWidth;
var ImageHeight;
var RelativePortalRootPath = "";
var PortalRef = "Card Corporation"

function CCDesign(USERID, WIDTH, HEIGHT, CUSTID, MODE, REFERAL, RELATIVE_PORTAL_ROOT_PATH){
	if (RELATIVE_PORTAL_ROOT_PATH){RelativePortalRootPath = RELATIVE_PORTAL_ROOT_PATH;}
	if (REFERAL){ReturnPage = REFERAL;}
	if (MODE){DisplayMode = MODE;}
	if (CUSTID){ProductGroup = CUSTID;}
	if (WIDTH){ImageWidth = WIDTH;}
	if (HEIGHT){ImageHeight = HEIGHT;}
	if (DisplayMode && DisplayMode != "E"){
		if (DisplayMode == "D"){
			document.write("<form action='http://www.cardcorp.co.uk/cgi-bin/displayCard.pl' method='post'><input type='hidden' name='WHATTODO' value='DISPLAYCARD'>");
		} else {
			document.write("<form action='http://www.cardcorp.co.uk/cgi-bin/DIYRegister.pl' method='post'>");
		}
		document.write("<input name='CUSTID' type='hidden' value='" + ProductGroup + "'><input name='USERID' type='hidden' value='" + USERID +"'>");
		document.write("<input name='PORTAL' type='hidden' value='");
		if (PortalRef){document.write(PortalRef + "'>");} else {document.write("Card Corporation'>");}
		document.write("<input name='REFERAL' type='hidden' value='" + FolderRoot + RelativePortalRootPath);
		if (ReturnPage){document.write(ReturnPage);}
		document.write("'>");
	}
	document.write("<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 bgcolor=#BFBFBF WIDTH=" + (ImageWidth + 8) + " HEIGHT=" + (ImageHeight + 8) + "><TR><TD COLSPAN=2 ROWSPAN=2 VALIGN=MIDDLE WIDTH=" + (ImageWidth + 2) + " HEIGHT=" + (ImageHeight + 2) + "><CENTER>");
	if (DisplayMode && DisplayMode != "E"){
		document.write("<input src='http://www.cardcorp.co.uk/imagesOptimised/" + USERID + ".gif' WIDTH='" + ImageWidth + "' HEIGHT='" + ImageHeight + "' type='image'>");
	} else {
		document.write("<img src='http://www.cardcorp.co.uk/imagesOptimised/" + USERID + ".gif' WIDTH='" + ImageWidth + "' HEIGHT='" + ImageHeight + "'");
	}
	document.write("</TD><TD><IMG SRC='" + RelativePortalRootPath + "images/Bord2.gif' WIDTH=6 HEIGHT=6></TD></TR><TR><TD><IMG SRC='" + RelativePortalRootPath + "images/Bord3.gif' WIDTH=6 HEIGHT=" + (ImageHeight - 4) + "></TD></TR><TR><TD><IMG SRC='" + RelativePortalRootPath + "images/Bord4.gif' WIDTH=6 HEIGHT=6></TD><TD><IMG SRC='" + RelativePortalRootPath + "images/Bord5.gif' WIDTH=" + (ImageWidth - 4) + " HEIGHT=6></TD><TD><IMG SRC='" + RelativePortalRootPath + "images/Bord6.gif' WIDTH=6 HEIGHT=6></TD></TR></TABLE>");
	if (DisplayMode && DisplayMode != "E"){document.write("</FORM>");}
}

function CCFolderName(FoldersDeepFromRoot, RootorFoldername){
	var FolderName;
	var locInd;
	var DerivedFolderRoot = "" + window.location;
	for (var i=1; i<=FoldersDeepFromRoot; i++){
		locIndex =  DerivedFolderRoot.lastIndexOf('/');
		DerivedFolderRoot = "" + DerivedFolderRoot.substring(0,locIndex);
	}
	locIndex =  DerivedFolderRoot.lastIndexOf('/');
	if (RootorFoldername == "F"){
		FolderName = "" + DerivedFolderRoot.substring(locIndex+1);
	} else {
		FolderName = "" + DerivedFolderRoot;
	}
	return FolderName;
}

function CCCharacterSwap(StringToConvert,CharToReplace, ReplacementChar){
	var ConvertedString =""
	for (var i=0; i<=StringToConvert.length; i++){
		if (StringToConvert.charAt(i) == CharToReplace){
			NextLetter = ReplacementChar;
		} else {
			NextLetter = StringToConvert.charAt(i);
		}
		ConvertedString += "" + NextLetter;
	}
	return ConvertedString;
}

var FormAdministrator = "ivorj@cardcorp.co.uk";

function CCCheckField(FormName,FieldName,AlertText,GuideText){
	if ((document.all(FormName).all(FieldName).value == "")||(document.all(FormName).all(FieldName).value == GuideText))
	{
		alert (AlertText);
		if (document.all(FormName).all(FieldName).type == "text"){
			document.all(FormName).all(FieldName).value = GuideText;
			document.all(FormName).all(FieldName).select();
			document.all(FormName).all(FieldName).focus();
		} else {
			document.all(FormName).all(FieldName).focus();
		}
		return true;
	} else {
		return false;
	}
}

function txetesrever(string){
	var newStr = "";
	for (i=string.length-1; i>=0; i--){
		newStr += string.charAt(i);
	}
	return newStr;
}

var prodIndex = "lmth.dnidorp/noitaroproC_draC/ku.oc.procdrac.www//:ptth";
var homePage = "lmth.xedni/noitaroproC_draC/ku.oc.procdrac.www//:ptth";

function chgPgFunc(thePage) {
	var winW = 0;
	if (parseInt(navigator.appVersion)>3) {
		if (navigator.appName=="Netscape") {
			winW = window.innerWidth;
		}
		if (navigator.appName.indexOf("Microsoft")!=-1) {
			winW = document.body.offsetWidth;
		}
	}
	
		if (winW > 0){
			var chgPg = txetesrever("'" + thePage + "' = noitacol.tnemucod");
			eval(chgPg);
		}

}

