// JavaScript Document

// Pop Up Message
function MM_popupMsg(msg) { //v1.0
  alert(msg);
}

// Pop Up Confirm Message
function GP_popupConfirmMsg(msg) { //v1.0
  document.MM_returnValue = confirm(msg);
}

// Jump Menu
function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

// Copy Field
function NM_copyField(f1,f2){
 	MM_findObj(f2).value=MM_findObj(f1).value;
}

// Focus Field
function NM_focusfield(objName){
	var obj = MM_findObj(objName); 
	obj.focus();obj.select();
}

// Toggle checkboxes
function flevToggleCheckboxes() { // v1.1
	// Copyright 2002, Marja Ribbers-de Vroed, FlevOOware (www.flevooware.nl/dreamweaver/)
	var sF = arguments[0], bT = arguments[1], bC = arguments[2], oF = MM_findObj(sF);
    for (var i=0; i<oF.length; i++) {
		if (oF[i].type == "checkbox") {if (bT) {oF[i].checked = !oF[i].checked;} else {oF[i].checked = bC;}}} 
}

// Macromedia Validate Form

function MM_validateForm() { //v4.0
  if (document.getElementById){
    var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
    for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=document.getElementById(args[i]);
      if (val) { nm=val.name; if ((val=val.value)!="") {
        if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
          if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
        } else if (test!='R') { num = parseFloat(val);
          if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
          if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
            min=test.substring(8,p); max=test.substring(p+1);
            if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
      } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
    } if (errors) alert('The following error(s) occurred:\n'+errors);
    document.MM_returnValue = (errors == '');
} }

// Disable Button on submit
function GP_DisableSubmitButton(el) { //v1.0
  el.disabled=true;
}

// Check the radion button
function NM_checkRadBut(f1){
 	chkButton = document.getElementById(f1);
	chkButton.checked = true;
}

// Check the number of characters
function XMCheckTextarea(val,num,msg){
	if (val.value.length>num) {
		val.value=val.value.substring(0,num);
		alert(unescape(msg))
	}
}

// Yaromat Validate 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=='');
}


// Massiomo Reformat textfield
function tmt_reFormat(f,re,s){
	fv=MM_findObj(f).value;var rex=new RegExp(unescape(re),"g");
	if(rex.test(fv)){MM_findObj(f).value=fv.replace(rex,unescape(s));}
}

// Massiomo Regular Expression Validator
function tmt_regExpValidator(f,re,eMsg,ru,r){
	var myErr="";var fv=MM_findObj(f).value;var rex=new RegExp(unescape(re));
	var t=eval(ru+rex.test(fv));if(r){if(fv.length<=0||!t){alert(unescape(eMsg));myErr+="eMsg";}}
	else if(fv.length>0&&!t){alert(unescape(eMsg));myErr+="eMsg";}document.MM_returnValue=(myErr=="");
}

// Set Text of Testfield from listbox
function NM_setTextOfTextfieldFromListbox(objName,x,newText) { //v3.0
  var text = MM_findObj(newText).options[MM_findObj(newText).selectedIndex].value;
  var obj = MM_findObj(objName); 
  if (obj) obj.value = text;
}


// Trim spaces
function Trim (string) { 
	if (string.length > 0) { 
	string = RemoveLeadingSpaces (string); 
	} 
	if (string.length > 0) { 
	string = RemoveTrailingSpaces(string); 
	} 
	return string; 
} 

function RemoveLeadingSpaces(string) {while(string.substring(0, 1) == " ") { 
	string = string.substring(1, string.length); 
	} 
	return string; 
} 

function RemoveTrailingSpaces(string) { 
	while(string.substring((string.length - 1), string.length) == " ") { 
	string = string.substring(0, (string.length - 1)); 
	} 
	return string; 
} 

// Create Nice Menu Link
function NM_menuLink(objName,objLink) {
	var objName = MM_findObj(objName);
	var objLink = MM_findObj(objLink);
	
	var strOut=" "; // replace this
	var strAdd="_"; // with this


	if (objName) temp = "" + objName.value.toLowerCase(); // temporary holder
	//temp = temp.toLowerCase() // Convert to lower case
	
	//remove qoutes
	temp = temp.replace("'", "");
	
	while (temp.indexOf(strOut)>-1) {
	pos=temp.indexOf(strOut);
	temp = ""+(temp.substring(0,pos)+strAdd+temp.substring((pos+strOut.length),temp.length));
	}

	if (objLink) objLink.value = filterNum(temp);
	// remove special characters like "$" and "," etc...
	
	function filterNum(str){
	  re =/\'|\‘|\’|\`|\$|\&|\,|\@|\#|\~|\%|\*|\^|\/|\&|\(|\)|\+|\=|\[|\-|\]|\[|\}|\{|\;|\:|\"|\<|\>|\?|\||\\|\!|\…|\¤|\“|\”|\£|\—|\./g;
	  return str.replace(re, "");
	}
	
	//alert(objLink.value);
}

/*
	"'"),chr(34),"'")		 'qoute 
	"–","&ndash;"),"–","&ndash;")	 'odd en dash!!
	"–","&ndash;"),"–","&ndash;")	 'en dash	
	"","&mdash;"),"—","&mdash;")	 'em dash
	"˜","&tilde;"),"˜","&tilde;")	 'Small tilde	
	"","&trade;"),"™","&trade;")	 'Trade mark sign
	"","&dagger;"),"†","&dagger;")	 'Dagger
	"","&Dagger;"),"†","&Dagger;")	 'Double dagger
	"","&permil;"),"‰","&permil;")	 'Per mile sign
	"","&lsquo;"),"‘","&lsquo;")	 'left quote
	"","&rsquo;"),"’","&rsquo;")	 'right quote				
	"","&ldquo;"),"“","&ldquo;")	 'left double quote						 
	"","&rdquo;"),"”","&rdquo;")	 'right double quote  	
	"","&iexcl;"),"¡","&iexcl;")	 'inverted exclamation 		 
	"","&cent;"),"¢","&cent;")		 'cent sign		
	"","&pound;"),"£","&pound;")	 'pound sterling  
	"","&euro;"),"€","&euro;")		 'euro sign 
	"","&hellip;"),"…","&hellip;")	 'Horizontal ellipsis  		 
	"","&curren;"),"¤","&curren;")	 'general currency sign		 
	"¥","&yen;"),"¥","&yen;") 		 'yen sign
	"¦","&brvbar;"),"¦","&brvbar;")	 'broken vertical bar		 
	"§","&sect;"),"§","&sect;")		 'section sign 
	"¨","&uml;"),"¨","&uml;")		 'umlaut (dieresis) 
	"©","&copy;"),"©","&copy;")		 'copyright  
	"ª","&ordf;"),"ª","&ordf;")	 	 'feminine ordinal		 
	"«","&laquo;"),"«","&laquo;") 	 'left angle quote, guillemotleft
	"¬","&not;"), "¬","&not;")  		 'not sign  
	"­","&shy;"), "­","&shy;")  		 'soft hyphen 
	"®","&reg;"), "®","&reg;") 		 'registered trademark
	"¯","&macr;"), "¯","&macr;") 	 'macron accent
	"°","&deg;"), "°","&deg;")  		 'degree sign
	"±"," &plusmn;"), "±","&plusmn;") 'plus or minus 
	"²","&sup2;"), "²","&sup2;") 	 'superscript two
	"³","&sup3;"), "³","&sup3;") 	 'superscript three
	"´","&acute;"), "´","&acute;") 	 'acute accent 
	"µ","&micro;"), "µ","&micro;") 	 'micro sign
	"¶","&para;"), "¶","&para;") 	 'paragraph sign
	"·","&middot;"), "·","&middot;")  'middle dot
	"¸","&cedil;"), "¸","&cedil;")  	 'cedilla
	"²","&sup1;"), "²","&sup1;") 	 'superscript one
	"º","&ordm;"), "º","&ordm;")		 'masculine ordinal 
	"•","&bull;"), "•","&bull;")		 'Bullet
	"»","&raquo;"), "»","&raquo;") 	 'right angle quote, guillemotright
	"¼","&frac14;"), "¼","&frac14;")  'fraction one-fourth
	"½","&frac12;"), "½","&frac12;")  'fraction one-half 
	"¾","&frac34;"), "¾","&frac34;")  'fraction three-fourths
	"¿","&iquest;"), "¿","&iquest;")  'inverted question mark
	"À","&Agrave;"), "À","&Agrave;")  'capital A, grave accent
	"Á","&Aacute;"), "Á","&Aacute;")  'capital A, acute accent
	"Â","&Acirc;"), "Â","&Acirc;")	 'capital A, circumflex accent
	"Ã","&Atilde;"), "Ã","&Atilde;")  'capital A, tilde
	"Ä","&Auml;"), "Ä","&Auml;")		 'capital A, dieresis or umlaut mark
	"Å","&Aring;"), "Å","&Aring;") 	 'capital A, ring
	"Æ","&AElig;"), "Æ","&AElig;") 	 'capital AE diphthong (ligature)
	"Ç","&Ccedil;"), "Ç","&Ccedil;")  'capital C, cedilla  
	"È","&Egrave;"), "È","&Egrave;")  'capital E, grave accent
	"É","&Eacute;"), "É","&Eacute;")  'capital E, acute accent 
	"Ê","&Ecirc;"), "Ê","&Ecirc;") 	 'capital E, circumflex accent
	"Ë","&Euml;"), "Ë","&Euml;") 	 'capital E, dieresis or umlaut mark
	"Ì","&Igrave;"), "Ì","&Igrave;")  'capital I, grave accent
	"Í","&Iacute;"), "Í","&Iacute;")  'capital I, acute accent 
	"Î","&Icirc;"), "Î","&Icirc;") 	 'capital I, circumflex accent
	"Ï","&Iuml;"), "Ï","&Iuml;")		 'capital I, dieresis or umlaut mark
	"Ð","&ETH;"), "Ð","&ETH;")  		 'capital Eth, Icelandic
	"Ñ","&Ntilde;"), "Ñ","&Ntilde;")  'capital N, tilde
	"Ò","&Ograve;"), "Ò","&Ograve;")  'capital O, grave accent 
	"Ó","&Oacute;"), "Ó","&Oacute;")  'capital O, acute accent 
	"Ô","&Ocirc;"), "Ô","&Ocirc;") 	 'capital O, circumflex accent 
	"Õ","&Otilde;"), "Õ","&Otilde;")  'capital O, tilde 
	"Ö","&Ouml;"), "Ö","&Ouml;") 	 'capital O, dieresis or umlaut mark
	"×","&times;"), "×","&times;")  	 'multiply sign
	"Ø","&Oslash;"), "Ø","&Oslash;")  'capital O, slash 
	"Ù","&Ugrave;"), "Ù","&Ugrave;")  'capital U, grave accent
	"Ú","&Uacute;"), "Ú","&Uacute;")  'capital U, acute accent
	"Û","&Ucirc;"), "Û","&Ucirc;") 	 'capital U, circumflex accent 
	"Ü","&Uuml;"), "Ü","&Uuml;") 	 'capital U, dieresis or umlaut mark
	"Ý","&Yacute;"), "Ý","&Yacute;")  'capital Y, acute accent
	"Þ","&THORN;"), "Þ","&THORN;")    'capital THORN, Icelandic
	"ß","&szlig;"), "ß","&szlig;") 	 'small sharp s, German (sz ligature)
	"à","&agrave;"), "à","&agrave;")  'small a, grave accent
	"á","&aacute;"), "á","&aacute;")  'small a, acute accent
	"â","&acirc;"), "â","&acirc;")  	 'small a, circumflex accent
	"ã","&atilde;"), "ã","&atilde;")  'small a, tilde
	"ä","&auml;"), "ä","&auml;") 	 'small a, dieresis or umlaut mark
	"å","&aring;"), "å","&aring;") 	 'small a, ring
	"æ","&aelig;"), "æ","&aelig;") 	 'small ae diphthong (ligature)
	"ç","&ccedil;"), "ç","&ccedil;")  'small c, cedilla
	"è","&egrave;"), "è","&egrave;")  'small e, grave accent
	"é","&eacute;"), "é","&eacute;")  'small e, acute accent
	"ê","&ecirc;"), "ê","&ecirc;")  	 'small e, circumflex accent
	"ë","&euml;"), "ë","&euml;") 	 'small e, dieresis or umlaut mark
	"ì","&igrave;"), "ì","&igrave;")  'small i, grave accent 
	"í","&iacute;"), "í","&iacute;")  'small i, acute accent
	"î","&icirc;"), "î","&icirc;") 	 'small i, circumflex accent
	"ï","&iuml;"), "ï","&iuml;")  	 'small i, dieresis or umlaut mark
	"ð","&eth;"), "ð","&eth;") 		 'small eth, Icelandic
	"ñ","&ntilde;"), "ñ","&ntilde;")  'small n, tilde
	"ò","&ograve;"), "ò","&ograve;")  'small o, grave accent
	"ó","&oacute;"), "ó","&oacute;")  'small o, acute accent
	"ô","&ocirc;"), "ô","&ocirc;") 	 'small o, circumflex accent
	"õ","&otilde;"), "õ","&otilde;")  'small o, tilde
	"ö","&ouml;"), "ö","&ouml;") 	 'small o, dieresis or umlaut mark
	"÷","&divide;"), "÷","&divide;")  'division sign
	"ø","&oslash;"), "ø","&oslash;")  'small o, slash
	"ù","&ugrave;"), "ù","&ugrave;")  'small u, grave accent
	"ú","&uacute;"), "ú","uacute;") 	 'small u, acute accent
	"û","&ucirc;"), "û","&ucirc;")  	 'small u, circumflex accent
	"ü","&uuml;"), "ü","&uuml;")  	 'small u, dieresis or umlaut mark
	"ý","&yacute;"), "ý","&yacute;")	 'small y, acute accent
	"þ","&thorn;"), "þ","&thorn;")	 'small thorn, Icelandic
	"ÿ","&yuml;"), "ÿ","&yuml;")		 'small y, dieresis or umlaut mark

*/
