// $Id$
// Janmedia Interactive 
/* ----------------------------------------------------------------------
	DEFAULT VALIDATION FORMS
---------------------------------------------------------------------- */
FAILED_INPUT_BACKGROUND_COLOR = "#FEDDBC";
function checkInput(input,message)
{
	if (!input)
	{
		alert(message + "\nInput not found!");		
		return false;
	}

    if (input.type=="checkbox") 
    {
    	if (!input.checked)
    	{
	        focusFailedInput(input,message);
	        return false;
	    }
	    return true;
    }
	
    if (input.value.length==0) 
    {
        focusFailedInput(input,message);
        return false;
    }
    
    return true;
}

function checkSelect(input,message)
{
	if (!input)
	{
		alert(message + "\nInput not found!");		
		return false;
	}
    if (input.disabled == true) return true;
    if (input.selectedIndex==0) 
    {
        focusFailedInput(input,message);
        return false;
    }
    return true;
}

function focusFailedInput(input, message)
{
    input.oldOnBlur = input.onblur;
    input.oldBackgroundColor = input.style.backgroundColor;
    input.style.backgroundColor = FAILED_INPUT_BACKGROUND_COLOR;
    if (message) alert(message);
    input.onblur = onAfterBlurFailedInput; 
    if (!input.disabled) input.focus();
}

function markFailedInput(input)
{
    input.style.border = "1px solid red";
}

function checkEmail(input,message)
{
    if (!_checkEmail(input.value)) 
    {
        focusFailedInput(input,message);
        return false;
    }
    return true;
}

function _checkEmail(email)
{
	if (email == "") return false;
  template=/^[0-9a-z]+[0-9a-z._-]*\@[0-9a-z]+[0-9a-z._-]*\.[0-9a-z]{2,}$/i;
  if (template.test(email) == false) return false;
	return true;
}

function checkNumberInput(input,message)
{
  
  //template=/^[0-9]?$/i;
  template=/^[0-9]*$/i;
  //if (template.test(email) == false) return false;

    if ((input.value.length==0) || !template.test(input.value))
    {
        focusFailedInput(input,message);
        return false;
    }
    return true;
}

function checkCheckboxes(input,message)
{
	if (!input)
	{
        alert(message);
        return false;
	}
  	if (input.length)
    {
        var i;
        for (i=0; i<input.length; i++)
        {
            if (input[i].checked)
            {
                return true;
            }
        }
        alert(message);
        if (!input[0].disabled) input[0].focus();
        return false;
    }
    return true;
}

function onAfterBlurFailedInput()
{
    if (this.oldOnBlur)
    {
        this.onblur = this.oldOnBlur; 
    }
    if (this.oldBackgroundColor!=null)
    {
        this.style.backgroundColor = this.oldBackgroundColor;
    }
}

/*
  Dodalem 3 parametr, bo jest wymagana zgodnosc w d :(
*/
function setCountry(countryinput, stateinput, newversion)
{
	/*
  if (newversion == true)
  {
    if (stateinput.value != "")
      countryinput.value="US";
  }
  else 
  {
  */

	if (stateinput.value != "Outside US")
		countryinput.value="United States";

	if (countryinput.value!="United States")
		countryinput.value="US"
}

function setState(countryinput, stateinput, newversion)
{
  if (newversion == true)
  {
    if (countryinput.value != "US")
      stateinput.value = "";
  }
  else 
    if (countryinput.value != "United States")
      stateinput.value = "Outside US";
}

/* ----------------------------------------------------------------------
	WINDOW AVAIBLE HEIGHT
---------------------------------------------------------------------- */
function getScreenSize(mode)
{
	if (self.innerHeight) // all except Explorer
	{
        if(mode == 'width') return self.innerWidth;
        else return self.innerHeight;
	}
	else if (document.body) // other Explorers
	{
        if(mode == 'width') return document.body.clientWidth;
        else return  document.body.clientHeight;
	}
	return 0;
}

/* ----------------------------------------------------------------------
	MOUSE OVER
---------------------------------------------------------------------- */
var overImgs = new Array();
function onTopMenuOver(img)
{
	img.srcOld = img.src;
	var s = img.src.replace(/\%23[^&]*/ig, "%23747474");	
	//alert(img.src + "\n" + s);
	setImgSrc(img,s);
}
function onTopMenuOut(img)
{
	setImgSrc(img,img.srcOld);
}
function setImgSrc(img,s)
{
	if (overImgs[s]==null)
	{
		(overImgs[s]=new Image()).src=s;
	}
	if (img.src!=s) img.src=overImgs[s].src;
}

function onRollOver(img){
	var s = img.src;
	if (s.match(/\.jpg$/)){
		setImgSrc(img,s.replace(/\.jpg$/, "_over.jpg"));
		return true;
	}
	if (s.match(/\.png$/)){
		setImgSrc(img,s.replace(/\.png$/, "_over.png"));
		return true;
	}
	return false;
}

function onRollOut(img){
	var s = img.src;
	if (s.match(/\.jpg$/)){
		setImgSrc(img,s.replace(/_over\.jpg$/, ".jpg"));
		return true;
	}
	if (s.match(/\.png$/)){
		setImgSrc(img,s.replace(/_over\.png$/, ".png"));
		return true;
	}
	return false;
}


/* ----------------------------------------------------------------------
	FLASH
---------------------------------------------------------------------- */
flash_versions = 20;

var flash = new Object();
flash.installed=false;
flash.version='0.0';

if (navigator.plugins && navigator.plugins.length) {
	for (x=0; x < navigator.plugins.length; x++) {
		if (navigator.plugins[x].name.indexOf('Shockwave Flash') != -1) {
			flash.version = navigator.plugins[x].description.split('Shockwave Flash ')[1];
			flash.installed = true;
			break;
		}
	}
}

else if (window.ActiveXObject) {
	for (x = 2; x <= flash_versions; x++) {
		try {
			oFlash = eval("new ActiveXObject('ShockwaveFlash.ShockwaveFlash." + x + "');");
			if(oFlash) {
				flash.installed = true;
				flash.version = x + '.0';
			}
		}
		catch(e) {}
	}
}
/**
 * Generates a browser-specific Flash tag. Create a new instance, set whatever
 * properties you need, then call either toString() to get the tag as a string, or
 * call write() to write the tag out.
 */

/**
 * Creates a new instance of the FlashTag.
 * src: The path to the SWF file.
 * width: The width of your Flash content.
 * height: the height of your Flash content.
 */
function FlashTag(src, width, height,version)
{
    this.src       = src;
    this.width     = width;
    this.height    = height;
    this.version   = version;
    this.id        = null;
    this.bgcolor   = '000000';
    this.flashVars = null;
}

/**
 * Sets the Flash version used in the Flash tag.
 */
FlashTag.prototype.setVersion = function(v)
{
    this.version = v;
}

/**
 * Sets the ID used in the Flash tag.
 */
FlashTag.prototype.setId = function(id)
{
    this.id = id;
}

/**
 * Sets the background color used in the Flash tag.
 */
FlashTag.prototype.setBgcolor = function(bgc)
{
    this.bgcolor = bgc;
}

/**
 * Sets any variables to be passed into the Flash content. 
 */
FlashTag.prototype.setFlashvars = function(fv)
{
    this.flashVars = fv;
}

/**
 * Get the Flash tag as a string. 
 */
FlashTag.prototype.toString = function()
{
    var ie = (navigator.appName.indexOf ("Microsoft") != -1) ? 1 : 0;
    var flashTag = new String();
    if (ie)
    {
        flashTag += '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" ';
        if (this.id != null)
        {
            flashTag += 'id="'+this.id+'" ';
        }
        flashTag += 'codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version='+this.version+'" ';
        flashTag += 'width="'+this.width+'" ';
        flashTag += 'height="'+this.height+'" align="middle">';
		flashTag += '<param name="scale" value="noscale" />';
        flashTag += '<param name="movie" value="'+this.src+'"/>';
        flashTag += '<param name="quality" value="high"/>';
        flashTag += '<param name="bgcolor" value="#'+this.bgcolor+'"/>';
        if (this.flashVars != null)
        {
            flashTag += '<param name="flashvars" value="'+this.flashVars+'"/>';
        }
        flashTag += '</object>';

    }
    else
    {
        flashTag += '<embed src="'+this.src+'" ';
        flashTag += 'quality="high" '; 
        flashTag += 'bgcolor="#'+this.bgcolor+'" ';
        flashTag += 'width="'+this.width+'" ';
        flashTag += 'height="'+this.height+'" ';
		flashTag += 'scale="noscale" ';
        flashTag += 'height="'+this.height+'" align="middle" ';
        flashTag += 'type="application/x-shockwave-flash" ';
        if (this.flashVars != null)
        {
            flashTag += 'flashvars="'+this.flashVars+'" ';
        }
        if (this.id != null)
        {
            flashTag += 'name="'+this.id+'" ';
        }
        flashTag += 'pluginspage="http://www.macromedia.com/go/getflashplayer">';
        flashTag += '</embed>';
    }
    return flashTag;
}

/**
 * Write the Flash tag out. Pass in a reference to the document to write to. 
 */
FlashTag.prototype.write = function(doc)
{
    doc.write(this.toString());
}

function MM_checkPlugin(src,width,height,flashVars) { 
	if (parseInt(flash.version)<6 || !flash.installed)
	{
		document.write('Flash Plugin is required to display the contents of this site.<br>Please <a href="http://www.macromedia.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" target="_blank"><font color="green">click this link</font></a> to upgrade.<br><br>');	 
	}
	else if (flash.installed)
	{
        var uid = new Date().getTime();
	    var tag = new FlashTag(src,width,height,'6,0,0,0');
	    tag.setFlashvars('lcId='+uid+'&' + flashVars);
	    tag.write(document);
	}
}

/* ----------------------------------------------------------------------
	CHECKOUT - MATH
---------------------------------------------------------------------- */
function formatPrice(d,decimal)
{
	if (typeof(decimal)=='undefined') decimal=2;
	var d2 = Math.floor(d);
	var s = "" + ((d*100-d2*100));	
	if (s.length>2) s=s.substr(0,2);
	else while (s.length<2) s="0"+s;
	
	var s1=""+d2;
	if (s1.length>3) s1=s1.substr(0,s1.length-3) + "," + s1.substr(s1.length-3,s1.length)
	return s1+"."+s; 
}
function PopupImage(url,width,height)
{
    var windowheight = height+40;
    var windowwidth = width+20;

    var left = (screen.width - windowwidth)/2;
    var top = (screen.height - windowheight)/2 - 18;
    
    var scrollbars = "no";
    
    if (left<0) { scrollbars = "yes"; left = 32; windowwidth = screen.width - 2*left; }
    if (top<0) { scrollbars = "yes"; top = 32; windowheight =  screen.height - 2*top - 18; top = top - 18; }

	var options = "toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=no,copyhistory=no"
	    + ",scrollbars=" + scrollbars
        + ",width=" + windowwidth 
        + ",height=" + windowheight
        + ",left=" + left 
        + ",top=" + top;

    var win = window.open(url,"popup",options);
	if (win) win.focus();
}

