/* ********************************** */
/* Poly-Bro js website utils          */
/* 22 jun 2005 by Eric Grossi         */
/* egrossi@simplestnet.com            */
/* Copyright 2005 SimplestNet Inc.    */
/* ********************************** */

///////////////////////////////////////////////////////////////////////////
function writeFlash(src, w, h, q, extra) {
    if (!extra) extra="";

    var line='<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" '+
                   'codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" '+
                   'width="'+w+'" height="'+h+'" '+extra+'><param name="movie" value="'+src+'">'+
                   '<param name="quality" value="'+q+'">'+
                   '<embed src="'+src+'" quality="'+q+'" width="'+w+'" height="'+h+'" type="application/x-shockwave-flash" '+
                   'pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" '+extra+
                   '></embed></object>';
    document.write(line);
}
///////////////////////////////////////////////////////////////////////////
var rot_count=0;
function rotateImages(images, t, a, s) {
    if ( images.length < 2 ) return;

    this.imgList=new Array();
    this.sID="_rot_"+rot_count;
    this.loop=5;
    var align="";
    var style="";

    if (a) align="align='"+a+"'";
    if (s) style="style='"+s+"'";
    if (t) this.loop=t;

    for (var i=0; i<images.length; i++) {
		this.imgList[i] = new Image();
		this.imgList[i].src = images[i];
	}

    document.write("<img id='_rot_"+rot_count+"' src='"+this.imgList[0].src+"' alt='' "+align+" "+style+"/>");
    this.elem=document.getElementById(this.sID);
    this.elem.rotator=this;
    this.current=0;
    window.setInterval("document.getElementById('"+this.sID+"').rotator._rotate_img()", this.loop*1000);
    rot_count++;
}

rotateImages.prototype._rotate_img=function() {
    this.current++;
    if (this.current>=this.imgList.length) this.current=0;
    this.elem.src=this.imgList[this.current].src;
}
///////////////////////////////////////////////////////////////////////////
function popWindow(link, name, width, height, top, left, scroll, sizable)
{
	var tscroll="no", tsizable="no", src, f, win;

	if ( undefined==link ) alert("Error: an url is required");
	if ( undefined==name || 0==name.length ) var name = "_blank";
	if ( undefined==width || 0==width ) var width=450;
	if ( undefined==height || 0==height ) var height=600;
	if ( undefined==top ) var top=50;
	if ( undefined==left ) var left=50;
	if ( scroll ) tscroll="yes";
	if ( sizable ) tsizable="yes";

	f = "top="+top+",left="+left+",width="+width+",height="+height+
		",resizable="+tscroll+",scrollbars="+tsizable;
	win = window.open(link, name, f);
	//win.resizeTo(width, height);
	win.focus();

    // patch for flick link in stupid ie
    if ( window.pre_img ) {
        for ( var i = 0; i < window.pre_img.length; i++ ) {
            src = window.pre_img[i].src;
    		window.pre_img[i] = new Image();
    		window.pre_img[i].src = src;
    	}
    }

    return win;
}
///////////////////////////////////////////////////////////////////////////
function preloadImages() {
	if ( !window.pre_img )
		window.pre_img=new Array();

	var l=window.pre_img.length;

	for (var i=0; i<preloadImages.arguments.length; i++) {
		window.pre_img[i+l] = new Image();
		window.pre_img[i+l].src = preloadImages.arguments[i];
	}
}
///////////////////////////////////////////////////////////////////////////
function validatemail()
{
	with(document.forms['sendmail'])
	{
		submit.disabled = true;
		
		if ( trim(name.value) == "")
		{
			alert(MSG_Fname);
			name.focus();
			submit.disabled = false;
			return false;
		}
		if ( trim(address.value) == "" )
		{
			alert(MSG_Email);
			address.focus();
			submit.disabled = false;
			return false;
		}
		if ( address.value.indexOf("@") < 0 || address.value.indexOf(".") < 0 )
		{
			alert(MSG_Email2);
			address.focus();
			submit.disabled = false;
			return false;
		}
		if ( trim(message.value) == "")
		{
			alert(MSG_Fmessage);
			message.focus();
			submit.disabled = false;
			return false;
		}
	}
	return true;
}
///////////////////////////////////////////////////////////////////////////
function trim(strText) { 
    // this will get rid of trailing spaces 
    while (strText.substring(0,1) == ' ') 
        strText = strText.substring(1, strText.length);
    while (strText.substring(strText.length-1,strText.length) == ' ')
        strText = strText.substring(0, strText.length-1);

   return strText;
}
///////////////////////////////////////////////////////////////////////////
var valid = '0123456789.'; // define valid characters
function isValid(string,allowed)
{
    for (var i=0; i< string.length; i++)
	{
       if (allowed.indexOf(string.charAt(i)) == -1)
          return false;
    }
    return true;
}