//---------------------------------------------------------------------------
// Checks for various types of patterns in a field
// Must be called onBlur of field
//---------------------------------------------------------------------------
function checkPattern(field, type){
	chkPtnFlag="";
	if (type=='filename'){
		var notFnRegxp = /[^a-zA-Z0-9_\-]/;
		if (notFnRegxp.test(field.value)){ chkPtnFlag="Not a valid file name - Illegal Characters."; }
	}

	if (type=='digits'){
		var notFnRegxp = /[^0-9]/;
		if (notFnRegxp.test(field.value)){ chkPtnFlag="Not a number value - Illegal Characters."; }
	}

	if (chkPtnFlag!=""){ alert(chkPtnFlag); field.focus(); }
}
//---------------------------------------------------------------------------

//---------------------------------------------------------------------------
// find affcode
//---------------------------------------------------------------------------
function find_affcode(url){
	startPos = null;
	affcode = "";
	//Find start position of aff value
	for (i = 0; i < url.length; i++){
		if (url.charAt(i) == "a" && url.charAt(i+1) == "f" && url.charAt(i+2) == "f" && url.charAt(i+3) == "="){
			startPos = i+4;
		}
	}

	//Get value
	while(url.charAt(startPos) != "?" && url.charAt(startPos) != "&" && startPos != url.length){
		affcode += url.charAt(startPos);
		startPos++;
	}

	if (affcode != ""){
		//alert(url.length+"\n"+url+"\n"+affcode);
	}

	return affcode;
}
//---------------------------------------------------------------------------

//---------------------------------------------------------------------------
// print cobrand
//---------------------------------------------------------------------------
function print_cobrand(){
	aff_lib = "/aff_lib/";

	myAffCode = find_affcode(document.location.href);

	if (myAffCode != ""){
		//Center it
		document.writeln("<center>");

		//Co-brand
		if (CAFF_bgcolor[myAffCode] != null){
			//Bgcolor and Background image
			document.writeln("<table border=0 cellpadding=0 cellspacing=0 width=588 bgcolor=\""+CAFF_bgcolor[myAffCode]+"\" background=\""+CAFF_bgimg[myAffCode]+"\"><tr>");

			//Logo
			if (CAFF_logolink[myAffCode] != ""){ document.writeln("<td align=center valign=center><A target=\"_blank\" HREF=\""+CAFF_logolink[myAffCode]+"\"><img border=0 src=\""+aff_lib+myAffCode+"-logoimg.gif\"></A></td>"); }

			//Nav
			if (CAFF_nav1link[myAffCode] != ""){ document.writeln("<td align=center valign=bottom><A target=\"_blank\" HREF=\""+CAFF_nav1link[myAffCode]+"\"><img border=0 src=\""+aff_lib+myAffCode+"-nav1img.gif\"></A></td>"); }
			if (CAFF_nav2link[myAffCode] != ""){ document.writeln("<td align=center valign=bottom><A target=\"_blank\" HREF=\""+CAFF_nav2link[myAffCode]+"\"><img border=0 src=\""+aff_lib+myAffCode+"-nav2img.gif\"></A></td>"); }
			if (CAFF_nav3link[myAffCode] != ""){ document.writeln("<td align=center valign=bottom><A target=\"_blank\" HREF=\""+CAFF_nav3link[myAffCode]+"\"><img border=0 src=\""+aff_lib+myAffCode+"-nav3img.gif\"></A></td>"); }
			if (CAFF_nav4link[myAffCode] != ""){ document.writeln("<td align=center valign=bottom><A target=\"_blank\" HREF=\""+CAFF_nav4link[myAffCode]+"\"><img border=0 src=\""+aff_lib+myAffCode+"-nav4img.gif\"></A></td>"); }
			if (CAFF_nav5link[myAffCode] != ""){ document.writeln("<td align=center valign=bottom><A target=\"_blank\" HREF=\""+CAFF_nav5link[myAffCode]+"\"><img border=0 src=\""+aff_lib+myAffCode+"-nav5img.gif\"></A></td>"); }
			if (CAFF_nav6link[myAffCode] != ""){ document.writeln("<td align=center valign=bottom><A target=\"_blank\" HREF=\""+CAFF_nav6link[myAffCode]+"\"><img border=0 src=\""+aff_lib+myAffCode+"-nav6img.gif\"></A></td>"); }
			document.writeln("</td></tr></table><br/>");
		}

		/*Link to normal affiliate (This is done in aff_js_bottom.js now - Irfan,2/2/2000)
		if (CAFF_bgcolor[myAffCode] == null){
			document.writeln("<table border=0 cellpadding=0 cellspacing=0 width=588><td width=588 align=right>");
			document.writeln("<SPAN CLASS=coverText><A HREF=\"http://www.chelseapaper.com/php3/index.php3?aff="+myAffCode+"\">http://www.chelseapaper.com/php3/index.php3?aff="+myAffCode+"</a></Span><BR>");
			document.writeln("</td></table>");
		}
		*/
		document.writeln("</center>");
	}
}
//---------------------------------------------------------------------------

//---------------------------------------------------------------------------
// print_cobrand_sizable(array[width, height])
//---------------------------------------------------------------------------
function print_cobrand_sizable(sizeArray){
  //Default size values and array indices correspondants
  var IDX_WIDTH = 0;

  //Add default values for sizes array here (based on the corresponding array indices above
  var size_defaults = new Array(588, '');

  //The sizes array
  var sizes = size_defaults;

  for (i = 0; i < sizeArray.length; i++){
    if (sizeArray[i] != ''){
      sizes[i] = sizeArray[i];
    }
  }

	aff_lib = "/aff_lib/";
	myAffCode = find_affcode(document.location.href);

	if (myAffCode != ""){
		//Center it
		document.writeln("<center>");

		//Co-brand
		if (CAFF_bgcolor[myAffCode] != null){
			//Bgcolor and Background image
			document.writeln("<table border=0 cellpadding=0 cellspacing=0 width=\""+sizes[IDX_WIDTH]+"\" bgcolor=\""+CAFF_bgcolor[myAffCode]+"\" background=\""+CAFF_bgimg[myAffCode]+"\"><tr>");

			//Logo
			if (CAFF_logolink[myAffCode] != ""){ document.writeln("<td align=center valign=center><A target=\"_blank\" HREF=\""+CAFF_logolink[myAffCode]+"\"><img border=0 src=\""+aff_lib+myAffCode+"-logoimg.gif\"></A></td>"); }

			//Nav
			if (CAFF_nav1link[myAffCode] != ""){ document.writeln("<td align=center valign=bottom><A target=\"_blank\" HREF=\""+CAFF_nav1link[myAffCode]+"\"><img border=0 src=\""+aff_lib+myAffCode+"-nav1img.gif\"></A></td>"); }
			if (CAFF_nav2link[myAffCode] != ""){ document.writeln("<td align=center valign=bottom><A target=\"_blank\" HREF=\""+CAFF_nav2link[myAffCode]+"\"><img border=0 src=\""+aff_lib+myAffCode+"-nav2img.gif\"></A></td>"); }
			if (CAFF_nav3link[myAffCode] != ""){ document.writeln("<td align=center valign=bottom><A target=\"_blank\" HREF=\""+CAFF_nav3link[myAffCode]+"\"><img border=0 src=\""+aff_lib+myAffCode+"-nav3img.gif\"></A></td>"); }
			if (CAFF_nav4link[myAffCode] != ""){ document.writeln("<td align=center valign=bottom><A target=\"_blank\" HREF=\""+CAFF_nav4link[myAffCode]+"\"><img border=0 src=\""+aff_lib+myAffCode+"-nav4img.gif\"></A></td>"); }
			if (CAFF_nav5link[myAffCode] != ""){ document.writeln("<td align=center valign=bottom><A target=\"_blank\" HREF=\""+CAFF_nav5link[myAffCode]+"\"><img border=0 src=\""+aff_lib+myAffCode+"-nav5img.gif\"></A></td>"); }
			if (CAFF_nav6link[myAffCode] != ""){ document.writeln("<td align=center valign=bottom><A target=\"_blank\" HREF=\""+CAFF_nav6link[myAffCode]+"\"><img border=0 src=\""+aff_lib+myAffCode+"-nav6img.gif\"></A></td>"); }
			document.writeln("</td></tr></table><br/>");
		}

		document.writeln("</center>");
	}
}
//---------------------------------------------------------------------------
