
/* Functions for new style rollovers; these are actual event handlers,   not just called from an event handler. */
function rollover_handler(e) {
  // get the source element in a cross-browser way
  if (window.event) { thisimg = window.event.srcElement;
  } else if (e.target) { thisimg = e.target;
  } else { return;
  }
  thisimg.src = thisimg.src.replace(/(\.[a-z0-9]+)$/i,'_on$1');
}
function rollout_handler(e) {
  // get the source element in a cross-browser way
  if (window.event) { thisimg = window.event.srcElement;
  } else if (e.target) { thisimg = e.target;
  } else { return;
  }
  thisimg.src = thisimg.src.replace(/_on(\.[a-z0-9]+)$/i,'$1');
}


/* post variables using <a href="javascript:postwith('post.aspx',{user:'peter',cc:'aus'})">link text</a>*/
function postwith (to,p) {
  var myForm = document.createElement("form");
  myForm.method="post" ;
  myForm.action = to ;
  for (var k in p) {
    var myInput = document.createElement("input") ;
    myInput.setAttribute("name", k) ;
    myInput.setAttribute("value", p[k]);
    myForm.appendChild(myInput) ;
  }
  document.body.appendChild(myForm) ;
  myForm.submit() ;
  document.body.removeChild(myForm) ;
}


function getWinSize() {
  var myWidth = 0, myHeight = 0;
  var dimensions = new Array();
  
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  
  dimensions[0] = myWidth;
  dimensions[1] = myHeight;
  
  return dimensions;
  
}


function getRadioValue(radioGroupName) {
        var value = null;
        
        var radios = document.getElementsByTagName('input');
        for (var i=0; i<radios.length; i++) {
                var input = radios[ i ];    
                if (input.type == 'radio' && input.name == radioGroupName && input.checked) {                          
                        value = input.value;
                        break;
                }
        }
        return value;
}




function checkFields(fields, msg){
	var missing = false;

	if(isArray(fields)){
		for (var i=0; i<fields.length; i++) {
			if($(fields[i]).value.empty()) missing = true;
		}
	}
	else{
		if($(fields).value.empty()) missing = true;
	}
	
	if(missing){
		if(msg != '') alert(msg);
		return false;
	}
	else return true;
}



function isArray(obj) {
	return (obj.constructor.toString().indexOf('Array') != -1);
}


