function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

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;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

function MM_refresh() {
  document.getElementById("captcha").src = "./scripts/Captcha.php";
}


// form validation function //
function chkform(lang) {
	var bFlag = true;
	var Msg = "This information is required.";
	//var Msg = "X";
	var lang;
	bFlag = checkvalue("form1","fname","T","S",1);
	if(!bFlag) { inlineMsg('fname',Msg); return false; }
	bFlag = checkvalue("form1","lname","T","S",1);
	if(!bFlag) { inlineMsg('lname',Msg); return false; }
	bFlag = checkvalue("form1","email","T","S",1);
	if(!bFlag) { inlineMsg('email',Msg); return false; }
	bFlag = checkvalue("form1","country","S","S",1);
	if(!bFlag) { inlineMsg('country',Msg); return false; }
	bFlag = checkvalue("form1","photo","T","S",1);
	if(!bFlag) { inlineMsg('photo',Msg); return false; }
	bFlag = checkvalue("form1","info","T","S",1);
	if(!bFlag) { inlineMsg('info',Msg); return false; }
	bFlag = checkvalue("form1","video","T","S",1);
	if(!bFlag) { inlineMsg('video',Msg); return false; }
	bFlag = checkvalue("form1","code","T","S",1);
	if(!bFlag) { inlineMsg('code',Msg); return false; }
	//document.getElementById('form1').action = "process.php?lang="+lang;
	document.getElementById('form1').submit();
	//return true;
}

// ---------

//function checkvalue(FormName,ObjName,TagType,ValueType,CheckValue,Msg) {
function checkvalue(FormName,ObjName,TagType,ValueType,CheckValue) {
	var flag = true;
	var value = GET_Value(FormName,ObjName,TagType);
	if ((!value) && (value!=0)) {
		flag = false;
	} else {
		if (ValueType == "I") {
			if ((value == "")||((CheckValue == "1")&&(value == "0"))) {
				flag = false;
			}
			if (flag) {
				flag = isNum(value);
			}
		} else {
			if (value == "") {
				flag = false;
			}
		}
	}
	//if (! flag)	{ 
	//	shotTo(FormName,ObjName,TagType,Msg);
	//}
	return flag;
}

function shotTo(FormName,ObjName,TagType,Msg) { 
	var X = document.forms[FormName].elements[ObjName];
	if (Msg != "") { alert(Msg); }
	if ((TagType == "C") || (TagType == "R")) {
		if (!X.length) {
			X.focus();
		} else {
			X[0].focus(); 
		}
	} else {
		X.focus();
	}
}

function GET_Value(FormName,ObjName,TagType) {
	var X = document.forms[FormName].elements[ObjName];
	if (TagType == "S") {
		var i = X.selectedIndex;
		//alert(i);
		return X[i].value;
	}
	if ((TagType == "C") || (TagType == "R")) {
		if (!X.length) {
			if (X.checked) { return X.value; }
		} else {
			var i = 0;
			while (i<X.length) {
				if (X[i].checked) { return X[i].value; }
				i++;
			}
		}
	}
	if (TagType == "T") { return X.value;}
}

function isNum(chkStr) {
	var cmp="0123456789.";
	var rc=true;
	var cmpChar;

	for(var i=0; i<chkStr.length; i++) {
		cmpChar=chkStr.substring(i,i+1)
		if(cmp.indexOf(cmpChar)<0) {
			rc=false;
			i=chkStr.length;
		}
	}
	return rc;
}

function checkemail(FormName,ObjName,TagType,Msg) {
	var pos = 0;
	var num = -1;
	var i = -1;
	var email = new Array()
	var graf = GET_Value(FormName,ObjName,TagType);
	
	while (pos != -1) {
		pos = graf.indexOf(";",i+1);
		num += 1;
		if (pos == -1) { email[num] = graf.substring(i+1,graf.length); }
		else { email[num] = graf.substring(i+1,pos); }
		i = pos;
	}

	for ( i = 0 ; i <= num ; i++ ) {
		if (email[i].length > 0) {
			l=email[i].indexOf("@");
			j=email[i].indexOf(".",l);
			k=email[i].indexOf(",");
			kk=email[i].indexOf(" ");
			jj=email[i].lastIndexOf(".") + 1;
			ll=email[i].indexOf(":");
			mm=email[i].indexOf("(");
			nn=email[i].indexOf(")");
			oo=email[i].indexOf("ĄG");
			len=email[i].length;

			if ((l <= 0) || (j <= (1+1)) || (k != -1) || (kk != -1) || (len-jj < 2) || (len-jj > 3) || (ll != -1) || (mm != -1 ) || (nn != -1) || (oo != -1)) {
				// shotTo(FormName,ObjName,TagType,Msg);
				return false;
			}
		}
   }
   return true;
}

// ---------

// START OF MESSAGE SCRIPT //

var MSGTIMER = 20;
var MSGSPEED = 5;
var MSGOFFSET = 3;
var MSGHIDE = 3;

// build out the divs, set attributes and call the fade function //
function inlineMsg(target,string,autohide) {
  var msg;
  var msgcontent;
  if(!document.getElementById('msg')) {
    msg = document.createElement('div');
    msg.id = 'msg';
    msgcontent = document.createElement('div');
    msgcontent.id = 'msgcontent';
    document.body.appendChild(msg);
    msg.appendChild(msgcontent);
    msg.style.filter = 'alpha(opacity=0)';
    msg.style.opacity = 0;
    msg.alpha = 0;
  } else {
    msg = document.getElementById('msg');
    msgcontent = document.getElementById('msgcontent');
  }
  msgcontent.innerHTML = string;
  msg.style.display = 'block';
  var msgheight = msg.offsetHeight;
  var targetdiv = document.getElementById(target);
  targetdiv.focus();
  var targetheight = targetdiv.offsetHeight;
  var targetwidth = targetdiv.offsetWidth;
  var topposition = topPosition(targetdiv) - ((msgheight - targetheight) / 2);
  var leftposition = leftPosition(targetdiv) + targetwidth + MSGOFFSET;
  msg.style.top = topposition + 'px';
  msg.style.left = leftposition + 'px';
  clearInterval(msg.timer);
  msg.timer = setInterval("fadeMsg(1)", MSGTIMER);
  if(!autohide) {
    autohide = MSGHIDE;  
  }
  window.setTimeout("hideMsg()", (autohide * 500));
}

// hide the form alert //
function hideMsg(msg) {
  var msg = document.getElementById('msg');
  if(!msg.timer) {
    msg.timer = setInterval("fadeMsg(0)", MSGTIMER);
  }
}

// face the message box //
function fadeMsg(flag) {
  if(flag == null) {
    flag = 1;
  }
  var msg = document.getElementById('msg');
  var value;
  if(flag == 1) {
    value = msg.alpha + MSGSPEED;
  } else {
    value = msg.alpha - MSGSPEED;
  }
  msg.alpha = value;
  msg.style.opacity = (value / 100);
  msg.style.filter = 'alpha(opacity=' + value + ')';
  if(value >= 99) {
    clearInterval(msg.timer);
    msg.timer = null;
  } else if(value <= 1) {
    msg.style.display = "none";
    clearInterval(msg.timer);
  }
}

// calculate the position of the element in relation to the left of the browser //
function leftPosition(target) {
  var left = 0;
  if(target.offsetParent) {
    while(1) {
      left += target.offsetLeft;
      if(!target.offsetParent) {
        break;
      }
      target = target.offsetParent;
    }
  } else if(target.x) {
    left += target.x;
  }
  return left;
}

// calculate the position of the element in relation to the top of the browser window //
function topPosition(target) {
  var top = 0;
  if(target.offsetParent) {
    while(1) {
      top += target.offsetTop;
      if(!target.offsetParent) {
        break;
      }
      target = target.offsetParent;
    }
  } else if(target.y) {
    top += target.y;
  }
  return top;
}

// preload the arrow //
if(document.images) {
  arrow = new Image(7,80); 
  arrow.src = "../images/msg_arrow.gif"; 
}