/*=========================================                  error handling                      */
onerror=handleErr

function handleErr(msg,url,l) {
    if (url=="http://www.4system.com/scripts/swfobject.js") {
	return;
    }
    //pominiecie bledow wewnetrznych firefox'a
    if(url.indexOf("chrome://")==0){
	return;
    }
    //pominiecie bledu pluginu skype
    if(msg.indexOf("SkypeSetCallButton")!=-1){
	return;
    }
    //pominiecie google translator'a
    if(url.indexOf("translate_c.js")!=-1){
	return;
    }
    var mess="%0AError: " + msg + "%0A";
    mess+="URL: " + url + "%0A";
    mess+="Location: " + document.location + "%0A";
    mess+="Line: " + l + "%0A";
    
//    for (i=0;i<document.forms.length;i++){
//        mess+="%0A%0AFORM "+(i+1)+"("+document.forms[i].name+"):%0A";
//        for (j=0;j<document.forms[i].elements.length;j++){
//            mess+=document.forms[i].elements[j].name+"="+document.forms[i].elements[j].value+"%0A";
//        }
//    }
    if (msg.search("Location.toString")==-1){
        fr = document.createElement("IFRAME");
        fr.setAttribute("src", "http://www.4system.com/scripts/php.php?act=send_form&typ=error&mail_subject=WWW error&send_to=www&message="+mess,"err_window");
        fr.style.display='none';
        document.body.appendChild(fr);
    }
}

function adminMessage(msg){
    var mess="%0AError: " + msg + "%0A";
    //mess+="URL: " + url + "%0A";
    mess+="Location: " + document.location + "%0A";
    //mess+="Line: " + l + "%0A";
    try{
        fr = document.createElement("IFRAME");
        fr.setAttribute("src", "http://www.4system.com/scripts/php.php?act=send_form&typ=error&mail_subject=WWW exception&send_to=jb&message="+mess,"err_window");
        fr.style.display='none';
        document.body.appendChild(fr);
    }catch(err){
        //shit!
    }
}

/*=============<( oblsuga parametrow z URL'a w JS )>===============*/
    var parameterString = document.location.href.replace(/.*\?(.*)/, "$1");
    var parameterTokens = parameterString.split("&");
    var parameterList = new Array();

    for (i = 0; i < parameterTokens.length; i++)  {
      var parameterName = parameterTokens[i].replace(/(.*)=.*/, "$1");
      var parameterValue = parameterTokens[i].replace(/.*=(.*)/, "$1");

      parameterList[parameterName] = parameterValue;
    }
    
    function getUrlParameter(paramName){
      var par = parameterList[paramName];
      if (par == undefined){
	return "";
      }
      return par;
    }


/*=========================================*/

function openNewWindow(adresURL,exWidth,exHeight,exTop,exLeft){
  var wind = window.open(adresURL,"example_window","width="+exWidth+", height="+exHeight+", top="+exTop+", left="+exLeft+", toolbar=no, menubar=no, location=no, personalbar=no, status=no, resizable=no, scrollbars=no, copyhistory=no");
}


/*=========================================                  nawigacja                      */
sfHover = function() {
    try {
	var sfEls = document.getElementById("nav1").getElementsByTagName("LI");
		for (var i=0; i<sfEls.length; i++) {
			//alert(sfEls[i].className);
			if (sfEls[i].className=='nav2_li'){
				
				sfEls[i].onmouseover=function() {
					this.className+=" subhover";}
				sfEls[i].onmouseout=function() {
					this.className=this.className.replace(new RegExp(" subhover\\b"), "");
					}
			} else {
			
				sfEls[i].onmouseover=function() {
				this.className+=" sfhover";
				}
				sfEls[i].onmouseout=function() {
				this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
				}
			//}
		}
	}
	}catch(err){
	
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);


/*=========================================                  sending e-mails                      */
function sendMail(whom, ob) {
   ob.href = "mail" + "to" + ":" + whom + unescape("%40") + "4system.com";
}

function sendMail2(whom, subject, ob) {
    try{
        if (document.location!=null){
            document.location.href = "mail" + "to" + ":" + whom + unescape("%40") + "4system.com?subject="+subject;
        }
    }catch(e){
//            document.location.href = "mail" + "to" + ":" + whom + unescape("%40") + "4system.com?subject="+subject;
    }
}


/*=========================================                  preloading images                   */

var obrazki = new Array();
function preload_images(){
}

function loadingResources(whom){
    try{
        if (document.location!=null){
    		//alert(document.location.href);
			var s1 = document.location.href;
			var n1=s1.search(/polska.4system.com/)
//    		alert(n1);
			if (n1>0)
				window.location="http://elearning.4system.com/index.html";

//		if(document.location.test("polska.4system.com"))        alert("found");
		
    //		alert(document.location.href);
        }
    }catch(e){
//            document.location.href = "mail" + "to" + ":" + whom + unescape("%40") + "4system.com?subject="+subject;
    }


	var komenda = "showBanerAnimation('" + whom + "')";
	var t = setTimeout(komenda,5000);
}

function showBanerAnimation(whom) {
	var params = whom.split(",");
	
	for(var i=0; i<params.length; i++){
		var who = params[i];
		switch(who){
			case "fla_banner":
				var fban = new SWFObject("images/layout/baner/baner.swf", "fla_banner_", "999", "152", "7", "#ffffff");
				fban.addParam("quality", "high");
				fban.addParam("wmode", "transparent");
				fban.write("fla_banner");
				break;
			case "fla_billboard":
				var so = new SWFObject("images/content/billboard/ad_banners.swf", "fla_billboard_", "750", "358", "7", "#ffffff");
				so.addParam("quality", "high");
				so.addParam("wmode", "transparent");
				so.write("fla_billboard");
				break;
		}
	}
}

function send_questionary(){
  var frm = document.forms['form_quest'];
  if (frm==null){
    return;
  }
  var content = "";
  content +="<html><body>";
  content +="<form name='form_questionary' method='post' action='scripts/send_questionary.php'>";
  content +="<input type='hidden' name='language' value='"+frm.language.value+"'>";
  content +="<input type='hidden' name='send_to' value='"+frm.send_to.value+"'>";
  content +="<input type='hidden' name='redirect_to' value='"+frm.redirect_to.value+"'>";
  content +="<input type='hidden' name='mail_subject' value='"+frm.mail_subject.value+"'>";
  content +="<input type='hidden' name='client_note' value='"+frm.client_note.options[frm.client_note.selectedIndex].text+"'>";
  content +="<input type='hidden' name='client_description' value='"+frm.client_description.value+"'>";
  content +="</form>";
  content +="<script>document.forms['form_questionary'].submit();</script>";
  content +="</body></html>";
  //czyszczenie pól ankiety
  frm.client_note.selectedIndex="0";
  frm.client_description.value="";
  var wind = window.open("","send_questionary","toolbar=no, menubar=no, location=no, personalbar=no, status=no, resizable=no, scrollbars=no, copyhistory=no, width=257, height=180, top=300, left=300");
  wind.document.write(content);
}

function randomElement(elementsCount){
  var id = Math.floor(elementsCount * Math.random())+1;
  var obj = document.getElementById('elem'+id);
  if (obj!=null){
    obj.style.display='block';
  }
}

// sprawdza czy podane pole nie jest puste
function checkFields(form, field){
  var frm = document.getElementsByName(form).item(0);
  if (frm==null){
    return false;
  }
  var obj = frm[field];
  if (obj==null){
    return false;
  }
  //alert(frm+"\n"+obj);
  if (obj.value=='') {
    return false
  } else return true;
}

function valid_email(emailInput) {
	var re = /^[A-Za-z0-9._%-]+@[A-Za-z0-9._-]+\.[A-Za-z]{2,4}$/;
	var OK = re.exec(emailInput);
	return OK;
}

function showMessage(){
  try{
	var obj = document.getElementById('div_message');
	if (obj!=null){
		obj.style.display='block';
	}
  } catch (err){
    adminMessage("Showmessage failed!");
  }
}

function hideMessage(){
	var obj = document.getElementById('div_message');
	if (obj!=null){
		obj.style.display='none';
	}
}

//preload_images();
