/* 
......................................................................
Web services by iContext Internet | www.icontext.com
All code (c) iContext / client, all rights reserved.
......................................................................
*/

// need to window.onload any js window load calls due to niftyCube needing to be last js call
// e.g. 
// window.onload=function(){
// MM_preloadImages("/assets/images/ui/EXAMPLE.gif");
// }

/************************ DISABLE TEXT SELECT 
document.onselectstart=new Function('return false');
	function ds(e){
		return false;
	}
	function ra(){
		return true;
	}
document.onmousedown=ds;document.onclick=ra;
*/

/************************ START CREATE COOKIE */
function createCookie(name,value,days) {
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  }
  else var expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
}
 
function readCookie(name) {
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  for(var i=0;i < ca.length;i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  }
  return null;
}
/************************ END CREATE COOKIE */

/************************ START INCREASE / DESCREASE FONT SIZE */
// http://nicusor.com/programming-stuff/javascript-text-resize/
function fontResize(size,unit,id){
var vfontsize = document.getElementById(id);
	if(vfontsize){
		vfontsize.style.fontSize = size + unit;
    	createCookie("textsizestyle", textsize, 365);
	}
}

function fontResizeReset(unit,id){
var vfontsize = document.getElementById(id);
var textsize = 100;
	if(vfontsize){
		vfontsize.style.fontSize = 100 + unit;
    	createCookie("textsizestyle", textsize, 365);
	}
}

var textsize = 100;
function changeTextSize(up){
  if(up){
   textsize = parseFloat(textsize)+10;
  }else{
   textsize = parseFloat(textsize)-10;
  }
}
/************************ END INCREASE / DESCREASE FONT SIZE */

/******************** START SET / CLEAR TEXTBOX */
function clickClear(thisField, defaultText) {
	if (thisField.value == defaultText) {
	thisField.value = "";
	}
}

function clickRecall(thisField, defaultText) {
	if (thisField.value == "") {
	thisField.value = defaultText;
	}
}
/******************** END SET / CLEAR TEXTBOX */

/****************************** START SHOW / HIDE DIV */
function showHide(thisID) {
	var e = document.getElementById(thisID);
	if(e.style.display == 'block')
		e.style.display = 'none';
	else
	e.style.display = 'block';
}
/****************************** END SHOW / HIDE DIV */

/******************** START TOGGLE DIV */
// http://www.netlobo.com/div_hiding.html
function toggleLayer( whichLayer ) {
	var elem, vis;
	if( document.getElementById ) // this is the way the standards work
		elem = document.getElementById( whichLayer );
	else if( document.all ) // this is the way old msie versions work
		elem = document.all[whichLayer];
	else if( document.layers ) // this is the way nn4 works
		elem = document.layers[whichLayer];
		vis = elem.style;
	// if the style.display value is blank we try to figure it out here
	if(vis.display==''&&elem.offsetWidth!=undefined&&elem.offsetHeight!=undefined)
		vis.display = (elem.offsetWidth!=0&&elem.offsetHeight!=0)?'block':'none';
		vis.display = (vis.display==''||vis.display=='block')?'none':'block';
} 
/******************** END TOGGLE DIV */

/***************************** START MM FIND OBJECT */
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
/***************************** END MM FIND OBJECT */

/***************************************** START MM POP ALERT */
function MM_popupMsg(msg) { //v1.0
  alert(msg);
}
/***************************************** END MM POP ALERT */

/******************** START YAROMAT CHECK FORM */
function YY_checkform() { //v4.71
//copyright (c)1998,2002 Yaromat.com
  var a=YY_checkform.arguments,oo=true,v='',s='',err=false,r,o,at,o1,t,i,j,ma,rx,cd,cm,cy,dte,at;
  for (i=1; i<a.length;i=i+4){
    if (a[i+1].charAt(0)=='#'){r=true; a[i+1]=a[i+1].substring(1);}else{r=false}
    o=MM_findObj(a[i].replace(/\[\d+\]/ig,""));
    o1=MM_findObj(a[i+1].replace(/\[\d+\]/ig,""));
    v=o.value;t=a[i+2];
    if (o.type=='text'||o.type=='password'||o.type=='hidden'){
      if (r&&v.length==0){err=true}
      if (v.length>0)
      if (t==1){ //fromto
        ma=a[i+1].split('_');if(isNaN(v)||v<ma[0]/1||v > ma[1]/1){err=true}
      } else if (t==2){
        rx=new RegExp("^[\\w\.=-]+@[\\w\\.-]+\\.[a-zA-Z]{2,4}$");if(!rx.test(v))err=true;
      } else if (t==3){ // date
        ma=a[i+1].split("#");at=v.match(ma[0]);
        if(at){
          cd=(at[ma[1]])?at[ma[1]]:1;cm=at[ma[2]]-1;cy=at[ma[3]];
          dte=new Date(cy,cm,cd);
          if(dte.getFullYear()!=cy||dte.getDate()!=cd||dte.getMonth()!=cm){err=true};
        }else{err=true}
      } else if (t==4){ // time
        ma=a[i+1].split("#");at=v.match(ma[0]);if(!at){err=true}
      } else if (t==5){ // check this 2
            if(o1.length)o1=o1[a[i+1].replace(/(.*\[)|(\].*)/ig,"")];
            if(!o1.checked){err=true}
      } else if (t==6){ // the same
            if(v!=MM_findObj(a[i+1]).value){err=true}
      }
    } else
    if (!o.type&&o.length>0&&o[0].type=='radio'){
          at = a[i].match(/(.*)\[(\d+)\].*/i);
          o2=(o.length>1)?o[at[2]]:o;
      if (t==1&&o2&&o2.checked&&o1&&o1.value.length/1==0){err=true}
      if (t==2){
        oo=false;
        for(j=0;j<o.length;j++){oo=oo||o[j].checked}
        if(!oo){s+='* '+a[i+3]+'\n'}
      }
    } else if (o.type=='checkbox'){
      if((t==1&&o.checked==false)||(t==2&&o.checked&&o1&&o1.value.length/1==0)){err=true}
    } else if (o.type=='select-one'||o.type=='select-multiple'){
      if(t==1&&o.selectedIndex/1==0){err=true}
    }else if (o.type=='textarea'){
      if(v.length<a[i+1]){err=true}
    }
    if (err){s+='* '+a[i+3]+'\n'; err=false}
  }
  if (s!=''){alert('The required information is incomplete or contains errors:\t\t\t\t\t\n\n'+s)}
  document.MM_returnValue = (s=='');
}
/******************** END YAROMAT CHECK FORM */

/******* START CHECK FIELD LENGTH (E.G. CREDIT CARD) */
function ccardLengthRestriction(elem, min, max){
	var uInput = elem.value;
	if(uInput.length >= min && uInput.length <= max){
		return true;
	}else{
		alert("Credit card number must be " +min+ " characters");
		elem.focus();
		return false;
	}
}
/******* END CHECK FIELD LENGTH (E.G. CREDIT CARD) */

/* http://javascript.internet.com/forms/validate-date.html */
function checkDate(field){
var checkstr = "0123456789";
var DateField = field;
var DateValue = "";
var DateTemp = "";
var seperator = "/";
var day;
var month;
var year;
var leap = 0;
var err = 0;
var i;
   err = 0;
   DateValue = DateField.value;
   /* Delete all chars except 0..9 */
   for (i = 0; i < DateValue.length; i++) {
	  if (checkstr.indexOf(DateValue.substr(i,1)) >= 0) {
	     DateTemp = DateTemp + DateValue.substr(i,1);
	  }
   }
   DateValue = DateTemp;
   /* Always change date to 8 digits - string*/
   /* if year is entered as 2-digit / always assume 19xx */
   if (DateValue.length == 6) {
      DateValue = DateValue.substr(0,4) + '19' + DateValue.substr(4,2); }
   if (DateValue.length != 8) {
      err = 19;}
   /* year is wrong if year = 0000 */
   year = DateValue.substr(4,4);
   if (year == 0) {
      err = 20;
   }
   /* Validation of month*/
   month = DateValue.substr(2,2);
   if ((month < 1) || (month > 12)) {
      err = 21;
   }
   /* Validation of day*/
   day = DateValue.substr(0,2);
   if (day < 1) {
     err = 22;
   }
   /* Validation leap-year / february / day */
   if ((year % 4 == 0) || (year % 100 == 0) || (year % 400 == 0)) {
      leap = 1;
   }
   if ((month == 2) && (leap == 1) && (day > 29)) {
      err = 23;
   }
   if ((month == 2) && (leap != 1) && (day > 28)) {
      err = 24;
   }
   /* Validation of other months */
   if ((day > 31) && ((month == "01") || (month == "03") || (month == "05") || (month == "07") || (month == "08") || (month == "10") || (month == "12"))) {
      err = 25;
   }
   if ((day > 30) && ((month == "04") || (month == "06") || (month == "09") || (month == "11"))) {
      err = 26;
   }
   /* if 00 ist entered, no error, deleting the entry */
   if ((day == 0) && (month == 0) && (year == 00)) {
      err = 0; day = ""; month = ""; year = ""; seperator = "";
   }
   /* if no error, write the completed date to Input-Field (e.g. 13.12.2001) */
   if (err == 0) {
      DateField.value = day + seperator + month + seperator + year;
   }
   /* Error-message if err != 0 */
   else {
      alert("Whoops! Incorrect date format entered - dd/mm/yyyy required.");
      DateField.select();
	  DateField.focus();
   }
}

function closeConfirm() {
  alert("Close window?");
    if (confirm("Are you sure?")) {
      parent.close();
    }
    else
      alert("Action cancelled"); {
    }
}

function closeNoConfirm () {
	win = top;
	win.opener = top;
	win.close();
}

