
function cbCardMessageRequired_onClick()
{
	if (document.forms[0][cbCardMessageRequiredID].checked)
	{
		document.forms[0][tbShip_to_text2ID].disabled=true;
	}
	else
	{
		document.forms[0][tbShip_to_text2ID].disabled=false;
	}

}


function CheckLeaveSite()
{
	if (window.confirm(question)) 
	{
		return true;	 
	}
	else
	{
		window.location="deliveryregions.aspx";
		return false;
	}
}

function GetMajor(bname, agent){
	bpos = agent.indexOf(bname) + bname.length + 1;
	return parseInt(agent.substr(bpos));
}

function GetMinor(bname, agent){
	bpos = agent.indexOf(bname) + bname.length + 1;
	return parseFloat(agent.substr(bpos));
}

function CheckAgent(bname, agent){
	return agent.indexOf(bname) > -1;
}

function Is() 
{
	var agent = navigator.userAgent.toLowerCase();
	
	this.ie = CheckAgent("msie", agent);
	this.ns = CheckAgent("mozilla", agent);
	this.op3 = CheckAgent("opera", agent);
	
	this.major = GetMajor("msie", agent);
	this.minor = GetMinor("msie", agent);
	this.nmajor = GetMajor("mozilla", agent);
	this.nminor = GetMinor("mozilla", agent);
	this.omajor = GetMajor("opera", agent);
	this.ominor = GetMinor("opera", agent);
	
	
	this.ns2 = (this.ns && (this.nmajor == 2));
	this.ns3 = (this.ns && (this.nmajor == 3));
	this.ns4b = (this.ns && (this.nminor < 4.04));
	this.ns4 = (this.ns && (this.nmajor >= 4));

	this.ie3  = (this.ie && (this.major == 2));
	this.ie4  = (this.ie && (this.major >= 4));
	this.ie5  = (this.ie && (this.major >= 5));
	this.ie6  = (this.ie && (this.major >= 6));

	this.win   = CheckAgent("win", agent);
	this.mac   = CheckAgent("mac", agent);
	this.unix  = CheckAgent("x11", agent);
}

function SetCookie(cookieName,cookieValue,nDays) {
 var today = new Date();
 var expire = new Date();
 if (nDays==null || nDays==0) nDays=1;
 expire.setTime(today.getTime() + 3600000*24*nDays);
 document.cookie = cookieName+"="+escape(cookieValue)
                 + ";expires="+expire.toGMTString();
}

function DetectFlash(){
	var bdetect = new Is();
	
	insns = false;
	ins4=false;
	ins5=false;
	ins6=false;
	ins7=false;
	if ((!bdetect.ie4) || (bdetect.op3)) {
			MM_PluginVersion = 0;
			if(navigator.plugins["Shockwave Flash"] != null){
				var words = navigator.plugins["Shockwave Flash"].description.split(" ");
				MM_PluginVersion = parseInt(words[2]); 
			}
		if(MM_PluginVersion >= 4){
			insns = true;
		}else{
			insns = false;
		}
	} else if (bdetect.ie4 && bdetect.win) {
		document.write('<SCR' + 'IPT LANGUAGE=VBScript\> \n'); //FS hide this from IE4.5 Mac by splitting the tag
		document.write('on error resume next \n');
			document.write('ins4 = ( IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash." & 4)))\n');
			document.write('ins5 = ( IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash." & 5)))\n');
			document.write('ins6 = ( IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash." & 6)))\n');
			document.write('ins7 = ( IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash." & 7)))\n');
			document.write('</SCR' + 'IPT\> \n');
	}
	//alert(ins4 || ins5 || ins6);
	return ins4 || ins5 || ins6 || ins7 || insns;
}

function SetInputFocus( vObject)
{
	var is = new Is();
	if( is.ie4)
		vObject.focus();
	delete is;
}

function ChangeAnchor( strAnchorID, strUrl, x, y, width, height)
{
	var theAnchor = (document.layers) || ! (document.getElementById) ? "['" + strAnchorID + "']" : "('" + strAnchorID + "')";
	var strFunction = (document.getElementById) ? "document.getElementById" : "document.anchors";
	var obj = eval(strFunction+theAnchor);

	if( obj)
	{	
		obj.href = "javascript:void(0);";
		obj.target = "";
		obj.onclick = new Function( "changelink( '" + strUrl + "', " + x + ", " + y + ", " + width + ", " + height + ")");
	}
}
	
function changelink( strUrl, x, y, width, height)
{
	window.open( strUrl, "popup_msg", "scrollbars=no,resizable=no,screenX=" + x + ",screenY=" + y + ",width=" + width + ",height=" + height + "");
}

function IsNetscapeOnMac()
{
	var agent = window.navigator.userAgent;
	//Is the user running Netscape browser?
	if ( ( agent.indexOf('Mozilla') != -1 ) && ( agent.indexOf('compatible')== -1 ) )
	{
		//Yes.
		//Are they using a Macintosh?
		if ( agent.indexOf('Macintosh') != -1 )
		{	//Yes.
			return true;
		} else {
			//No.
			return false;
		}
	} else {
		//No
		return false;
	}
}

function IsExplorerOnMac()
{
	var agent = window.navigator.userAgent;
	//Is the user running Internet Explorer?
	if ( ( agent.indexOf('Mozilla') != -1 )
		&& ( agent.indexOf('compatible') != -1 )
		&& ( agent.indexOf('MSIE')!= -1 ) )
	{
		//Yes.
		//Are they using a Macintosh?
		if ( agent.indexOf('Mac_PowerPC') != -1 )
		{	//Yes.
			return true;
		} else {
			//No.
			return false;
		}
	} else {
		//No
		return false;
	}
}

function IsNetscape6() {
	return ( navigator.appName == "Netscape" && navigator.appVersion.charAt(0) == "5" );
}
	
function IsAOL6O( agent)
{
	//Is the user running AOL 6.0?
	if ( ( agent.indexOf('Mozilla') != -1 )
		&& ( agent.indexOf('compatible') != -1 )
		&& ( agent.indexOf('MSIE')!= -1 )
		&& ( agent.indexOf('AOL ')!= -1 )
		)
	{
		//Yes.
		return true;

	} else {
		//No
		return false;
	}
}

function launchCenter( agent, url, name, height, width, extraspec) 
{
	var str = "height=" + height;
	str += ",width=" + width;
	if (window.screen) 
	{
/*	
 		var ah = screen.availHeight - 30;
 		var aw = screen.availWidth - 10;

 		var xc = (aw - width) / 2;
 		var yc = (ah - height) / 2;
*/
 		var xc = 100;
 		var yc = 100;

 		str += ",screenX=" + xc;
 		str += ",screenY=" + yc;
 		if(!IsAOL6O( agent))
 		{
 			str += ",top=" + yc;
			str += ",left=" + xc;
 		}

		 		
 		str += "," + extraspec;
	}
	return window.open(url, name, str);
}

function On3DSecureLoadEvent( agent, strFormName, strAction)
{
	var ThreeDSecureChildwin;
	var ThreeDSecurePopupName;

	window.name = 'FIPaymentPage';

	//Make sure window has a name //NOT USED
	//if (window.name == "" || window.name == null) {
	//		window.name = "OpeningWindow";
	//}
	
	ThreeDSecurePopupName = window.name + "Popup";

	ThreeDSecureChildwin = launchCenter( agent, 'about:blank', ThreeDSecurePopupName, 400, 390, 'status=yes,dependent=no,scrollbars=yes,resizable=no');
   ThreeDSecureChildwin.focus();
   
	var objForm = getFormObject( strFormName);
   
	objForm.target = ThreeDSecurePopupName;
	objForm.action = strAction;
	objForm.submit();
	//location.replace(document.referrer);
	//history.back();
}

function On3DSecureCloseLoad( strFormName, intPageMode) 
{
	window.opener.focus();
	
	var objForm = getFormObject( strFormName);
	
	objForm.action =  'Payment.aspx?mode=' + intPageMode; //See Notes in OpenAuthenticationWindow about this..
	objForm.target =  'FIPaymentPage'; //See Notes in OpenAuthenticationWindow about this..

	// change the name and id of the viewstate input field so aspnet will not recognise it anymore
	objForm.elements[0].name = "VS";
	objForm.elements[0].id = "VS";

	objForm.submit();
	
	// close the popup but
	// delay the	self.close() by 1 second
	// because some browsers on Macintosh need time for the
	// submit to execute
	if ( IsNetscape6() || IsNetscapeOnMac() || IsExplorerOnMac() )
	{
		setTimeout('self.close()',1000);
	} else {
		self.close();
	}
}

function On3DSecurePopupClosedLoad( strFormName)
{
	var objForm = getFormObject( strFormName);
	
	objForm.action =  'Payment.aspx?mode=2'; //See Notes in OpenAuthenticationWindow about this..
	objForm.submit();
}

function getFormObject( strFormName)
{
	var strForm = (document.layers) || ! (document.getElementsByName) ? "['" + strFormName + "']" : "('" + strFormName + "')[0]";
	var funcName = (document.getElementsByName) ? "document.getElementsByName" : ((document.layers) ? "document.forms" : "document.all");

	return eval( funcName + strForm);
}

	function TieButton(buttonName)
	{
		if ((event.which && event.which == 13) || (event.keyCode && event.keyCode == 13)) 
		{
			document.getElementsByName(buttonName)[0].click();
			return false;
		}
		else
			return true;
	}

function checkInstructionsField(objectID) 
{
	fld=document.forms[0][objectID];

	if (fld.value.length > 200) 
		fld.value = fld.value.substring(0,200);

	for (var j=0; j<fld.value.length;j++)	
	{
		if (fld.value.charCodeAt(j) > 128)
		{
			fld.value = fld.value.substring(0,j) + fld.value.substring(j+1, fld.value.length);
			j--;
		}
	}		
}

function UpdateCounter(field, objectID, objectWarning, allow, cntrID)
{
	var text = field.value
     	field.value = fixNewLines(text);
	field.scrollTop = field.scrollHeight;
	if (!allow)
		checkChars(objectID, objectWarning);
     	var count = fixNewLines(document.forms[0][objectID].value).length;
     	document.forms[0][cntrID].value = 248 - count;
     	if (count > 248 ) {
		field.value = field.value.substring(0,field.value.length-1);
		UpdateCounter(field, objectID, objectWarning, allow, cntrID);
	     }
	
}

function checkChars(objectID, strWarning)
{
	var blnAlerted = false
	var flds = new Array()
	flds[0]=document.forms[0][objectID]
	flds[0].value = fixNewLines(flds[0].value);
	document.forms[0][objectID].scrollTop = document.forms[0][objectID].scrollHeight;

	for (var i=0; i<flds.length;i++)
	{
		for (var j=0; j<flds[i].value.length;j++)
		{
			if (flds[i].value.charCodeAt(j) > 255)
			{
				if (!blnAlerted)
					alert(strWarning)
				blnAlerted = true
				flds[i].value = flds[i].value.substring(0,j) + flds[i].value.substring(j+1, flds[i].value.length)
				j--;
			}
		}
	} 
}

function otherGenderChange(objectID, objectOtherID)	{
	if (document.forms[0][objectOtherID].value.length > 0)
		document.forms[0][objectID].selectedIndex =  document.forms[0][objectID].length -1
	return true
}

function GenderChange(objectID, objectOtherID, objectNameID)
{
	if (document.forms[0][objectID].selectedIndex != document.forms[0][objectID].length -1)
	{
		document.forms[0][objectOtherID].value = ''
		SetInputFocus(document.forms[0][objectNameID])
	}
	else
		SetInputFocus(document.forms[0][objectOtherID])
	return true
}

function selText(keyval, ca_mode, objectID, strWarning, allow, cntrID) 
{
	if (ca_mode)
	{
		var strText;
		eval("strText = text_" + keyval + ";");
	
		if( strText.length > 248)
			strText = strText.substr( 0, 230) + " [...more text]";
		document.forms[0][objectID].value = strText;
	}
	 else 
	{
		eval("document.forms[0][objectID].value = text_" + keyval + ";");
	}
	UpdateCounter(document.forms[0][objectID], objectID, strWarning, allow, cntrID);
}

var xPos,yPos;
xPos = 0;
yPos = 0;
var isNS = (navigator.appName == "Netscape" && parseInt(navigator.appVersion) >= 4);
function pos()
{
	imgElem = document.images["_ctl0_Content__ctl0_imProduct"];
	if(imgElem==null)
	return;
	if(isNS)
	{
		xPos = eval(imgElem).x;
		yPos = eval(imgElem).y;
	}
	else
	{
        xPos = eval(imgElem).offsetLeft;
        tempEl = eval(imgElem).offsetParent;
        while (tempEl != null)
        {
			xPos += tempEl.offsetLeft;
            tempEl = tempEl.offsetParent;
        }
		 yPos = eval(imgElem).offsetTop;
		 tempEl = eval(imgElem).offsetParent;
		 while (tempEl != null)
		 {
			yPos += tempEl.offsetTop;
			tempEl = tempEl.offsetParent;
		}
		xPos = xPos + 160;

	}
}

function showEnlargeImage(object) {
	
	
	var lft,tp;
		w1 = document.images["_ctl0_Content__ctl0_imProduct"].width;
		w2 = 345;
		lft = xPos - (w2-w1);
		tp = yPos;
		document.images["bigimage"].src = document.images["_ctl0_Content__ctl0_imProduct"].src;
		object.style.left = lft;
		object.style.top = tp;
		object.style.borderColor = "Green";
        object.style.visibility = "VISIBLE";
	
}

function hideEnlargeImage(object){
	object.style.visibility = "HIDDEN";
}
function repaireFlash(id)
{
	var flashObject = document.getElementById(id);
	
	if (flashObject != null)
		flashObject.outerHTML = flashObject.outerHTML;
}

function ShowFlashPlayer(path, width, height)
{
    widthW = width + 20;
    heightW = height + 20;
    var flashWin = window.open("","", "height= " + heightW +",width=" + widthW + ",menubar=no, top=150, left=150, status=no, location=no, toolbar=no, scrollbars=no, resizable=no");
    var content = "<html><head><title></title></head><body><div style= style=\"margin:0px;padding:0px\">";
    content += "<object width='" + width + "' height='" + height + "' id='Object2'>";
    content += "<param name='movie' value='" + path + "'/>";
    content += "<embed src='" + path + "' width='" + width + "' height='" + height + "' type='application/x-shockwave-flash'>";
    content += "</object></div></body></html>";
    flashWin.document.write(content);
}

//open pop-up window
function openPopupWindow(sURL, iWidth, iHeight)
{
	var retval = ""
	retval = window.open(sURL, "wndPopUpHandle", "width="+ iWidth +", height=" + iHeight + ", menubar=no, top=0, left=0, status=no, location=no, toolbar=no, scrollbars=yes, resizable=no");
	return retval;
}

function fixNewLines(val)
{             
	if (val.indexOf('\r\n')!=-1) 
	{}
	else if (val.indexOf('\r')!=-1)
	{
		val = val.replace ( /\r/g, "\r\n" );
	}
	else if (val.indexOf('\n')!=-1)
	{
		val = val.replace ( /\n/g, "\r\n" );
	}
	else 
	{}

	return val;
}	
	

function UpdateCounter2(field, objectID, objectWarning, allow, cntrID)
{
        var ncount = ncount = countNewLines(field);
     	var count = field.value.length + ncount;
	if (count > 248) {
	  field.value = field.value.substr(0, 248-ncount);
	} 
 	document.forms[0][cntrID].value = 248 - count;
}

function filterUserInput(event,strWarning,field, objectID, allow, cntrID)
{
        var ncount = countNewLines(field);
     	var count = field.value.length + ncount;

	//var v_code = (document.all) ? event.keyCode:GV_evt.which;
	var v_letter = (event.charCode != undefined && event.charCode != 0) ? event.charCode : String.fromCharCode(event.keyCode);
	if (v_letter > 255 && !allow) {
  	   alert(strWarning);
	   return false;
	} 
	else if (event.keyCode == 13) {
     	   if (count > 246) return false;
	}
	else if (event.keyCode == 8 || (event.keyCode > 32 && event.keyCode < 47)) {
	} 
	else {
     	   if (count > 247) return false;
	}
	return true;
}

function onRecipientSubmit(objectID)
{
	var obj = document.forms[0][objectID];
	obj.value = fixNewLines(obj.value);
	return true;
}

function countNewLines(field)
{
        var ncount = 0;
	if (field.value.indexOf('\r\n')!=-1) 
	{ }
	else if (field.value.indexOf('\r')!=-1) {
		ncount = field.value.match(/\r/g).length;
	}
	else if (field.value.indexOf('\n')!=-1) {
		ncount = field.value.match(/\n/g).length;
	}
	return ncount;
}
