<!-- //Begin JavaScript 
String.prototype.startsWith = function(str){return (this.match("^"+str)==str)}

if (document.images){
   roll = 1; 
}
else{
   roll = 0; 
}

if (roll){
// begin circlebar rollovers
pla = new Image() ;
pla.src = "/Pages/Themes/Default/Browsing/Images/flaga-pl-a.gif";
plb = new Image() ;
plb.src = "/Pages/Themes/Default/Browsing/Images/flaga-pl-b.gif";

ena = new Image() ;
ena.src = "/Pages/Themes/Default/Browsing/Images/flaga-en-a.gif";
enb = new Image() ;
enb.src = "/Pages/Themes/Default/Browsing/Images/flaga-en-b.gif";

dea = new Image() ;
dea.src = "/Pages/Themes/Default/Browsing/Images/flaga-de-a.gif";
deb = new Image() ;
deb.src = "/Pages/Themes/Default/Browsing/Images/flaga-de-b.gif";

rua = new Image() ;
rua.src = "/Pages/Themes/Default/Browsing/Images/flaga-ru-a.gif";
rub = new Image() ;
rub.src = "/Pages/Themes/Default/Browsing/Images/flaga-ru-b.gif";


// end circlebar rollovers
}

function hiLite(imgDocID,imgObjName){   
	if (roll) { 
		document.images[imgDocID].src = eval(imgObjName + ".src"); 
	} 
}
// funkcje enkodowania wyszukiwania - start
var Utf8 = {

    // public method for url encoding
    encode: function(string) {
        string = string.replace(/\r\n/g, "\n");
        var utftext = "";

        for (var n = 0; n < string.length; n++) {

            var c = string.charCodeAt(n);

            if (c < 128) {
                utftext += String.fromCharCode(c);
            }
            else if ((c > 127) && (c < 2048)) {
                utftext += String.fromCharCode((c >> 6) | 192);
                utftext += String.fromCharCode((c & 63) | 128);
            }
            else {
                utftext += String.fromCharCode((c >> 12) | 224);
                utftext += String.fromCharCode(((c >> 6) & 63) | 128);
                utftext += String.fromCharCode((c & 63) | 128);
            }

        }

        return utftext;
    },

    // public method for url decoding
    decode: function(utftext) {
        var string = "";
        var i = 0;
        var c = c1 = c2 = 0;

        while (i < utftext.length) {

            c = utftext.charCodeAt(i);

            if (c < 128) {
                string += String.fromCharCode(c);
                i++;
            }
            else if ((c > 191) && (c < 224)) {
                c2 = utftext.charCodeAt(i + 1);
                string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
                i += 2;
            }
            else {
                c2 = utftext.charCodeAt(i + 1);
                c3 = utftext.charCodeAt(i + 2);
                string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
                i += 3;
            }

        }

        return string;
    }

}
function trim(str, chars) {
    return ltrim(rtrim(str, chars), chars);
}

function ltrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}

function rtrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}

function UrlEncode(str) {
    var retval = "";
    if (str && (str.toString().length > 0)) {
        
        //str = Utf8.encode(str);
        var validchars = " qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM1234567890ąćęłńóśżźĄĆĘŁÓŚŻŹ";
        for (i = 0; i < str.toString().length; i++) {
            var charval = str.toString().substr(i, 1);
            if (validchars.indexOf(charval) >= 0) {
                retval += charval;
            }
            else {
                var invalidchars = "\\&|!(){}[]^\"~?:*/.<>%+";
                
                if ((charval.charCodeAt(0) > 250) || (invalidchars.indexOf(charval)>= 0)) {
                    retval += "char(" + charval.charCodeAt(0) + ")";
                    //var varinhex = "&#" + charval.charCodeAt(0)+";";
                    //alert(charval.charCodeAt(0)+"\n"+varinhex);
                    //retval += varinhex;
                } else {
                    var varinhex = "%" + charval.charCodeAt(0).toString(16);
                    retval += varinhex;
               }
            }
        }
    }
    while (retval.indexOf("/") >= 0) {
        retval = retval.replace("/", "%2F");
    }
    return retval;
}

function disableUnusedInputs(frm)
{
    if (frm && frm.elements)
    {
        for(i = 0; i < frm.elements.length ; i++)
        {
            var disableElem = true;
            var elem = frm.elements[i];
            if (elem)
            {
                if (elem.value)
                {
                    if(elem.value.toString().length > 0)
                    {
                        disableElem = false;
                    }
                }
                if (elem.name == "sltCategories" || elem.name == "notifierEmail")
                {
                    disableElem = true;
                }
            }
            if (disableElem)
            {
                try{
                if (elem.name)
                {
                    elem.name = "";
                }
                elem.disabled = true;
                }catch(e){;}
            }
        }
    }
    
}

function SubmitForm() {
    if (document.forms.length > 0) {
        var frm = document.forms[0];
        disableUnusedInputs(frm);
        checkSubmitForm(frm);
        frm.submit();
    }
}

function MakeSearch()
{
    var navigateurl = prepareBaseSearchUrl();
    document.location.href = navigateurl;
}

function LockFreeTextSearch()
{
    var frm = document.forms[0];
    if (frm && frm["freeTextSearch"])
    {
        var FreeTextSearch = frm["freeTextSearch"];
        if (!FreeTextSearch.disabled)
        {
            if (frm["freeTextSearch"].value)
            {
                var FreeTextSearchValue = trim(FreeTextSearch.value);
                keyword = UrlEncode(FreeTextSearchValue)
            }
            FreeTextSearch.name = "";
            FreeTextSearch.disabled = true;
        }
     }
}

function prepareBaseSearchUrl()
{
    var frm = document.forms[0];
    
    var retVal = "";
    var keyword = "";
    if (frm && frm["freeTextSearch"]) {
        var FreeTextSearch = frm["freeTextSearch"];
        if (frm["freeTextSearch"].value) {
            var FreeTextSearchValue = trim(FreeTextSearch.value);
            keyword = UrlEncode(FreeTextSearchValue)
        }
        LockFreeTextSearch();
        if (frm.__EVENTTARGET)
        {
            if(frm.__EVENTTARGET.value.toString().length == 0) {frm.__EVENTTARGET.name = '';frm.__EVENTTARGET.disabled = true;}
        }
        if (frm.__EVENTARGUMENT)
        {
            if(frm.__EVENTARGUMENT.value.toString().length == 0) {frm.__EVENTARGUMENT.name = '';frm.__EVENTARGUMENT.disabled = true;}
        }
         
         
        keyword = keyword.replace("Wpisz szukane słowo","");
        keyword = keyword.replace("Type a search word","");
        keyword = keyword.replace("Geben Sie einen Suchbegriff","");
        keyword = keyword.replace("Введите слово для поиска","");
        keyword = keyword.replace("char(1042)char(1074)char(1077)char(1076)char(1080)char(1090)char(1077) char(1089)char(1083)char(1086)char(1074)char(1086) char(1076)char(1083)char(1103) char(1087)char(1086)char(1080)char(1089)char(1082)char(1072)","");
        while(keyword.indexOf(" ",0)>=0)
        {
            keyword = keyword.replace(" ","+");
        }        
        retVal = urltemplate.replace("$keyword$", keyword);
    }
    retval = retVal.replace("//","/");
    return retval;
}

function checkSubmitFormGlobal(frm, urltemplate) {
    //frm.action = prepareBaseSearchUrl();
    LockFreeTextSearch();
    frm.action = urltemplate;
}



// funkcje enkodowania wyszukiwania - stop

// obsługa napisuReklama - start

function isAdExists(putbanid){
    var retVal = false;
    if(typeof(banXxByPoz)!=='undefined' && banXxByPoz[putbanid]!='')
    {
        retVal = true;
    }
    return retVal;
}

function localSetStringReklamaForPutban(putbanid, lang)
{
   var reklamaNapisy = new Array();
    reklamaNapisy["pl"] = "Reklama";
    reklamaNapisy["en"] = "Advertisement";
    reklamaNapisy["de"] = "Werbung";
    reklamaNapisy["ru"] = "Реклама";
    var napisElem = document.getElementById("rektitle_"+putbanid);
    if (napisElem)
    {
        if (isAdExists(putbanid))
        {
            napisElem.innerHTML = reklamaNapisy[lang];
        }
        else
        {
            napisElem.innerHTML = "";
            napisElem.style.display = "none";
        }
    }

}

function setStringReklamaForPutban(putbanid, lang)
{
    localSetStringReklamaForPutban(putbanid,lang)
    setTimeout("localSetStringReklamaForPutban('"+putbanid+"','"+lang+"')",300);
}
// obsługa napisuReklama - start

function ChangeStateGaphicCheckBox(fileldname,basevalue,oncssclass,offcssclass)
{
    try{
        if (document.forms.length > 0) {
            var frm = document.forms[0];
            var chval = frm[fileldname].value;
            if (chval.length >0)
            {
                frm[fileldname].value = "";
                document.getElementById("ChIco"+fileldname).className = offcssclass;
            }
            else
            {
                frm[fileldname].value = basevalue;
                document.getElementById("ChIco"+fileldname).className = oncssclass;
            }
        }
    }
    catch(e)
    {
    //alert(e.message);
    }
}

function DisableRegionOnNoPoland(countryselect)
{
    var dbg = "";

    try{
    
        if (document.forms.length > 0) {
            var frm = document.forms[0];        
            if (countryselect.value == 'PL' || countryselect.value == '')
            {
                document.getElementById('RegionControl').style.display = "block"
                if (frm["Region"])
                {
                    frm["Region"].disabled = false;
                }
                
            }
            else
            {
                document.getElementById('RegionControl').style.display = "none"
                if (frm["freeTextSearch"])
                {
                    frm["Region"].value = "";
                    frm["Region"].disabled = true;
                }
                
            }
        }
    }catch(e){;}
}

function clearSelect(selectObj){
    try{
        if(selectObj)
        {
            selectObj.length=0;
        }
    }catch(e){;}
}

function insertToSel(selectObj,index,name,value){
    try{
        if (selectObj)
        {
            selectObj.options[index] = new Option(name);
            selectObj.options[index].value=value;
        }
    }catch(e){;}
}

function changeModels(brandValue)
{
    try{
        if (document.forms.length > 0) {
            var frm = document.forms[0];
            var modelsPulldown = frm["Model"];
            var modelsinfo;
            if (modelsPulldown)
            {
                if (modelsInBrands)
                {
                    for (i = 0; i < modelsInBrands.length; i++)
                    {
                        var modelinbrand = modelsInBrands[i];
                        if (modelinbrand)
                        {
                            if (brandValue.toString().toLowerCase() == modelinbrand[0].toString().toLowerCase())
                            {
                                i = modelsInBrands.length;
                                modelsinfo = modelinbrand[1];
                                var firstElemName;
                                var firstElemValue;
                                var useFirstElem = false;
                                if (modelsPulldown.options.length > 0)
                                {
                                    firstElemValue = modelsPulldown.options[0].value;
                                    useFirstElem = true;
                                    firstElemName = modelsPulldown.options[0].text;
                                }
                                clearSelect(modelsPulldown);
                                if (modelsinfo && (modelsinfo.length>0))
                                {
                                    if (useFirstElem)
                                    {
                                        insertToSel(modelsPulldown,modelsPulldown.options.length,firstElemName,firstElemValue);
                                    }
                                    var modelsinfoarray = modelsinfo.split(";")
                                    for (j=0; j < modelsinfoarray.length; j++)
                                    {
                                        modeldata = modelsinfoarray[j];
                                        modelvalue = modeldata;
                                        modelname = modeldata;
                                        if (modeldata.indexOf("|") >=0)
                                        {
                                            var modeldataarray = modeldata.split("|");
                                            modelvalue = modeldataarray[0];
                                            modelname =  modeldataarray[1];
                                        }
                                        insertToSel(modelsPulldown,modelsPulldown.options.length,modelname,modelvalue);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }catch(e){;}   
    
}
// waildatory - start



// obsługa wciśnięcia klawiszy - start


function postEnabledControl(target){
    var retVal = 0;
    try
    {
        var className = target.className.toLowerCase();
        if (className && (className.length > 0))
        {
            if (className.indexOf("posttoponenter")>=0)
            {
                retVal = 1;
            }
            if (className.indexOf("postfilteronenter")>=0)
            {
                retVal = 2;
            }
        }
    }catch(e){;}
    return retVal;
}


function traderKeyEvent(e) {
    var ev;
    if (document.all){
			ev = window.event;
		}else{
			ev = e;
		};
		
	var target
	if (document.all){
		target = ev.srcElement;
	}else{
		target = ev.target
	};
    if (ev.keyCode && ev.keyCode==13)
    {
        var postcontrol = postEnabledControl(target);
        var helper = document.getElementById("globalhelper");
        if (helper)
        {
            helper.innerHTML = "jest enter = "+postcontrol;
        }
        if (postcontrol == 1)
        {
            MakeSearch();
        }
        if (postcontrol == 2)
        {
            SubmitForm();
        }
            
    }
    return true;
}
// obsługa wciśnięcia klawiszy - stop
// obsługa zdarzeń - start
if (document.layers) {
  document.captureEvents(Event.KEYDOWN);
  document.captureEvents(Event.KEYPRESS);
  document.captureEvents(Event.KEYUP);
  document.captureEvents(Event.MOUSEMOVE)
}
document.onmousemove = mmoveEventHandler;
document.onkeydown = keyDownEventHandler;
document.onkeypress = keyPressEventHandler;
document.onkeyup = keyUpEventHandler;

function mmoveEventHandler(e){
    try{getMouseXY(e)}catch(ex){;}
}

function keyDownEventHandler(e){
    try{GalleryFullViewDisableSomeKeysMove();}catch(ex){;}
    try{traderValidateForms(e);}catch(ex){;}
}

function keyUpEventHandler(e){
    
    try{GalleryFullViewChangePicsOnKeys(e);}catch(ex){;}
    try{traderValidateForms(e);}catch(ex){;}
}

function keyPressEventHandler(e){
    try{GalleryFullViewDisableSomeKeysMove();}catch(ex){;}
    try{ClaculateKeys(e);}catch(ex){;}
}


// obsługa zdarzeń - stop


var CurrentMousePosOnPage = new CPoint(0,0);
var registeredMouseMoveEvents = new Array();
function getMouseXY(e) {
  try
  {
      var IE = false;
      if (document.all)
      {
        IE = true;
      }
      
      if (IE) { // grab the x-y pos.s if browser is IE
        CurrentMousePosOnPage.X = event.clientX + document.body.scrollLeft
        CurrentMousePosOnPage.Y = event.clientY + document.body.scrollTop
      } else {  // grab the x-y pos.s if browser is NS
        CurrentMousePosOnPage.X = e.pageX
        CurrentMousePosOnPage.Y = e.pageY
      }  
      
      CurrentMousePosOnPage.Y = CurrentMousePosOnPage.Y + getPageScroll();
      // catch possible negative values in NS4
      if (CurrentMousePosOnPage.X  < 0){CurrentMousePosOnPage.X  = 0;}
      if (CurrentMousePosOnPage.Y  < 0){CurrentMousePosOnPage.Y = 0;}  
      for( i=0; i < registeredMouseMoveEvents.length ; i++)
      {
        try
        {
            
            eval(registeredMouseMoveEvents[i]);
        }
        catch(e)
        {
        ;
        }
      }
  }
  catch(e)
    {
    ;
    }
  return true
}

var validTraderDate = "xxxx-xx-xx";
var validTraderTime = "xx:xx:xx";
var validTraderDateTime = "xxxx-xx-xx xx:xx:xx";

//var KeyCalculation = 0;
//var KeyCalculationTime = 
function ClaculateKeys(e)
{    
    traderValidateForms(e);
}
function getValidClassName(target)
{
	var retVal = "";
	var className = target.className;
	if (className && className.length > 0)
	{
		className = className.toLowerCase();
		var classArray = (className+" ").split(" ");
		for (i = 0; i < classArray.length ; i++)
		{
			s = classArray[i].toLowerCase();
			if (s.indexOf("integer")==0) retVal  = s;
			if (s.indexOf("float")==0) retVal  = s;
			if (s.indexOf("buildyear")==0) retVal  = s;
			if (s.indexOf("date")==0) retVal  = s;
			if (s.indexOf("datetime")==0) retVal  = s;
			if (s.indexOf("time")==0) retVal  = s;
			if (s.indexOf("string")==0) retVal  = s;
			if (s.indexOf("inputemail")==0) retVal  = s;
			if (s.indexOf("intwithoutzero")==0) retVal  = s;		
		}
	}
	return retVal;
}

function traderValidateForms(e) {
	var target
		if (document.all){
			target = window.event.srcElement;
		}else{
			target = e.target
		};
		traderKeyEvent(e);
		var className = getValidClassName(target);
		aRange=getRange(target);
		if (className.substr(0, 7) == "integer"){
			var tmpMaxSize = getTraderValidNumber(className);
			var value = target.value;
			if (value.length > 0){
				value = getTraderValidNumber(value);
				if (!isNaN(parseInt(aRange.to))){
					value = checkValue(value,aRange.to);
				}
				if (!isNaN(parseInt(value))) {
					if (target.value != parseInt(value)) {
						target.value = parseInt(value);
					}
				}else{target.value = ""}
			}
		}
		
		if (className.substr(0, 14) == "intwithoutzero"){
			var tmpMaxSize = getTraderValidNumber(className);
			var value = target.value;
			if (value.length > 0){
				value = getTraderValidNumber(value);
				if (!isNaN(parseInt(aRange.to))){
					value = checkValue(value,aRange.to);
				}
				if (!isNaN(parseInt(value))) {
					if (target.value != parseInt(value)) {
						target.value = parseInt(value);
					}
				}else{target.value = ""}
			}
			
			if(target.value == 0)
			{
			   target.value = "";
			}
		}
					
		if (className.substr(0, 9) == "buildyear"){
			var value = target.value;
			value = checkBuildYear(value)
			if (target.value != value) target.value = value;
		}
		
		if (className.substr(0, 5) == "float"){
			var value = target.value;
			value = value.replace(",",".");
			value = getTraderValidNumber(value);
			
			if (!isNaN(parseFloat(aRange.to))){
				value = checkValue(value,aRange.to);
			}
			if (!isNaN(parseFloat(value))) {
				if (target.value != value) target.value = value;
			}else{
				target.value = "";
			}
		}
		
		if (className.substr(0, 4) == "date"){
			var value = target.value;
			value = checkTraderDateTimeMask(validTraderDate,value)
			if (target.value != value) target.value = value;
		}
		
		if (className.substr(0, 8) == "datetime"){
			var value = target.value;
			value = checkTraderDateTimeMask(validTraderDateTime,value)
			if (target.value != value) target.value = value;
		}
		
		if (className.substr(0, 4) == "time"){
			var value = target.value;
			value = checkTraderDateTimeMask(validTraderTime,value)
			if (target.value != value) target.value = value;
		}

		if (className.substr(0, 6) == "string"){
			var tmpMaxSize = getTraderValidNumber(className)
			if (!isNaN(parseInt(tmpMaxSize))){
				var maxSize = parseInt(tmpMaxSize);
				var value = target.value;
				if (value.length > maxSize) target.value = value.substr(0,maxSize);
			}
		}	
}


function validateValueBySchema(value, schema)
{
    var retVal = false;
    if (schema=="email") retVal = isEmail(value);
    if (schema.toString().indexOf("stringnotlowerthan") >= 0 )
    {
        var lowrange = schema.toString().replace("stringnotlowerthan[","").replace("]","")
        retVal = isStringLongerThan(value,lowrange);
    }
    if(schema.toString().indexOf("passwordlowerthan") >= 0)
    {
       var lowrange = schema.toString().replace("passwordlowerthan[","").replace("]","")
       retVal = isStringLongerThan(value,lowrange);
       if(retVal)
       {
         
         retVal = IsPasswordtidentical(value)
       }
    }
    if(schema.toString().indexOf("stringaccuratelenght") >= 0)
    {
       var lowrange = schema.toString().replace("stringaccuratelenght[","").replace("]","")
        retVal = isStringAccurateLong(value,lowrange);               
    }
    if(schema.toString().indexOf("stringnotempty") >= 0)
    {
      retVal = isNotEmpty(value);
    }
    if(schema.toString().indexOf("mobilephone") >= 0)
    {
       retVal = isMobilePhone(value, 9);
    }
    if(schema.toString().indexOf("isinteger") >= 0)
    {
       var lowrange = schema.toString().replace("isinteger[","").replace("]","")
       retVal = !isStringLongerThan(value,lowrange);
       if(retVal)
       {
         retVal = isInt(value);
       }
    }
    
    return retVal;
}

function getTraderValidNumber(value){
	var c;
	var retval = "";
	for (var i = 0; i<value.length; i++){
		c = value.substr(i,1);
		if ("0123456789.".indexOf(c) >= 0) retval = retval.concat(c);
	}
	value = retval;
	retval = "";
	var commaexists = false;
	for (var i = (value.length-1); i>=0; i--){
		c = value.substr(i,1);
		if ((c!=".") || (!commaexists)) retval = c+""+retval;
		if (c == ".") commaexists = true;
	}		
	return retval;
}


function getTraderValidDateTimeChars(value){
	var c;
	var retval = "";
	var goodstring = "0123456789-: "
	for (var i = 0; i<value.length; i++){
		c = value.substr(i,1);
		if (goodstring.indexOf(c) >= 0) retval = retval.concat(c);
	}				
	return retval;
}

function checkYearValue(value)
{
	retval = "";
	var rexpstr = "(^19[0123456789][0123456789]$)|(^200[0123456789]$)|(^201[012]$)|(^19[0123456789]$)|(^20[012]$)|(^19$)|(^20$)|(^1$)|(^2$)";
	var re = new RegExp(rexpstr);
	var matchar = value.match(re);
	if (matchar){
		if (matchar.length > 0) {retval = matchar[0]}  else {retval = ""};
	}else{retval = "";}	
	return retval;
}

function isEmail(value)
{
    var retVal = false;
   	var rexpstr = "^[_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*\.(([0-9]{1,3})|([a-zA-Z]{2,3})|(aero|coop|info|museum|name))$";
	var re = new RegExp(rexpstr);
    var matchar = value.match(re);
	if (matchar){
	    retVal = true;
	}
    return retVal;
}

function isStringNotLongerThan(value, len)
{
    var retVal = true;
    if (value && value.toString().length < len) retVal = false;
    return retVal;
}

function isNotEmpty(value)
{
  var retVal = true;
  if(value.toString().length <= 0) retVal = false;
  return retVal;
}

function isStringLongerThan(value, len)
{
    var retVal = false;
    if (value && value.toString().length > len) retVal = true;
    return retVal;
}

function isStringAccurateLong(value, len)
{
    var retVal = false;
    if (value && value.toString().length == len) retVal = true;
    return retVal;
}

function isMobilePhone(value, len)
{
   var retval = false;
   retval = isStringAccurateLong(value, len)
   if(retval)
   {    
      retval = isInt(value);
   }
   if(retval)
   {
     retval = IsMobilePrefix(value)
   }
   
   return retval;
}

function isInt(value){
  if(!isNaN(value)){
      return true;
 } else {
      return false;
 }
}

function IsMobilePrefix(value)
{
  var elementexistsinlist = false;
  for (var i = 0; i < mobilePrefixes.length; i++) 
  {
     if(value.startsWith(mobilePrefixes[i]))
     {
        elementexistsinlist = true;
     }
  } 
 return elementexistsinlist;
}

function checkBuildYear(value){
	var validchars = "0123456789";
	var digitvalue = "";
	var checkedvalue = "";
	var retval = "";
	var lastchecked = "";
	if (value.length > 0)
	{
		var orgval = value;
		for(i = 0; i < orgval.length ; i++)
		{
			if(validchars.indexOf(orgval.substr(i,1)) >= 0)
			{
				digitvalue += orgval.substr(i,1);
				checkedvalue = checkYearValue(digitvalue);
				if (checkedvalue.length > 0)
				{
					lastchecked = checkedvalue;
					retval = digitvalue;
				}
			}
		} 
	}
	else
	{
		retval = "";
	}
	return retval;
}
	

function changeDTToMask(value){
	var c;
	var retval = "";
	for (var i = 0; i<value.length; i++){
		c = value.substr(i,1);
		if ("0123456789".indexOf(c) >= 0) {
			retval = retval.concat("x")}else{retval = retval.concat(c)
		}
	}
	return retval;
}

function checkTraderDateTimeMask(mask,value){
	var tmpval = value;
	var validformat=/^\d{4}\-\d{1,2}\-\d{1,2}$/
	if (!validformat.test(value)){
		var retval = "";
		tmpvalmask = "";
		for (var i = 1; i<=tmpval.length;i++){
			tmpvalmask = changeDTToMask(tmpval);
			if (mask.substr(0,i) == tmpvalmask.substr(0,i)) retval = tmpval.substr(0,i)
		} 
	} else retval = value
	return retval;
} 

function checkValue(value,maxvalue){
	var retval = "";
	var c;
	if ((value.length > 0)&&(!isNaN(parseFloat(value)))) {
		value = parseFloat(value); 
		if (value > maxvalue) {
			for (var i = 0; i<value.toString().length; i++){
				c = value.toString().substr(i,1);
				if  (parseFloat(retval.concat(c))<=maxvalue){
					retval = retval.concat(c);
				}
			}
		}else{
			retval = value;
		}
	}
	return retval;
}

function getRange(obj){
	if (document.getElementById("test")) document.getElementById("test").value = "aaa";
	var range = new CRange();
	if (obj){
		var tmp = "";
		var rangestr = "";
		var cname = getValidClassName(obj)
		
		if (cname.length>0){
			cname = cname.replace("\t"," ");
			cname = cname.replace("\t"," ");
			cname = cname.replace("\t"," ");
			cnamear = (cname+" ").split(" ");
			for (i=0;i<cnamear.length;i++){
				tmp = (cnamear[i]).toLowerCase();
				if (tmp.length>0){if (tmp.indexOf("integer")==0) rangestr = tmp.replace("integer","");}
				if (tmp.length>0){if (tmp.indexOf("float")==0) rangestr = tmp.replace("float","");}
				if (tmp.length>0){if (tmp.indexOf("buildyear")==0) rangestr = tmp.replace("buildyear","");}
				if (tmp.length>0){if (tmp.indexOf("date")==0) rangestr = tmp.replace("date","");}
				if (tmp.length>0){if (tmp.indexOf("datetime")==0) rangestr = tmp.replace("datetime","");}
				if (tmp.length>0){if (tmp.indexOf("time")==0) rangestr = tmp.replace("time","");}
				if (tmp.length>0){if (tmp.indexOf("string")==0) rangestr = tmp.replace("string","");}
				if (tmp.length>0){if (tmp.indexOf("inputemail")==0) rangestr = tmp.replace("inputemail","");}
			}
		}
		if (rangestr.length>0){
			if (rangestr.indexOf("^")>=0){
				rangestrar = rangestr.split("^");
				range.from = rangestrar[0];
				range.to = rangestrar[1];
			}else{
				range.to = rangestr;
			}
		}
	}
	if (document.getElementById("test")) document.getElementById("test").value = range.toString();
	return range
}


function ValidateDateInput(input, inputname){
	var validformat=/^\d{4}\-\d{1,2}\-\d{1,2}$/ 
	var returnval=false
	if (!validformat.test(input.value))
		alert("Nieprawidłowy format daty w polu "+inputname+". Proszę wpisać w formacie RRRR-MM-DD")
	else{ 

	var monthfield=input.value.split("-")[1]
	var dayfield=input.value.split("-")[2]
	var yearfield=input.value.split("-")[0]
	var dayobj = new Date(yearfield, monthfield-1, dayfield)

	if ((dayobj.getMonth()+1!=monthfield)||(dayobj.getDate()!=dayfield)||(dayobj.getFullYear()!=yearfield))
		alert("Nieprawidłowa data w polu "+inputname)
	else
		returnval=true
	}
	return returnval;
}

function CRange(from,to) {
	if (from){
		this.from=from;
	}else{this.from=""}
	if (to){
		this.to=to;
	}else{this.to=""}
}
function CRangeToString(){return this.from+"^"+this.to;}
CRange.prototype.toString = CRangeToString;

function internalValidateForm(form){
	var ret = true;
	if (form){
		if (form.elements){
			var elem;
			var aRange;
			var msg = "";
			for (i=0;((i<form.elements.length)&&(msg==""));i++){
				elem = form.elements[i];
				if (elem){
					if (elem.type.toLowerCase()=="text"){
						aRange = getRange(elem);
						var basetype = "";							
						var cname = getValidClassName(elem);
						if (cname.length>0){
							cname = cname.replace("\t"," ");
							cname = cname.replace("\t"," ");
							cname = cname.replace("\t"," ");
							cnamear = (cname+" ").split(" ");
							for (i=0;i<cnamear.length;i++){
								tmp = (cnamear[i]).toLowerCase();
								if (tmp.length>0){if (tmp.indexOf("integer")==0) basetype="integer";}
								if (tmp.length>0){if (tmp.indexOf("float")==0) basetype="float";}
								if (tmp.length>0){if (tmp.indexOf("buildyear")==0) basetype="buildyear";}
								if (tmp.length>0){if (tmp.indexOf("date")==0) basetype="date";}
								if (tmp.length>0){if (tmp.indexOf("datetime")==0) basetype="datetime";}
								if (tmp.length>0){if (tmp.indexOf("time")==0) basetype="time";}
								if (tmp.length>0){if (tmp.indexOf("string")==0) basetype="string";}
								if (tmp.length>0){if (tmp.indexOf("inputemail")==0) basetype="inputemail";}
							}
						}							
						if (basetype!=""){
							if ((aRange.toString()).length > 1){
								if (aRange.from.length>0) {
									if ((";integer;float;buildyear;").indexOf(";"+basetype+";") > 0){
										if (parseFloat(elem.value) < parseFloat(aRange.from)) msg += "wartość tego pola musi być większa od: "+aRange.from+"\n";
									}

									if ((";date;datetime;time;").indexOf(";"+basetype+";") > 0){
										if (elem.value < aRange.from) msg += "wartość tego pola musi być większa od: "+aRange.from+"\n";
									}

									if ((";string;inputemail;").indexOf(";"+basetype+";") > 0){
										if (elem.value.length < aRange.from) msg += "ilość znaków tego pola musi być większa od: "+aRange.from+"\n";
									}
								}
								if (aRange.to.length>0) {
									if ((";integer;float;buildyear;").indexOf(";"+basetype+";") > 0){
										if (parseFloat(elem.value) > parseFloat(aRange.to)) msg += "wartość tego pola musi być mniejsza niż: "+aRange.to+"\n";
									}

									if ((";date;datetime;time;").indexOf(";"+basetype+";") > 0){
										if (elem.value > aRange.to) msg += "wartość tego pola musi być mniejsza niż: "+aRange.to+"\n";
									}

									if ((";string;inputemail;").indexOf(";"+basetype+";") > 0){
										if (elem.value.length > aRange.to) msg += "ilość znaków tego pola musi być mniejsza niż: "+aRange.to+"\n";
									}
								}
							}
						}
					}
				}
			}
			if (msg!=""){
				ret = false;
				try{
					;
				}catch(e){;}
			}
		}
	}
	return ret;
}

// waildatory - stop

// skrypt galerii obrazkow - start

var currentBigPicturePosition = new CPoint(0,0);
var currentBigPictureSize = new CPoint(0,0);
var isBigPicureInLoad = true;

function GalleryFullViewChangePicsOnKeys(e)
{
    var ev;
    if (document.all){
			ev = window.event;
		}else{
			ev = e;
		};
		
    if (ev.keyCode &&  pictureGallery &&((ev.keyCode==27) || (ev.keyCode==37) || (ev.keyCode==39)))
    {
        if (pictureGallery.IsGalleryInFullView)
        {
            if (ev.keyCode == 27){
                pictureGallery.CloseBigPicture();
                CloseDialogForm();
                ev.cancelBubble = true;                
            }else if (ev.keyCode == 37){
                pictureGallery.PrevBigPicture();
                ev.cancelBubble = true;
            }else if (ev.keyCode == 39){
                pictureGallery.NextBigPicture();
                ev.cancelBubble = true;
            }
        }
    }
}

function GalleryFullViewDisableSomeKeysMove(e)
{
    var ev;
    if (document.all){
			ev = window.event;
		}else{
			ev = e;
		};
		
    if (ev.keyCode &&  pictureGallery &&((ev.keyCode==27) || (ev.keyCode==37) || (ev.keyCode==39)))
    {
        if (pictureGallery.IsGalleryInFullView)
        {
            if (ev.keyCode == 27){
                ev.cancelBubble = true;                
            }else if (ev.keyCode == 37){
                ev.cancelBubble = true;
            }else if (ev.keyCode == 39){
                ev.cancelBubble = true;
            }
        }
    }
}


function AfterLoadBigImage()
{
    SetBigPictureSizeAndPositionData();
    isBigPicureInLoad = false;
}

function SetPossitionForPrevNextButtons()
{
    
    var imgbig = document.getElementById("GalleryImageFullViewPictureObj");
    if (imgbig)
    {
        SetBigPictureSizeAndPositionData();
        var bigpos = currentBigPicturePosition;
        var bigsize = currentBigPictureSize;        
    }
}

function SetBigPictureSizeAndPositionData()
{
    var imgbig = document.getElementById("GalleryImageFullViewPictureObj");
    if (imgbig)
    {
        currentBigPicturePosition = getAbsoluteObjPos(imgbig);
        currentBigPictureSize = getObjSize(imgbig);
    }
}

function PictureGallery() {
        var galleryIsVisible = false;
        var picturesArray;
        var currentPage = 0;
        var currentImageOnPage = 0;
        var imagesCount = 0;
        var pagesCount = 0;
        var itemsPerPage = 9;
        var SearchResultsDirUrl = "http://pictures.trader.pl/pictures/Tabor24/search-results/";
        var NormalResultsDirUrl = "http://pictures.trader.pl/pictures/Tabor24/";
        var OriginalResultsDirUrl = "http://pictures.trader.pl/pictures/Tabor24/original/";
        var currentPagePictures = new Array();
        var currentBigPicture = 0;        
        this.NextBigPicture = NextBigPicture;
        this.PrevBigPicture = PrevBigPicture;
        this.MoveToPrevPicture = MoveToPrevPicture;
        this.MoveToNextPicture = MoveToNextPicture;
        this.ShowFromThumbnail = ShowFromThumbnail;
        this.SetPicturesArray = SetPicturesArray;
        this.ShowBigPicture = ShowBigPicture
        this.SetPage = SetPage;
        this.CloseBigPicture = CloseBigPicture;
        this.IsGalleryInFullView = IsGalleryInFullView;
        
        function IsGalleryInFullView(){
            return galleryIsVisible;
        }
        
        function SetPagination() {

            var divGalleryPrevNextButtons = document.getElementById("divGalleryPrevNextButtons");
            if (divGalleryPrevNextButtons) {
                if (picturesArray.length > 1) {
                    divGalleryPrevNextButtons.style.display = "block";
                }
                else {
                    divGalleryPrevNextButtons.style.display = "none";
                }
            }
            var paginationDiv = document.getElementById("divGalleryPagination");
            if (paginationDiv)
            {
                if (pagesCount < 2)
                {
                    paginationDiv.style.display = "none";
                }
                else
                {
                    var paginationHTML = "";
                    for(i = 0; i < pagesCount ; i++)
                    {
                        var pageDisplayNum = (i+1);
                        if (i == currentPage)
                        {
                           
                            paginationHTML += "<span class=\"GaleriaZdjecPaginacja\">"+pageDisplayNum.toString()+"</span>";
                        }
                        else
                        {
                            paginationHTML += "<span class=\"GaleriaZdjecPaginacja ZdjecieMouseOn\" onclick=\"pictureGallery.SetPage("+i.toString()+");\"><a href=\"javascript: pictureGallery.SetPage("+i.toString()+");\" title=\"Następna strona\">"+pageDisplayNum.toString()+"</a></span>";
                        }
                    }
                    paginationDiv.innerHTML = paginationHTML;
                }
            }
        }
        
        function ClearStatInfo()
        {
            currentPage = 0;
            currentImageOnPage = 0;
            imagesCount = 0;
            pagesCount = 0;
        }
                
        function getThObj(ind)
        {
            return document.getElementById("pictureThumbnail_"+ind);
        }
        
        function SetPage(pagenum)
        {
            if ((pagenum >= 0) && (pagenum < pagesCount))
            {
                currentPage = pagenum;
                SetThumbnailsOnPage();
                SetMainPictureFromThumbnail(0);
            }
        }
        
        function SetThumbnailsOnPage(){
            var firstImageIndexOnPage = currentPage * itemsPerPage;
            currentPagePictures = new Array();
            for (thumbind = 0 ; thumbind < itemsPerPage; thumbind++)
            {
                var globalimageindex = firstImageIndexOnPage + thumbind;
                var thmbObj = getThObj(thumbind);
                var currPict = picturesArray[globalimageindex];
                
                if (currPict && currPict.length > 0)
                {
                    thmbObj.style.display = "block";
                    var completePictUrl = SearchResultsDirUrl+currPict;
                    currentPagePictures[currentPagePictures.length] = currPict;
                    thmbObj.style.background = "url("+completePictUrl+") no-repeat center";
                }
                else
                {
                    thmbObj.style.display = "none";
                }
            }
            SetPagination();
        }
        
        
        function SetInitialView()
        {
            if (picturesArray)
            {
                imagesCount = picturesArray.length;
                if (imagesCount >0 )
                {
                    pagesCount = Math.ceil(imagesCount / itemsPerPage);
                }
                SetThumbnailsOnPage();
                SetMainPictureFromThumbnail(0);
            }
        }
        
        function SetPicturesArray(picarray)
        {
            ClearStatInfo();
            picturesArray = picarray;
            SetInitialView();
        }
        
        function MoveToPrevPicture() {
            if ((currentImageOnPage-1) >= 0)
            {
                SetMainPictureFromThumbnail(currentImageOnPage-1);
            }
            else
            {
                if ((currentPage-1) >= 0)
                {
                    SetPage(currentPage-1);
                    SetMainPictureFromThumbnail(currentPagePictures.length-1);
                    
                }
                else
                {
                    SetPage(pagesCount-1);
                    SetMainPictureFromThumbnail(currentPagePictures.length-1);
                }
            }
        }
        
        function MoveToNextPicture() {
            if ((currentImageOnPage +1) < currentPagePictures.length)
            {
                SetMainPictureFromThumbnail(currentImageOnPage+1);
            }
            else
            {
                if ((currentPage+1) < pagesCount)
                {
                    SetPage(currentPage+1);
                }
                else
                {
                    SetPage(0);
                }
            }
        }

        function SetFocusOnThumb(picnumber)
        {
            for (i = 0 ; i < itemsPerPage ; i++)
            {
                var thmbObj = getThObj(i);
                var currentClassName = thmbObj.className;
                currentClassName = currentClassName.replace("ObrazekWybrany","");
                if (i == picnumber)
                {
                    currentClassName += " ObrazekWybrany";
                }
                thmbObj.className = currentClassName; 
                
            }
        }
        
        function SetMainPictureFromThumbnail(picnumber)
        {
            var pictureDiv = document.getElementById("mainpicturediv");
            if (pictureDiv)
            {
                if (currentPagePictures)
                {
                    var imgsrc = currentPagePictures[picnumber];
                    if (imgsrc && imgsrc.length >0)
                    {
                        var imgurl = NormalResultsDirUrl+imgsrc;
                        pictureDiv.style.background = "url("+imgurl+") no-repeat center";
                        SetFocusOnThumb(picnumber);
                        currentImageOnPage = picnumber;
                    }
                }
            }
            
        }
        
        function ShowFromThumbnail(picnumber) {
            SetMainPictureFromThumbnail(picnumber);
        }
        
        function SetBigPictureCounterInfo()
        {
            var cInfo = document.getElementById("GalleryImageFullViewCounterInfo");
            var tmpstr = bigPicturePaginationInfoTemplate;
            if (picturesArray.length == 1)
            {
                try
                {
                    document.getElementById("prevOnTop").style.display = "none";
                    document.getElementById("nextOnTop").style.display = "none";
                }
                catch(e)
                {
                
                }
            }
            tmpstr = tmpstr.replace("%1",currentBigPicture+1);
            tmpstr = tmpstr.replace("%2",picturesArray.length);
            cInfo.innerHTML = tmpstr;//(currentBigPicture+1) + " / "+picturesArray.length;
        }
        
        function NextBigPicture()
        {
            if ((currentBigPicture+1) < picturesArray.length)
            {
                SetBigPicture(currentBigPicture+1);
            }
            else
            {
                SetBigPicture(0);
            }
        }
        
        function PrevBigPicture()
        {
        
            if (currentBigPicture>0)
            {
                SetBigPicture(currentBigPicture-1);
            }
            else
            {
                SetBigPicture(picturesArray.length-1);
            }
        }
        
        function SetBigPicture(bigPicInd)
        {
            if (bigPicInd < picturesArray.length)
            {
                var pobj = document.getElementById("GalleryImageFullViewPictureObj");
                var imgUrl = OriginalResultsDirUrl+picturesArray[bigPicInd];
                isBigPicureInLoad = true;
                pobj.src = imgUrl;
                currentBigPicture = bigPicInd;
                SetBigPictureCounterInfo();
            }
        }
        
        
        function ShowBigPicture()
        {
            galleryIsVisible = true;
            isBigPicureInLoad = false;
            var fViewContainer = document.getElementById("GalleryImageFullViewContainer");
            SetBigPictureCounterInfo();
            var bigPictureind = 0;            
            bigPictureind = (currentPage * itemsPerPage)+currentImageOnPage;
            SetBigPicture(bigPictureind);
            ShowLayer();
            ShowObjectAtStandardPosition(fViewContainer,"gallery-big-picture");
        }
        
        function CloseBigPicture()
        {
            galleryIsVisible = false;
            var fView = document.getElementById("GalleryImageFullViewContainer");
            fView.style.display = "none";
            HideLayer();
            isBigPicureInLoad = false;
        }
    }
// skrypt galerii obrazkow - stop

// skrypt mierznia i lokalizacji elementow html - start

function CPoint(X,Y) {this.X=X;this.Y=Y;}
function CPointToString(){return this.X+"|"+this.Y;}
CPoint.prototype.toString = CPointToString;

function getPageScroll(){
	var yScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
	}
	return yScroll;
}

function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}
    
    var divendlocator = document.getElementById("div_endlocator");
	if (divendlocator)
	{
		var endlocatorpos = getAbsoluteObjPos(divendlocator)
		if (endlocatorpos.Y > pageHeight){
		    pageHeight = endlocatorpos.Y;
		}
	}


	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) ;
	return arrayPageSize;
}

function checkAbsoluteObjPos(toobject,aPoint){
	try{
		if (toobject) {
			aPoint.X += toobject.offsetLeft;aPoint.Y += toobject.offsetTop;
			if (toobject.offsetParent) checkAbsoluteObjPos(toobject.offsetParent,aPoint);
		}
	}catch(e){;}
}

function getAbsoluteObjPos(toobject){
	aPoint = new CPoint(0,0);
	try{
		checkAbsoluteObjPos(toobject,aPoint);
	}catch(e){;}
	return aPoint;
}

function getObjSize(toobject){
	aPoint = new CPoint(0,0);
	try{	
		if (toobject){
			if ((toobject.style.width).length>1){
				aPoint.X = parseInt(toobject.style.width);
			}else{
				aPoint.X = toobject.offsetWidth;
			}
			if ((toobject.style.height).length>1){
				aPoint.Y = parseInt(toobject.style.height);
			}else{
				aPoint.Y = toobject.offsetHeight;
			}			
		}
	}catch(e){;}
	return aPoint;
}
// skrypt mierznia i lokalizacji elementow html - start

// skrypt layera - start

function ShowLayer(){    
    $("div.ReklamaSzczegoly").css('display', 'none');
    $('#banP1').css('display', 'none');
    $('div[id*=banP]').css('display', 'none');
    var ie = false;
    if (document.all) ie = true;
    var pscroll = getPageScroll();
    var aTop = new CPoint(0,0);
    //var ov = document.getElementById("fullviewbackground_overlayer");
    var bg = document.getElementById("fullviewbackground");
    //bg.innerHTML = "";
    bg.className  = "fullviewopa70";
    var psize =  getPageSize();
    var bgsize = new CPoint(0,0);
    bg.style.position = "absolute";
    bgsize.X=psize[0];
    bgsize.Y=psize[1];
    bg.style.height = bgsize.Y+"px";
    bg.style.left = "0px";
    bg.style.top = "0px";
    bg.style.width = "100%";    
    bg.style.display="block";    		
}



function ShowObjectAtStandardPosition(obj , positionname)
{
    if (obj)
    {
        var ie = false;
        if (document.all) ie = true;
        var psize =  getPageSize();
        var pageWidth = psize[0];
        var pageHeight = psize[1];
        var windowWidth = psize[2];
        var windowHeight = psize[3];
        var objTop = 0;
        var objLeft = 0;
        var displaystyle = "block";
        obj.style.position = "absolute";
        obj.style.left = "-3000px";
        obj.style.top = "0px";
        obj.style.zIndex = "999";
        obj.style.display = "block";
        var objsize = getObjSize(obj);
        if (positionname.toLowerCase() == "page-center-top")
        {
            objLeft = (psize[0] / 2) - (objsize.X /2);
        }
        
        if (positionname.toLowerCase() == "window-center-top")
        {
            
            objTop = 0+getPageScroll();
            objLeft = (psize[2] / 2) - (objsize.X /2);
        }
        
        if (positionname.toLowerCase() == "gallery-big-picture")
        {
            displaystyle = "inline";
            objTop = 25+getPageScroll();
            //objLeft = 0;
            //if (ie)
            //{
            //    obj.style.width = pageWidth+"px";
            //}
            //else
            //{
            //    obj.style.width = (pageWidth-18)+"px";
            //}
        }
        
        if (positionname.toLowerCase() == "dialog-window-center")
        {
            
            displaystyle = "inline";
            objTop = ((windowHeight/2) - (objsize.Y / 2)) + getPageScroll();
            
            //objLeft = 0;
            //if (ie)
            //{
            //    obj.style.width = pageWidth+"px";
            //}
            //else
            //{
            //    obj.style.width = (pageWidth-18)+"px";
            //}
        }
        obj.style.display = "none";
        obj.style.left = objLeft+"px";
        obj.style.top = objTop+"px";
        obj.style.display=displaystyle;
    }
}

function HideLayer(){
    $("div.ReklamaSzczegoly").css('display', 'block');
    $('#banP1').css('display', 'block');
    $('div[id*=banP]').css('display', 'block');
    var bg = document.getElementById('fullviewbackground');
    bg.style.display="none";
}

function SemiTransparentLayer()
{
}
// skrypt layera - stop
        function ShowDialogForm(formType)
        {
           ClearSendMailForm(); 
           var formTitle = document.getElementById('sendMailFormTitle');
           formTitle.innerHTML = GetFormTitle(formType);
           FillDropdown(formType);                   
           
           document.getElementById('sendMailType').value = formType;
           if(formType == 1)
           {            
             document.getElementById('divPriceProposal').style.display = 'block';
             document.getElementById('divSendMailMessage').style.display = 'none';
             document.getElementById('divSendMailYourPhone').style.display = 'block';
             
             document.getElementById('gwiazdkaEmail').style.display = 'inline';
           }else
           {
             document.getElementById('divPriceProposal').style.display = 'none';
             document.getElementById('divSendMailMessage').style.display = 'block';
             document.getElementById('divSendMailYourPhone').style.display = 'none';
             
             document.getElementById('gwiazdkaEmail').style.display = 'none';
             document.getElementById('gwiazdkaWiadomosc').style.display = 'none';            
           }
           
           var selectLabel = document.getElementById('MailFormSelectLabel');
           selectLabel.innerHTML = GetSelectLabel(formType);
           
           var fView = document.getElementById("dialogForm");                
           ShowLayer();
           ShowObjectAtStandardPosition(fView,"dialog-window-center");
           
           if(DaneOgloszeniodawcyVisible)
           {
             var contactTextarea = document.getElementById('ctl00_ctl00_ContentPlaceHolder1_BaseContent_ucContactForm_divDaneOgloszeniodawcy');
             contactTextarea.className  = 'GlobalFloatLeft DaneOgloszeniodawcy';  
           }
        }
        
        function CloseDialogForm()
        {
            ClearSendMailForm(); 
            var fView = document.getElementById("dialogForm");
            fView.style.display = "none";          
            HideLayer(); 
           
           if(DaneOgloszeniodawcyVisible)
           { 
             var contactTextarea = document.getElementById('ctl00_ctl00_ContentPlaceHolder1_BaseContent_ucContactForm_divDaneOgloszeniodawcy');
             contactTextarea.className  = 'GlobalFloatLeft DaneOgloszeniodawcy';  
           }         
        }
   
 function IEOldBrowserCheck()
 {
   var bName = navigator.appName;
   var agt=navigator.userAgent.toLowerCase();
    
    var is_major = parseInt(navigator.appVersion);
    var is_minor = parseFloat(navigator.appVersion);
    
    var is_ie     = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
    var is_ie3    = (is_ie && (is_major < 4));
    var is_ie4    = (is_ie && (is_major == 4) && (agt.indexOf("msie 4")!=-1) );
    var is_ie5    = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.0")!=-1) );
    var is_ie5_5  = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.5") !=-1));
    var is_ie6    = (is_ie && (is_major == 4) && (agt.indexOf("msie 6.")!=-1) );  
    var is_ie7    = (is_ie && (is_major == 4) && (agt.indexOf("msie 7.")!=-1) );  
    var is_ie7down  = (is_ie && (is_ie3 || is_ie4 || is_ie5 || is_ie5_5 || is_ie6 || is_ie7));
   
   var bVer = null;
   var isIEOlder = false;
   /*if(validateInteger(navigator.appVersion))
   {
     bVer = parseInt(navigator.appVersion);
   }
   
   var isIEOlder = false;
   if(bName == "Microsoft Internet Explorer")
   {
     if(bVer <= 7)
     {
       isIEOlder = true;
     }
   }*/
   
   if(is_ie7down)
   {
     isIEOlder = true;
   }
   
   //alert(agt + "<br> is_ie: " + is_ie + " is_ie6: " + is_ie6 + " is_ie7: " + is_ie7  + " is ieUp7: " + is_ie7down);  
   return isIEOlder;
 }
 
 function SendNewProducerMail()
 {
    var isValid = true;
    document.getElementById('divSendMailNewProducerErrorText').style.display = 'none';
    var message = document.getElementById('inpNewProducerMailMessage');
    
    isValid = CheckIfIsEmpty(isValid, message, 'divSendMailNewProducerErrorText', 'FormularzTextareaBgr', false);
    if(isValid == true)
    {
             //wywolywany ajax, który wysle maila
               $.ajax({
            type: "POST",
            url: '/LocalServices/MailSender.asmx/SendInnerMail',
            contentType: "application/json; charset=utf-8",        
            data : "{ 'emailText': '" + message.value + "','templatename':'service_contactform_newbrand_template', "
            + "'emailSubject': 'Propozycja dodania nowego producenta', 'mailLanguage': '" +  pageLanguage + "', 'urgent' : true}",
            dataType: "json",
            success: AjaxLayerSucceeded,
            error: AjaxLayerFailed
          });
          
          CloseDialogLayer('divAddNewProducer');
          document.getElementById('divSendMailNewProducerErrorText').style.display = 'none';
          message.value = '';
    }else
    {
        document.getElementById('divSendMailNewProducerErrorText').style.display = 'block';
    }
      
 }
   
      
 function SendMailForm()
 {
   var isValid = true; 
   document.getElementById('divSendMailErrorText').style.display = 'none';
   document.getElementById('divSendMailWrongMail').style.display = 'none';
   var formType = document.getElementById('sendMailType').value;
   var priceProposal = document.getElementById('inpPriceProposal');
   var yourEmail = document.getElementById('inpSendMailYourEmail');
   var yourPhone = document.getElementById('inpSendMailYourPhone');
   var message = document.getElementById('inpSendMailMessage');
   var selIdx = document.getElementById('sltMailOption').selectedIndex;
   var selValue = document.getElementById('sltMailOption').options[selIdx].text; 
   
   if(formType == 1)
   {
     isValid = CheckIfIsEmpty(isValid, priceProposal, 'divSendMailErrorText', 'FormularzInputyBgr', true);
     //document.getElementById('divSltMailOption').style.display = 'none';

   }else
   {
    //isValid = CheckIfIsEmpty(isValid, message, 'divSendMailErrorText', 'FormularzTextareaBgr Wiadomosc', false);
    if(selIdx == 0)
    {
      if(IEOldBrowserCheck())
      {
         document.getElementById('divSltMailOption').className = "FormularzSelectBorder0IE FormularzSelectBlad";
      }else
      {
         document.getElementById('sltMailOption').className = 'FormularzInputyBgr PowodZgloszenia' + " FormularzInputyBlad"; 
      }    

      isValid = false;
    }else
    {
      
      if(IEOldBrowserCheck())
      {
         document.getElementById('divSltMailOption').className = "FormularzSelectBorder0IE";
      }else
      {
         document.getElementById('sltMailOption').className = 'FormularzInputyBgr PowodZgloszenia'; 
      }    

    }
   }
   
    var validMail = false;
   if(formType == 1)
   {
     validMail = CheckIfIsEmpty(isValid, yourEmail, 'divSendMailErrorText', 'FormularzInputyBgr', false);
     
   }
   else
   {
     validMail = true;
   }
   validMail = emailValidation(validMail, yourEmail, 'divSendMailWrongMail', 'FormularzInputyBgr');  
   
    if(isValid == true  && validMail == true)
   {
     var mailTitle = null;
     var token = null;
     var descriptionText = "";
     var mailLang = usermailLanguage;

     if(formType == 1)
     {
       token = priceFormToken;
       mailTitle = priceFormMailTitle;           
       descriptionText = priceProposal.value + " " + selValue;
     }else
     {
       token = errorFormToken;
       mailTitle = errorFormMailTitle;
       descriptionText = "<#QueryReason: " + userLangSelect[selIdx] + "#>" + message.value;
       mailLang = pagecurrentLanguage;
     }
     descriptionText = "" + descriptionText;
     token = "" + token;
     
     //wywolywany ajax, który wysle maila
               $.ajax({
            type: "POST",
            url: '/LocalServices/MailSender.asmx/SendMail',
            contentType: "application/json; charset=utf-8",        
            data : "{ 'senderEmail': '" + yourEmail.value + "','senderPhone':'" + yourPhone.value + "', 'emailText': '" +  descriptionText
            + "', 'emailSubject': '" + mailTitle + "', 'mailLanguage': '" +  mailLang + "', 'formTokenId': '" + token + "', 'urgent' : true}",
            dataType: "json",
            success: AjaxLayerSucceeded,
            error: AjaxLayerFailed
          });
     
     ClearSendMailForm();     
     CloseDialogForm();
   }else
   {
      if(!isValid)
      {
        document.getElementById('divSendMailErrorText').style.display = 'block';
        if(yourEmail.value == '')
        {
           document.getElementById('divSendMailWrongMail').style.display = 'none';
        }else
        {
          if(!validMail)
          {
            document.getElementById('divSendMailWrongMail').style.display = 'block';
          }else
          {
            document.getElementById('divSendMailWrongMail').style.display = 'none';
          }
        }    
      }else
      {     
        document.getElementById('divSendMailErrorText').style.display = 'none';
        if(!validMail)
        {
          document.getElementById('divSendMailWrongMail').style.display = 'block';
        }
      }
   }
 } 
 
 function AjaxLayerSucceeded(result)
{
   var resultInfo = "Status wysłania: " + result.d.IsSent + " Informacja o wysłaniu: " + result.d.DetailStatus;
   
   if(result.d.IsSent == true)
   {
   /*var formType = document.getElementById('sendMailType').value;
   var token = null;
   var mailsentType = null
   if(formType == 1)
   {
      token = priceFormToken;
      mailsentType = 2;
   }else
   {
      token = errorFormToken;
      mailsentType = 3;
   }
            $.ajax({
            type: "GET",
            url: '/Handlers/StatisticHandler.ashx?stat=2&adId=' + advertId + '&mType=' + mailsentType + '&tokenId=' + token +'&message=Przykladowy_tekst',
            contentType: "application/json; charset=utf-8",        
            dataType: "json",
            success: AjaxStatisticsSucceeded,
            error: AjaxStatisticsFailed
          });*/
   //alert(resultInfo);  
   //if(result.d.IsSent != true)
   //{
   //  $("#contactFormMessageSended").html(mailErrorMessage);
   //}
   }
}

function AjaxLayerFailed(result) 
{
   //$("#contactFormMessageSended").html(mailErrorMessage);
}   

 function AjaxStatisticsSucceeded(result)
{
   var resultInfo = "Status wysłania: " + result.d.IsSent + " Informacja o wysłaniu: " + result.d.DetailStatus;
   //alert(resultInfo);
}    

function AjaxStatisticsFailed(result) 
{
 //alert(result.status + ' ' + result.statusText);
}

//Walidacja formularza kontaktowego na stroni kontaktowej
function ValidateStaticContactForm()
{
  var isValid = true; 
  var errorTextLayer = document.getElementById('divContactErrorText');
  errorTextLayer.style.display = 'none';
  var errorMailLayer = document.getElementById('divContactMailError');
  errorMailLayer.style.display = 'none';
  
  var mailSent = document.getElementById('divContactSent');
  var contactForm = document.getElementById('divContactForm');
  
  var selIdx = document.getElementById('sltMessageCategory').selectedIndex;
  var selValue = document.getElementById('sltMessageCategory').options[selIdx].text; 
   
    if(selIdx == 0)
    {
      if(IEOldBrowserCheck())
      {
         document.getElementById('divMessageCategory').className = "FormularzSelectBorder0IE FormularzSelectBlad";
      }else
      {
         document.getElementById('sltMessageCategory').className = 'FormularzInputyBgr PowodZgloszenia' + " FormularzInputyBlad"; 
      }    
      isValid = false;
    }else
    {
      
      if(IEOldBrowserCheck())
      {
         document.getElementById('divMessageCategory').className = "FormularzSelectBorder0IE";
      }else
      {
         document.getElementById('sltMessageCategory').className = 'FormularzInputyBgr PowodZgloszenia'; 
      }    

    }
   
    var contactTextarea = document.getElementById('txtDescription');
    isValid = CheckIfIsEmpty(isValid, contactTextarea, 'divContactErrorText', 'FormularzTextareaBgr ', false);
    
    var selClientTypeIdx = document.getElementById('sltClientType').selectedIndex;
    var selClientTypeValue = document.getElementById('sltClientType').options[selClientTypeIdx].text; 
   
    if(selClientTypeIdx == 0)
    {
      if(IEOldBrowserCheck())
      {
         document.getElementById('divClientType').className = "FormularzSelectBorder0IE FormularzSelectBlad";
      }else
      {
         document.getElementById('sltClientType').className = 'FormularzInputyBgr PowodZgloszenia' + " FormularzInputyBlad"; 
      }    
      isValid = false;
    }else
    {
      
      if(IEOldBrowserCheck())
      {
         document.getElementById('divClientType').className = "FormularzSelectBorder0IE";
      }else
      {
         document.getElementById('sltClientType').className = 'FormularzInputyBgr PowodZgloszenia'; 
      }    

    }
    
     var contactMail = document.getElementById('inpSendMailYourEmail');
     var validMail = false;
     isValid = CheckIfIsEmpty(isValid, contactMail, 'divContactErrorText', 'FormularzInputyBgr', false);
     validMail = emailValidation(isValid, contactMail, 'divContactMailError', 'FormularzInputyBgr');
     
      var personName = document.getElementById('inpPersonName');
     
     if(isValid == true  && validMail == true)
     {
        contactForm.style.display = 'none';  
        mailSent.style.display = 'block';
       
        var descriptionText =  "<#MessageType: " + messageType[selIdx] + "#>" + "<#UserType: " + clientType[selClientTypeIdx] + "#>" + "<#UserName: " + personName.value + "#>" + contactTextarea.value;
        var token = "" + contactFormToken;
        //var token = "";
        
        $.ajax({
            type: "POST",
            url: '/LocalServices/MailSender.asmx/SendMail',
            contentType: "application/json; charset=utf-8",        
            data : "{ 'senderEmail': '" + contactMail.value + "', 'emailText': '" +  descriptionText
            + "', 'emailSubject': '" + MailTitle + "', 'mailLanguage': '" + pagecurrentLanguage + "', 'formTokenId': '" + token + "', 'urgent' : true}",
            dataType: "json",
            success: AjaxSucceeded,
            error: AjaxFailed
          });
     
     contactMail.value = '';
     contactTextarea.value = '';
     personName.value = '';
     document.getElementById('sltClientType').selectedIndex = 0;
     document.getElementById('sltMessageCategory').selectedIndex = 0;
     }else
     {
       if(!isValid)
       {      
       errorTextLayer.style.display = 'block';
       if(contactMail.value == '')
       {
         errorMailLayer.style.display = 'none';
       }else
       {
         if(!validMail)
         {
            errorMailLayer.style.display = 'block';
         }else
         {
            errorMailLayer.style.display = 'none';
         }
       }
       }else
       {
         errorTextLayer.style.display = 'none';
         if(!validMail)
         {
            errorMailLayer.style.display = 'block';
         }
       }  
     
     contactForm.style.display = 'block';  
     mailSent.style.display = 'none'; 
     
     }
}


//Walidacja formularza kontaktowego w detalach ogloszeń
function ValidateContactForm()
{
  var isValid = true; 
  var errorTextLayer = document.getElementById('divContactErrorText');
  errorTextLayer.style.display = 'none';
  var errorMailLayer = document.getElementById('divContactMailError');
  errorMailLayer.style.display = 'none';
  var mailSent = document.getElementById('divContactSent');
  var contactForm = document.getElementById('divContactForm');
  
   var contactMail = document.getElementById('inpContactEmail');
   var contactPhone = document.getElementById('inpContactYourPhone');
   var contactTextarea = document.getElementById('txtDescription');
  
  isValid = CheckIfIsEmpty(isValid, contactMail, 'divContactErrorText', 'FormularzInputyBgr', false);
  isValid = CheckIfIsEmpty(isValid, contactTextarea, 'divContactErrorText', 'FormularzTextareaBgr ', false);
  
  var validMail = false;
  validMail = emailValidation(isValid, contactMail, 'divContactMailError', 'FormularzInputyBgr');
    
   if(isValid == true  && validMail == true)
   {
     mailSent.style.display = 'block';
     contactForm.style.display = 'none';  
     var descriptionText = "" + contactTextarea.value;
     var token = "" + contactFormToken;
     //data: "{}",
     //data : { senderEmail: JSON.stringify($("#inpContactEmail").val()), emailText: JSON.stringify($("#txtDescription").val()), emailSubject: JSON.stringify("Zapytanie dotyczące oferty"), mailLanguage: JSON.stringify($("#currentLanguage").val()), urgent: true},
        
          $.ajax({
            type: "POST",
            url: '/LocalServices/MailSender.asmx/SendMail',
            contentType: "application/json; charset=utf-8",        
            data : "{ 'senderEmail': '" + contactMail.value + "','senderPhone': '" + contactPhone.value + "', 'emailText': '" +  descriptionText
            + "', 'emailSubject': '" + contactFormMailTitle + "', 'mailLanguage': '" + usermailLanguage + "', 'formTokenId': '" + token + "', 'urgent' : true}",
            dataType: "json",
            success: AjaxSucceeded,
            error: AjaxFailed
          });
     
     contactMail.value = '';
     contactTextarea.value = '';
     contactPhone.value = '';   
   }else
   {
     if(!isValid)
     {      
       errorTextLayer.style.display = 'block';
       if(contactMail.value == '')
       {
         errorMailLayer.style.display = 'none';
       }else
       {
         if(!validMail)
         {
            errorMailLayer.style.display = 'block';
         }else
         {
            errorMailLayer.style.display = 'none';
         }
       }
     }else
     {
         errorTextLayer.style.display = 'none';
         if(!validMail)
         {
            errorMailLayer.style.display = 'block';
         }
     }  
     
     contactForm.style.display = 'block';  
     mailSent.style.display = 'none'; 
   }
}

function AjaxSucceeded(result)
{
   //var resultInfo = "Status wysłania: " + result.d.IsSent + " Informacja o wysłaniu: " + result.d.DetailStatus;
   //alert(resultInfo);
   if(result.d.IsSent != true)
   {
     $("#contactFormMessageSended").html(mailErrorMessage);
   }else
   {
     /* var token = contactFormToken;
     var mailsentType = 1;
            $.ajax({
            type: "GET",
            url: '/Handlers/StatisticHandler.ashx?stat=2&adId=' + advertId + '&mType=' + mailsentType + '&tokenId=' + token +'&message=Przykladowy_tekst',
            contentType: "application/json; charset=utf-8",        
            dataType: "json",
            success: AjaxStatisticsSucceeded,
            error: AjaxStatisticsFailed
          });*/
   }
}

function AjaxFailed(result) 
{
   $("#contactFormMessageSended").html(mailErrorMessage);
   //alert(result.status + ' ' + result.statusText);

}  

function ReturnToContactForm()
{
     var mailSent = document.getElementById('divContactSent');
     var contactForm = document.getElementById('divContactForm');
     mailSent.style.display = 'none';
     contactForm.style.display = 'block';
     var contactTextarea = document.getElementById('txtDescription');
     contactTextarea.className  = 'FormularzTextareaBgr';
     
}

function stripIt(x){
x.value = x.value.replace(/['"]/g,'');
};

function CheckIfIsEmpty(isValid, input, errorDivName, classname, isInteger)
{
   var errorDiv = document.getElementById(errorDivName);
   stripIt(input);
   
   if(input.value == '') 
   {
	 if(isValid == false)
	 {
	   input.focus();
	 }
	 input.className = classname + " FormularzInputyBlad"; 
	 errorDiv.style.display = 'block';
	 return false;
   }else
   {
     
     if(isInteger == true)
     {
       isValid =  validateInteger(input.value)
       if(isValid == false)
	   {
	     input.focus();
	     input.className = classname + " FormularzInputyBlad"; 
	     errorDiv.style.display = 'block';
	     return false;
	   }else
	   {
	     input.value = parseInt(input.value);
	     input.className = classname;
	     errorDiv.style.display = 'none';
	     return true;
	   }
     }else
     { 
       input.className = classname;
       if(isValid == false)
       {
         errorDiv.style.display = 'block';
         return false;
       }else
       {
         errorDiv.style.display = 'none';
         return true;
       } 
     }
   }
}

function validateInteger(numb){ 
  if(isNaN(parseInt(numb))) 
  {
    return false;
  }else
  {
    return true;
  }
} 

function ClearSendMailForm()
{
   var priceInput = document.getElementById('inpPriceProposal');
   priceInput.value = '';
   priceInput.className = 'FormularzInputyBgr';
   
   var yourPhone = document.getElementById('inpSendMailYourPhone');
   yourPhone.value = '';
   
   var priceInput = document.getElementById('inpSendMailYourEmail');
   priceInput.value = '';
   priceInput.className = 'FormularzInputyBgr';
   
   var message = document.getElementById('inpSendMailMessage');
   message.value = '';
   message.className = 'FormularzTextareaBgr Wiadomosc';
   
   document.getElementById('divSendMailErrorText').style.display = 'none';
   document.getElementById('divSendMailWrongMail').style.display = 'none'; 
   
   document.getElementById('divSltMailOption').className = 'FormularzSelectBorder0';
   document.getElementById('sltMailOption').className = 'FormularzInputyBgr';
}

function emailValidation(isValid, email, errorDivName, classname)
{
  var errorDiv = document.getElementById(errorDivName);
  var regex = /^[a-zA-Z0-9._-]+@([a-zA-Z0-9.-]+\.)+[a-zA-Z0-9.-]{2,4}$/;
  //var regex = /^[^@]+@([a-z0-9\-]+\.)+[a-z]{2,5}$/i;

  var returnValue = false;
   if(email.value.length == 0 || regex.test(email.value) )
   {
     if(email.value.length == 0 && isValid == false)
     {
          errorDiv.style.display = 'block';
          email.className = classname + " FormularzInputyBlad"; 
     }else
     {
       errorDiv.style.display = 'none';
       email.className = classname; 
       returnValue = true;
     }
   }else
   {
     errorDiv.style.display = 'block';
     email.className = classname + " FormularzInputyBlad"; 
     email.focus();
   }
   
   return returnValue;
}

function CalculateFormTokenResponse(token)
{
    
}





    function ShowRelatedRegion(value, relatedDictionaryName) {
        var tmpFieldNameDict = GetClientId(relatedDictionaryName);
        var relatedSelect = document.getElementById(tmpFieldNameDict);

        if (value == 'PL') {
            ReloadSelect(relatedSelect, value);
        } else {
            relatedSelect.length = 1;
        }
    }

    function ReloadSelect(selectElement, parentSelectorId, dictarray) {
        var element = dictarray[parentSelectorId];
        
        var selIdx = selectElement.selectedIndex;
        var selValue = selectElement.options[selIdx].value;
        
        selectElement.length = 1;
        var counter = 0;

        for (key in element) {
            var text = element[key][0];
            var value = element[key][1];
            if (value != undefined) {
                counter++;
                selectElement.options[counter] = new Option(text, value);
                if(selValue == value)
                {
                  selectElement.options[counter].selected = true;
                }
            }
        }
    }
    
     function ShowOnStartRelateddDctionary(value, relatedDictionaryName, arrayName) {
        var tmpFieldNameDict = GetClientId("advert_" + relatedDictionaryName);
        var relatedSelect = document.getElementById(tmpFieldNameDict);
        if (relatedDictionaryName == "Region") {
            divRegion = document.getElementById(GetClientId('ElContRegion'));
            if (value == "PL") {
                divRegion.style.display = 'block';
            } else {
                divRegion.style.display = 'none';
            }
        }
         ReloadSelect(relatedSelect, value, arrayName);
    }
    
    function ShowRelateddDctionary(value, relatedDictionaryName, arrayName) {
        var tmpFieldNameDict = GetClientId("advert_" + relatedDictionaryName);
        var relatedSelect = document.getElementById(tmpFieldNameDict);
        if (relatedDictionaryName == "Region") {
            var tmpFieldNameRegion = GetClientId('ElContRegion');
            divRegion = document.getElementById(tmpFieldNameRegion);
            if (value == "PL") {
                divRegion.style.display = 'block';
            } else {
                divRegion.style.display = 'none';
            }
        }
        ReloadSelect(relatedSelect, value, arrayName);
    }

    function ShowRelateddDctionaryWithValue(value, relatedDictionaryName, arrayName, relatedValue, parentDictName) {
        var tmpParentDictName = GetClientId("advert_" + parentDictName);
        var parentSelect = document.getElementById(tmpParentDictName);

        if(parentDictName == "CountryWithPhonePrefixes" && parentSelect != null && parentSelect.value == 'PL')
        {
        var tmpFieldNameDict = GetClientId("advert_" + relatedDictionaryName);
        var relatedSelect = document.getElementById(tmpFieldNameDict);
        if (relatedDictionaryName == "Region") {
            var tmpFieldNameRegion = GetClientId('ElContRegion');
            divRegion = document.getElementById(tmpFieldNameRegion);
            if (value == "PL") {
                divRegion.style.display = 'block';
            } else {
                divRegion.style.display = 'none';
            }
        }
        ReloadSelectWithValue(relatedSelect, value, arrayName, relatedValue);
        }
    }
    
   function ShowRelateddDctionaryWithUnknownValue(parentDictName, relatedDictionaryName, arrayName, relatedValue) {
        var tmpParentDictName = GetClientId("advert_" + parentDictName);
        var parentSelect = document.getElementById(tmpParentDictName);
        
        var tmpFieldNameDict = GetClientId("advert_" + relatedDictionaryName);
        var relatedSelect = document.getElementById(tmpFieldNameDict);
        
        var tmpFieldNameDict = GetClientId("advert_" + relatedDictionaryName);
        var relatedSelect = document.getElementById(tmpFieldNameDict);
        var tmpFieldNameRegion = GetClientId('ElContRegion');
        divRegion = document.getElementById(tmpFieldNameRegion);

        if(parentDictName == "CountryWithPhonePrefixes")
        {
          if(parentSelect != null && parentSelect.value == 'PL')
          {
            divRegion.style.display = 'block';
                
            var parentSelValue = parentSelect.selectedIndex;
            var parentValue = parentSelect.options[parentSelect.selectedIndex].value;
            ReloadSelectWithValue(relatedSelect, parentValue, arrayName, relatedValue);
          }
          else
          {
            divRegion.style.display = 'none';
          }
        }      
    }
    
   function ReloadSelectWithValue(selectElement, parentSelectorId, dictarray, relatedValue) {
        var element = dictarray[parentSelectorId];
        
        //var selIdx = selectElement.selectedIndex;
        //var selValue = selectElement.options[selIdx].value;
        
        selectElement.length = 1;
        var counter = 0;

        for (key in element) {
            var text = element[key][0];
            var value = element[key][1];
            if (value != undefined) {
                counter++;
                selectElement.options[counter] = new Option(text, value);
                if(relatedValue == value)
                {
                  selectElement.options[counter].selected = true;
                }
            }
        }
    }

    function GetObjByClientId(ClientId) {
       
        var tmpFieldName = GetClientId(ClientId);
        if(tmpFieldName != null)
        {
        return document.getElementById(tmpFieldName);
        }else
        {
         return null;
        }
    }

	function SetGraphicalCheckBoxState(checkboxId, state, oncssclass, offcssclass){
		var elem = document.getElementById(checkboxId);
		if (elem){
			if (state){
				elem.className = oncssclass;
			}else{
				elem.className = offcssclass;
			}
			
		}
	} 
	
    function ChangeCheckBox(fileldname, graphicfield, basevalue, oncssclass, offcssclass, groupName) {
        try {
            scriptNamingPath = "ctl00_ctl00_ContentPlaceHolder1_BaseContent_ctl01_rpAdvertFields_ctl15_";
            
            if(groupName != '')
            {
                var count = document.getElementsByTagName('input').length;
                var i = 0;
                var elementName;
                for (i = 0; i < count; i++) {
                  var fieldidik = document.getElementsByTagName('input')[i].id;
                  if(fieldidik != '' && fieldidik.indexOf(fileldname) == -1)
                  {
                     var posGr = fieldidik.indexOf(groupName);
                     if(posGr >= 0)
                     {
                       // var subName = fileldname.substring(0, posGr);
                        //pos = fieldidik.indexOf(subName);
                        //if (pos >= 0) {
                          var field = document.getElementById(fieldidik);
                          field.value = '';
                        //}
                     }
                  }
               }
               
               var countdiv = document.getElementsByTagName('div').length;
               var j = 0;
               var elementDivName;
               for (j = 0; j < countdiv; j++) {
                  var fieldidik = document.getElementsByTagName('div')[j].id;
                  if(fieldidik != '' && fieldidik.indexOf(graphicfield) == -1)
                  {
                     var posGr = fieldidik.indexOf(groupName);
                     if(posGr >= 0)
                     {
                        //var subName = fileldname.substring(0, posGr);
                        //pos = fieldidik.indexOf(subName);
                        //if (pos >= 0) {
                           var field = document.getElementById(fieldidik);
                           field.className = offcssclass;
                        //}
                     }
                  }
               }                        
            }
            
            elementName = GetClientId(fileldname);
            //elementName = $("[input#id$=_" + fileldname + "]").attr("id");
            graphicfieldElementName = GetClientId(graphicfield);
            //graphicfieldElementName = $("div[id$=_" + graphicfield + "]").attr("id");

            var chval = document.getElementById(elementName);
            if (chval.value.length > 0) {
                chval.value = "";
				SetGraphicalCheckBoxState(graphicfieldElementName,false,oncssclass,offcssclass); 
                //document.getElementById(graphicfieldElementName).className = offcssclass;
            }
            else {
                chval.value = basevalue;
				SetGraphicalCheckBoxState(graphicfieldElementName,true,oncssclass,offcssclass); 
                //document.getElementById(graphicfieldElementName).className = oncssclass;
            }
        }
        catch (e) {
            //alert(e.message);
        }
    }

	function updateCheckBoxes(fieldIdFirsPart,checkboxIdFirstPart, oncssclass, offcssclass){
		var frm = document.forms[0];
		var tmp = "";
		for(i = 0 ; i < frm.elements.length ; i++)
		{
			var elem = frm.elements[i];
			if (elem)
			{
				if (elem.tagName.toLowerCase() == "input")
				{
					if (elem.type.toLowerCase() == "hidden" && elem.value == "1")
					{
						if (elem.id.indexOf(fieldIdFirsPart) > 0){
							SetGraphicalCheckBoxState(elem.id.replace(fieldIdFirsPart,checkboxIdFirstPart), true, oncssclass, offcssclass)
						}
					} 
				}
			}
		}
	}

    function RemoveSelections() {
        var count = document.getElementsByTagName('*').length;
        var i = 0;
        for (i = 0; i < count; i++) {
            eleName = document.getElementsByTagName('*')[i];
            var classname = RemoveSubStringfromString(eleName.className, "FormularzInputyAktywne");
            eleName.className = classname;
        }
    }

    function GetClientIdNew(strid) {
       var el = $("#" + strid);
       if (el.length < 1)
          el = $("[id$=_" + strid + "]");
        return el.attr('id');
    }
    
    function GetClientId(strid) { 
        
       var isOpera = false, isIE = false;
       if(typeof(window.opera) != 'undefined')
       {
         isOpera = true;
       }
       
       var IEpos = navigator.appName.indexOf('Internet Explorer');
       if(!isOpera && IEpos >= 0)
       {
         isIE = true;
       }
       
      if(isIE)
      {   
        //IE
        var elem = document.getElementsByTagName('*');
        var element;
        for(i = 0,iarr = 0; i < elem.length; i++) 
        {
           element = elem[i].getAttribute("id");
           if(element != null  && element != '' && element != '[object]')
           {
             var pos1 = element.indexOf(strid);
             if (pos1 != null && pos1 >= 0) 
             {
                element = element.replace("$", "_");
               break;       
             }
           }      
        }
     
        return element;
      }
      else
      {
        var count = document.getElementsByTagName('*').length;
        var i = 0;
        var eleName;
        for (i = 0; i < count; i++) 
        {
            eleName = document.getElementsByTagName('*')[i].id;
            if(eleName != null && eleName != '')
            {
              pos = eleName.indexOf(strid);
              if (pos >= 0)
              {
               break;
              }
            }
        }
        return eleName;
      }
    }

    function PriceFill(firstPriceName, secondPriceName, type) {
        var mnoznik = 1/euroExchangeRate;
        if (type == 2) {
            mnoznik = euroExchangeRate;
        }

        var firstprice = document.getElementById(GetClientId('advert_' + firstPriceName));
        var seconprice = document.getElementById(GetClientId('advert_' + secondPriceName));

        if (seconprice.value.length == 0) {
            seconprice.value = parseInt(Math.round((firstprice.value * mnoznik)*100)/100);
        }
    }

    var focusableElements = new Array();
    function getFocusableElementsIds() {
        return focusableElements;
    }

    function addFocusableElementId(elementid) {
        var simpeelementId = "";
        var focusableelementsdef = "tbEmail|tbPassword|tbPasswordConfirm|tbName|tbZipCode|tbCity|tbAddress|tbPhone2|tbAfterPhone2|tbPhone3|tbAfterPhone3|tbFax|tbAfterFax|tbMessengerId|tbWebPage";
        var elementexistsinlist = false;
        for (var i = 0; i < focusableElements.length; i++) {
            if (focusableElements[i] == elementid) elementexistsinlist = true;
        }
        if (!elementexistsinlist) {
            focusableElements[focusableElements.length] = new Array(elementid, simpeelementId);
        }
        return simpeelementId;
    }
    
    function SetValidIcon(fieldId, IconType)
    {
      SetValidIconWithName(fieldId, IconType, "ValidIcon")
    }

    function SetValidIconWithName(fieldId, IconType, iconName) {
        var divIonId = fieldId + iconName;
        var elemIco = GetClientId(divIonId);
        var iconElement = document.getElementById(elemIco);
        switch (IconType) {
            case 1:
                iconElement.className = "GlobalFloatLeft GrafikiStrony";
                break;

            case 2:
                iconElement.className = "GlobalFloatLeft GrafikiStrony FormularzPoprawnieIco";
                break;
                
            case 3:
                iconElement.className = "GlobalFloatLeft GrafikiStrony FormularzBladIco";
                break;
            default:
                iconElement.className = "GlobalFloatLeft GrafikiStrony";
                break;
        }
    
    }
    

    function setFocusOnCurrentElement(inputobj) {
        if (inputobj) {
            var classname = inputobj.className;
            RemoveSelections();
            inputobj.className = classname + " FormularzInputyAktywne";
            SetValidIcon(inputobj.id, 1);
        }
    }
    
    function SetFocusOnElementById(inputobj, fieldname)
    {       
            if (inputobj) {
            var classname = inputobj.className;
            RemoveSelections();
            inputobj.className = classname + " FormularzInputyAktywne";
            SetValidIconWithName(fieldname, 1, "Ico");
        }
    }
    
    
    function SetFocusOnElementByIdInvoice(inputobj, fieldname)
    {       
            if (inputobj) {
            var classname = inputobj.className;
            RemoveSelections();
            inputobj.className = classname + " FormularzInputyAktywne";
            SetValidIconWithName(fieldname, 1, "ValidIcon");
        }
    }
    
    function SetFocusOnElementByIdWithoutHelp(inputobj, fieldname)
    {       
            if (inputobj) {
            var simpleelementId = addFocusableElementId(inputobj.id);
            var classname = inputobj.className;
            RemoveSelections();
            inputobj.className = classname + " FormularzInputyAktywne";
            SetValidIconWithName(fieldname, 1, "Ico");
            
            var infoelem = document.getElementById(fieldname + "Info");
            var infoelemend = document.getElementById(fieldname + "InfoEnd");
            if (infoelem) {
                infoelem.style.display = "none";
                if (infoelemend) {
                    infoelemend.style.display = "none";
                }
            }
        }
    }
    
        function SetFocusOnElementByIdGrey(inputobj, fieldname)
    {       
            if (inputobj) {
            var simpleelementId = addFocusableElementId(inputobj.id);
            var classname = inputobj.className;         
            
            RemoveSelections();
            inputobj.className = classname + " FormularzInputyAktywne";
            var tmpFieldName = GetClientId(simpleelementId + "Ico");
            var icoelem = document.getElementById(tmpFieldName);
            SetValidIconWithName(fieldname, 1, "Ico");
            
            if (simpleelementId && (simpleelementId.length > 0)) {
                removeIcoSign(icoelem);
                
                
                var infoelem = document.getElementById(simpleelementId + "Info");
                var infoelemend = document.getElementById(simpleelementId + "InfoEnd");
                if (infoelem) {
                    infoelem.style.display = "block";
                    if (infoelemend) {
                        infoelemend.style.display = "block";
                    }
                }
            }
            
            /*var infoelem = document.getElementById(fieldname + "Info");
            var infoelemend = document.getElementById(fieldname + "InfoEnd");
            if (infoelem) {
                infoelem.style.display = "none";
                if (infoelemend) {
                    infoelemend.style.display = "none";
                }
            }*/
        }
    }

    function removeFocusOnAll() {
        var felemens = getFocusableElementsIds();
        for (var i = 0; i < felemens.length; i++) {
            var mainelem = document.getElementById(felemens[i][0]);
            if (mainelem) {
                mainelem.className = RemoveSubStringfromString(mainelem.className, "FormularzInputyAktywne");
                /*var currentClassName = " " + mainelem.className + " ";
                if (currentClassName.indexOf(" FormularzInputyAktywne ") > 0) {
                    currentClassName = currentClassName.replace(" FormularzInputyAktywne ", " ");
                    while (currentClassName.indexOf(" ") == 0) {
                        currentClassName = currentClassName.substr(1, currentClassName.length - 1);
                    }
                    while (currentClassName.lastIndexOf(" ") == (currentClassName.length - 1)) {
                        currentClassName = currentClassName.substr(0, currentClassName.length - 1)
                    }
                    mainelem.className = currentClassName;
                }*/
            }
        }
    }

    function GetKeyCode(evt) {
        var keyCode;

        if ("which" in evt) {// NN4 & FF &amp; Opera
            keyCode = evt.which;
        } else if ("keyCode" in evt) {// Safari & IE4+
            keyCode = evt.keyCode;
        } else if ("keyCode" in window.event) {// IE4+
            keyCode = window.event.keyCode;
        } else if ("which" in window.event) {
            keyCode = evt.which;
        } else { ketcode = 'unknown'; }

        return keyCode;
    }

    function RemoveSubStringfromString(originalString, stringToRemove) {
        var pos = originalString.indexOf(stringToRemove);
        if (pos != -1) {
            originalString = originalString.replace(stringToRemove, "");
        }
        return originalString;
    }

    function RemoveInputFieldLayoutStyles(field) {
        var classname = field.className;
        classname = RemoveSubStringfromString(classname, "FormularzInputyBgr");
        classname = RemoveSubStringfromString(classname, "FormularzInputyAktywne");
        classname = RemoveSubStringfromString(classname, "FormularzInputyBlad");

        return classname;
    }

    function RequiredOnChange(field) {
        if (field.value == "") {
            field.className = "FormularzInputyBgr FormularzInputyBlad";
            SetValidIcon(field.id, 3);
        } else {

            var classnameStr = field.className;
            var c1Pos = classnameStr.indexOf("FormularzInputyBgr")
            if (c1Pos != 0) {
                classnameStr.substr(c1Pos, 18);
            }

            var c2Pos = classnameStr.indexOf("FormularzInputyAktywne")
            if (c2Pos != 0) {
                classnameStr.substr(c2Pos, 22);
            }
            field.className = " FormularzInputyBgr";
            SetValidIcon(field.id, 2);
        }
    }
    
    function RequiredWithSpecifilLength(field, length)
    {
       if(field.value.length != length)
       {
          var classnameStr = field.className;
          var c1Pos = classnameStr.indexOf("FormularzInputyBgr")
          if (c1Pos != 0) {
                classnameStr.substr(c1Pos, 18);
          }
          
          var c2Pos = classnameStr.indexOf("FormularzInputyAktywne")
          if (c2Pos != 0) {
                classnameStr.substr(c2Pos, 22);
          }
          
          var c3Pos = classnameStr.indexOf("FormularzInputyBlad")
          if (c3Pos != 0) {
                classnameStr.substr(c2Pos, 19);
          }
         
         field.className = classnameStr + " FormularzInputyBgr FormularzInputyBlad";
         SetValidIcon(field.id, 3);
       }else
       {
          RequiredOnChange(field);
       }
    }

    function OnInputChange(field) {
        SetValidIcon(field.id, 2);
    }

    function RequiredOnKeyDown(evt, field) {
        var TAB = 9;
        var keyCode = GetKeyCode(evt);
        var classname = RemoveInputFieldLayoutStyles(field);
        if (field.value == "" && keyCode == TAB) {
            field.className = classname + "FormularzInputyBgr FormularzInputyBlad";
            SetValidIcon(field.id, 3);
        } else {
            if (keyCode == TAB) {
                field.className = classname + " FormularzInputyBgr";
                SetValidIcon(field.id, 2);
            } else {
                field.className = classname + " FormularzInputyBgr FormularzInputyAktywne";
                SetValidIcon(field.id, 1);
            }
        }
    }

    function RequiredOnKeyUp(evt, field) {
        var TAB = 9;
        var keyCode = GetKeyCode(evt);
        var classname = RemoveInputFieldLayoutStyles(field);

        if (field.value == "" && keyCode != TAB) {
            field.className = classname + "FormularzInputyBgr FormularzInputyBlad";
            SetValidIcon(field.id, 3);
        } else {
            field.className = classname + " FormularzInputyBgr FormularzInputyAktywne";
            SetValidIcon(field.id, 1);
        }
    }
    
    function CheckIfSpecificLenght(field, length)
    {
        var retVal = false;
        
        if(field.value.length != length)
       {
          var classnameStr = field.className;
          var c1Pos = classnameStr.indexOf("FormularzInputyBgr")
          if (c1Pos != 0) {
                classnameStr.substr(c1Pos, 18);
          }
          
          var c2Pos = classnameStr.indexOf("FormularzInputyAktywne")
          if (c2Pos != 0) {
                classnameStr.substr(c2Pos, 22);
          }
          
          var c3Pos = classnameStr.indexOf("FormularzInputyBlad")
          if (c3Pos != 0) {
                classnameStr.substr(c2Pos, 19);
          }
         
         field.className = classnameStr + " FormularzInputyBgr FormularzInputyBlad";
         SetValidIcon(field.id, 3);
         
         retVal = false;
       }else
       {
          retVal = true;
       }
       
       return retVal;
    }

    function CheckIfFieldIsNotEmpty(field) {
        var classname = RemoveInputFieldLayoutStyles(field);

        if (field.value == "") {
            field.className = classname + "FormularzInputyBgr FormularzInputyBlad";
            SetValidIcon(field.id, 3);
            return false;
        } else {
            field.className = classname + " FormularzInputyBgr";
            SetValidIcon(field.id, 2);
            return true;
        }
    }

    function CheckIfSelectIsNotEmpty(select) {
        var selIdx = select.selectedIndex;
        var selValue = select.options[selIdx].value;
        var classname = RemoveInputFieldLayoutStyles(select);
            
        if ((select.length > 1) && (selValue == "")) {
            select.className = "FormularzInputyBgr FormularzInputyBlad";
            SetValidIcon(select.id, 3);
            return false;
        } else {
            select.className = "FormularzInputyBgr";
            SetValidIcon(select.id, 2);
            return true;
        }
    }

    function CheckIfRegionIsNotEmpty(select, countryStr) {
        var tmpFieldName = GetClientId(countryStr);
        var country = document.getElementById(tmpFieldName);

        var selIdx = select.selectedIndex;
        var selValue = select.options[selIdx].value;
        var classname = RemoveInputFieldLayoutStyles(select);
        
        if (country.selectedIndex != 'PL') {
            select.className = "FormularzInputyBgr";
            SetValidIcon(select.id, 2);
            return true;
        } else {
            if (selValue == "") {
                select.className = "FormularzInputyBgr FormularzInputyBlad";
                SetValidIcon(select.id, 3);
                return false;
            } else {
                select.className = "FormularzInputyBgr";
                SetValidIcon(select.id, 2);
                return true;
            }
        }
    }
    

    function SubmitAddAdvert() {
        var validform = true;
        
        var changePassLayer = document.getElementById('divChangePassword');
        
        if(changePassLayer.style.display != 'inline')
        {
        
        if (requiredInputs.length > 0) {
            for (i = 0; i < requiredInputs.length; i++) {
                var elementName = requiredInputs[i];
                var tmpFieldName = GetClientId(elementName);
                var element = document.getElementById(tmpFieldName);
                if (!CheckIfFieldIsNotEmpty(element)) {
                    //element.focus();
                    validform = false;
                }
            }
        }
        
        if(requiredValids.length > 0)
        {
           for (i = 0; i < requiredValids.length; i++) {
              var elementName = requiredValids[i];
              var tmpFieldName = GetClientId(elementName);
              var element = document.getElementById(tmpFieldName);
               if (! CheckIfSpecificLenght(element, 4)) {
                  validform = false;
               }
           }
        }

        if (requiredSelects.length > 0) {
            for (i = 0; i < requiredSelects.length; i++) {
                var elementName = requiredSelects[i];

                var tmpFieldName = GetClientId(elementName);
                var element = document.getElementById(tmpFieldName);
                var selCountry = document.getElementById(GetClientId("advert_Country"));
                if (elementName == "advert_Region" && selCountry.value != 'PL') {
                } else {
                    if (!CheckIfSelectIsNotEmpty(element)) {
                        validform = false;
                    }
                }
            }
        }
        


        var pgArray = $('#ulPhotoGallery').sortable('toArray');
        var resultsFn = new Array();
        var resultsTitleFn = new Array();
        var idx = 0;
        for (fname in pgArray) {
            var imgCtx = $('#' + pgArray[fname]).attr('imgId');
            myFn = $('#' + imgCtx).attr('src');
            resultsFn[idx] = $('#' + imgCtx).attr('src');
            resultsTitleFn[idx] = $('#' + imgCtx).attr('title');
            idx++;
        }
        $('#galleryImages').val(resultsFn.toString());
        $('#galleryTitles').val(resultsTitleFn.toString());
        
        }
        
        var tmpFieldName = GetClientId("divErrorAlert");
        errorDiv = document.getElementById(tmpFieldName);
        if (validform) {
            errorDiv.style.display = 'none';
            return true;
        } else {
            anchor = document.getElementById("advertAnch");          
            errorDiv.style.display = 'block';
            var hr = RemoveSubStringfromString(location.href, "#advertAnch");
            location.href = hr + '#advertAnch';
            return false;
        }
    }


    function ShowTab(tabNr) {
        
        var divContactTab = GetClientId("divContactTab")
        if(divContactTab != null && divContactTab != '')
        {    
        var divContactTab = document.getElementById(divContactTab);
        if (!loggedUser && (divContactTab != null)) {
            removeFocusOnAll();
            for (var i = 1; i <= 3; i++) {
                var showTab = document.getElementById("divTab" + i);
                var leftarrow = document.getElementById("LeftArrowTab" + i);
                var middle = document.getElementById("MiddleTab" + i);
                var rightarrow = document.getElementById("RightArrowTab" + i);
                var tabHref = document.getElementById("HrefTab" + i);
                var helpTab = document.getElementById("Tab" + i + "Help");
                            
                if (i == tabNr) {
                    showTab.className = "GlobalFloatLeft KontaktZakladka";
                    leftarrow.className = "GlobalFloatLeft GrafikiStrony KontaktZakladkiElement ZaznaczonaLewa";
                    middle.className = "GlobalFloatLeft KontaktZakladkiElement ZaznaczonaTlo";
                    rightarrow.className = "GlobalFloatLeft GrafikiStrony KontaktZakladkiElement ZaznaczonaPrawa";
                    tabHref.className = "ZakladkiTytulZaznaczone";
                    helpTab.style.display = 'block';

                } else {
                    showTab.className = "GlobalFloatLeft KontaktZakladka Niezaznaczona";
                    leftarrow.className = "GlobalFloatLeft GrafikiStrony KontaktZakladkiElement Lewa";
                    middle.className = "GlobalFloatLeft KontaktZakladkiElement Tlo";
                    rightarrow.className = "GlobalFloatLeft GrafikiStrony KontaktZakladkiElement Prawa";
                    tabHref.className = "ZakladkiTytul";
                    helpTab.style.display = 'none';
                }
            }

            var bodyTab2 = document.getElementById("BodyTab2");
            var bodyTab3 = document.getElementById("BodyTab3");          

            var divFirstPhone = document.getElementById(GetClientId("ContactDataStandardUser1_divPhoneFirst"));
            if (tabNr == 2) {
                bodyTab2.style.display = 'block';
                bodyTab3.style.display = 'none';
                if(divFirstPhone != null)
                {
                   divFirstPhone.style.display = "block";
                }
            } else {
                bodyTab2.style.display = 'none';
                bodyTab3.style.display = 'block';
                
                var tmpFieldPassword = GetClientId('ContactDataStandardUser1_divPassword');
                var inputPass = document.getElementById(tmpFieldPassword);
                var tmpFieldConfirmPassword = GetClientId('ContactDataStandardUser1_divConfirmPassword');
                var inputContPass = document.getElementById(tmpFieldConfirmPassword);
                var tmpFieldPhoneNumber = GetClientId('ContactDataStandardUser1_divPhoneNumber');
                var inputPhone = document.getElementById(tmpFieldPhoneNumber);

                if (tabNr == 1) {

                    inputPass.style.display = 'none';
                    inputContPass.style.display = 'none';
                    inputPhone.style.display = 'block';
                    if(divFirstPhone != null)
                    {
                     divFirstPhone.style.display = "none";
                    }
                } else {
                    inputPass.style.display = 'block';
                    inputContPass.style.display = 'block';
                    inputPhone.style.display = 'none';
                   if(divFirstPhone != null)
                   {
                     divFirstPhone.style.display = "block";
                   }
                }
            }

            var tmpFieldName = GetClientId("contactType");
            var contactType = document.getElementById(tmpFieldName);
            contactType.value = tabNr;
        }
        }
        
    }
    
    function ShowDialogLayer(layerName) {
        //ClearSendMailForm();
        var fView = document.getElementById(layerName);
        ShowLayer();
        ShowObjectAtStandardPosition(fView, "dialog-window-center");
    }

    function CloseDialogLayer(layerName) {
        var fView = document.getElementById(layerName);
        fView.style.display = "none";
        HideLayer();
    }
    
    
    function ValidNip(fieldname)
    {
       var tmpFieldName = GetClientId(fieldname);
       var field = document.getElementById(tmpFieldName);
       
       var countryfield = GetClientId("ddlUserCountrySelector");
       var select = document.getElementById(countryfield );
        var selIdx = select.selectedIndex;
        var selValue = select.options[selIdx].value;
         if (selValue == "PL")
         {
           if (field.value == "")
           {
             field.className = "FormularzInputyBgr FormularzInputyBlad";
             SetValidIcon(fieldname, 3);
           }else
           {
             if(isNIP(field.value))
             {
                var classnameStr = field.className;
                var c1Pos = classnameStr.indexOf("FormularzInputyBgr")
                if (c1Pos != 0) {
                   classnameStr.substr(c1Pos, 18);
                }

                var c2Pos = classnameStr.indexOf("FormularzInputyAktywne")
                if (c2Pos != 0) {
                   classnameStr.substr(c2Pos, 22);
                }
                
                field.className = " FormularzInputyBgr";
                SetValidIcon(fieldname, 2);
             }else
             {
                field.className = "FormularzInputyBgr FormularzInputyBlad";
                SetValidIcon(fieldname, 3);
             }
           }        
         }else
         {
            RequiredStaticOnChange(fieldname);
         }   
    }
    
    function isNIP(value)
    {
      var retVal = false;
   	  var rexpstr = "^[0-9-]{1,25}$";
	  var re = new RegExp(rexpstr);
      var matchar = value.match(re);
	  if (matchar){
	     retVal = true;
	  }
      return retVal;
    }
    
    function RequiredStaticOnChange(fieldname) {
        var tmpFieldName = GetClientId(fieldname);
        var field = document.getElementById(tmpFieldName);
        if (field.value == "") {
            field.className = "FormularzInputyBgr FormularzInputyBlad";
            SetValidIcon(fieldname, 3);
        } else {

            var classnameStr = field.className;
            var c1Pos = classnameStr.indexOf("FormularzInputyBgr")
            if (c1Pos != 0) {
                classnameStr.substr(c1Pos, 18);
            }

            var c2Pos = classnameStr.indexOf("FormularzInputyAktywne")
            if (c2Pos != 0) {
                classnameStr.substr(c2Pos, 22);
            }
            field.className = " FormularzInputyBgr";
            SetValidIcon(fieldname, 2);
        }
    }

    function CheckIfStaticFieldIsNotEmpty(field) {
        var tmpFieldName = GetClientId(field);
        var element = document.getElementById(tmpFieldName);
        var classname = RemoveInputFieldLayoutStyles(element);
        if (element.value == "") {
            element.className = classname + "FormularzInputyBgr FormularzInputyBlad";
            SetValidIcon(field, 3);
            return false;
        } else {
            element.className = classname + " FormularzInputyBgr";
            SetValidIcon(field, 2);
            return true;
        }
    }

    var mobilePrefixes = ["601", "603", "605", "607", "609", "691", "693", "695", "697", "661", "663", "665", "667", 
               "722", "723", "724", "725", "726", "7274", "7275", "7276", "7277", "7278", "7279", "781", "782", "783", 
               "785", "885", "887", "600", "602", "604", "606", "608", "692", "694", "696", "698", "660", "662", "664", 
               "6661", "6662", "6663", "6664", "6665", "6667", "6668", "6669", "6660", "668", "7272", "7273", "7281", 
               "7282", "7283", "7284", "7285", "7286", "7287", "7288", "7289", "784", "787", "788", "7951", "7952", 
               "7953", "7954", "7955", "8818", "882", "8833", "8838", "8841", "8842", "886", "888", "889", "880",
               "501", "502", "503", "504", "505", "506", "507", "508", "509", "500", "510", "511", "512", "513", 
               "514", "515", "516", "517", "518", "519", "7891", "7892", "7893", "7894", "7890", "7865", "7866", 
               "7867", "7868", "7869", "780", "797", "798", "7997", "7998", "7999", "7990", "6901", "6902", "6903", 
               "6904", "6905", "6906", "6666", "531", "533", "535", "530", "791", "792", "793", "794", "7956", "7957",
               "7958", "7959", "7950 796 790", "8831", "8832", "8834", "8835", "8836", "8837", "8839", "8830",
               "7861", "7862", "7863", "7864", "7860", "7271", "7280", "7201", "7202", "7203", "7204", "7205", 
               "7206", "7207", "7209", "7200", "8811", "8844", "8845", "669", "721"];
               
               
               
                   function removeFocusOnAll() {
        var felemens = getFocusableElementsIds();
        for (var i = 0; i < felemens.length; i++) {
            removeFocusOnElem(felemens[i]);
        }
    }
    
    function setFocusOnInput(inputobj) {
        //FormularzInputyAktywne
        if (inputobj) {
            var simpleelementId = addFocusableElementId(inputobj.id);
            
            removeFocusOnAll();
            inputobj.className += " FormularzInputyAktywne";
            var tmpFieldName = GetClientId(simpleelementId + "Ico");
            var icoelem = document.getElementById(tmpFieldName);
            if (simpleelementId && (simpleelementId.length > 0)) {
                removeIcoSign(icoelem);
                
                
                var infoelem = document.getElementById(simpleelementId + "Info");
                var infoelemend = document.getElementById(simpleelementId + "InfoEnd");
                if (infoelem) {
                    infoelem.style.display = "block";
                    if (infoelemend) {
                        infoelemend.style.display = "block";
                    }
                }
            }
        }
    }
    
    function validdata(inputobj)
    {
        
        var simpleelementId = addBlurValidableElementId(inputobj.id);
        
        var elemIcoName = GetClientId(simpleelementId + "Ico");
        var icoelem = document.getElementById(elemIcoName);
        if (icoelem)
        {
        
            removeIcoSign(icoelem);
            var cssclassname = icoelem.className;
            cssclassname += " FormularzPoprawnieIco";
            icoelem.className = cssclassname;
            if (inputobj)
            {
                var cssclassname = inputobj.className;
                //cssclassname = cssclassname.replace(" FormularzInputyBlad ","")
                //cssclassname = cssclassname.replace(" FormularzInputyBlad","")
                cssclassname = cssclassname.replace("FormularzInputyBlad","")
                inputobj.className = cssclassname;
            }
        }
        //FormularzPoprawnieIco
                

    }
    
    function invaliddata(inputobj)
    {
        var simpleelementId = addBlurValidableElementId(inputobj.id);
        var elemIco = GetClientId(simpleelementId + "Ico");
        var icoelem = document.getElementById(elemIco);
        if (icoelem)
        {
            removeIcoSign(icoelem);
            var cssclassname = icoelem.className;
            cssclassname += " FormularzBladIco";
            icoelem.className = cssclassname;
            if (inputobj)
            {
                var cssclassname = inputobj.className;
                cssclassname = cssclassname.replace(" FormularzInputyAktywne ","")
                cssclassname = cssclassname.replace(" FormularzInputyAktywne","")
                cssclassname = cssclassname.replace("FormularzInputyAktywne","")
                cssclassname = cssclassname.replace("FormularzInputyBlad","")
                cssclassname += " FormularzInputyBlad";
                inputobj.className = cssclassname;
            }
        }
        //FormularzBladIco
    }
    
    function invaliddatawithhelp(inputobj)
    {
        var simpleelementId = addBlurValidableElementId(inputobj.id);
        var tmpFieldName = GetClientId(simpleelementId + "Ico");
        var icoelem = document.getElementById(tmpFieldName);
        if (icoelem)
        {
            removeIcoSign(icoelem);
            var cssclassname = icoelem.className;
            cssclassname += " FormularzBladIco";
            icoelem.className = cssclassname;
            if (inputobj)
            {
                var cssclassname = inputobj.className;
                cssclassname = cssclassname.replace(" FormularzInputyAktywne ","")
                cssclassname = cssclassname.replace(" FormularzInputyAktywne","")
                cssclassname = cssclassname.replace("FormularzInputyAktywne","")
                cssclassname = cssclassname.replace("FormularzInputyBlad","")
                cssclassname += " FormularzInputyBlad";
                inputobj.className = cssclassname;
                
               /* var infoelem = document.getElementById(simpleelementId + "Info");
                var infoelemend = document.getElementById(simpleelementId + "InfoEnd");
                if (infoelem) {
                    infoelem.style.display = "block";
                    if (infoelemend) {
                        infoelemend.style.display = "block";
                    }
                }*/
            }
        }
        //FormularzBladIco
    }
    
    function validdatawithhelp(inputobj)
    {
        
        var simpleelementId = addBlurValidableElementId(inputobj.id);
        
        var tmpFieldNameIco = GetClientId(simpleelementId + "Ico");
        var icoelem = document.getElementById(tmpFieldNameIco);
        if (icoelem)
        {
        
            removeIcoSign(icoelem);
            var cssclassname = icoelem.className;
            cssclassname += " FormularzPoprawnieIco";
            icoelem.className = cssclassname;
            if (inputobj)
            {
                var cssclassname = inputobj.className;
                //cssclassname = cssclassname.replace(" FormularzInputyBlad ","")
                //cssclassname = cssclassname.replace(" FormularzInputyBlad","")
                cssclassname = cssclassname.replace("FormularzInputyBlad","")
                inputobj.className = cssclassname;
                
                var infoelem = document.getElementById(simpleelementId + "Info");
                var infoelemend = document.getElementById(simpleelementId + "InfoEnd");
                if (infoelem) {
                    infoelem.style.display = "none";
                    if (infoelemend) {
                        infoelemend.style.display = "none";
                    }
                }
            }
        }
        //FormularzPoprawnieIco
                

    }
    
    
    
    function invaliddatawithouticon(inputobj)
    {
        var simpleelementId = addBlurValidableElementId(inputobj.id);
        if (inputobj)
        {
            var cssclassname = inputobj.className;
            cssclassname = cssclassname.replace(" FormularzInputyAktywne ","")
            cssclassname = cssclassname.replace(" FormularzInputyAktywne","")
            cssclassname = cssclassname.replace("FormularzInputyAktywne","")
            cssclassname = cssclassname.replace("FormularzInputyBlad","")
            cssclassname += " FormularzInputyBlad";
            inputobj.className = cssclassname;
        }     
    }
    
    function validdatawithouticon(inputobj)
    {        
        var simpleelementId = addBlurValidableElementId(inputobj.id);       
        if (inputobj)
        {
            var cssclassname = inputobj.className;
            //cssclassname = cssclassname.replace(" FormularzInputyBlad ","")
            //cssclassname = cssclassname.replace(" FormularzInputyBlad","")
            cssclassname = cssclassname.replace("FormularzInputyBlad","")
            inputobj.className = cssclassname;
        }               
    }
    
    function ValidatePasswordOnBlur(inputobj, validateschema, validfunction, notvalidfunction, secondPasswordName)
    {
        if (inputobj)
        {
            removeFocusOnAll();
            if (validateschema)
            {
                if (validateValueBySchema(inputobj.value,validateschema))
                {
                    var firstPassValue = inputobj.value;
                    var tmpFieldNamePass = GetClientId(secondPasswordName);
                    var secondPassValue = document.getElementById(tmpFieldNamePass).value    
                    if(PasswordCompare(firstPassValue, secondPassValue))
                    {
                      validfunction(inputobj);
                    }else
                    {
                       notvalidfunction(inputobj);
                    }
                }
                else
                {
                    notvalidfunction(inputobj);
                }
            }
        }
    }
    
    function PasswordCompare(firstPassValue, secondPassValue)
    {
      var retVal = false;
      if(secondPassValue == '' || firstPassValue == secondPassValue)
      {
        retVal = true;
      }
      
      return retVal;
    }
    
    function validateOnBlur(inputobj, validateschema, validfunction, notvalidfunction)
    {
        if (inputobj)
        {
            removeFocusOnAll();
            if (validateschema)
            {
                if (validateValueBySchema(inputobj.value,validateschema))
                {
                    validfunction(inputobj);
                }
                else
                {
                    notvalidfunction(inputobj);
                }
            }
        }
    }
    
        function removeFocusOnElem(elem)
    {
        var mainelem = document.getElementById(elem[0]);
        var infoelem = document.getElementById(elem[1] + "Info");
        var infoelemend = document.getElementById(elem[1] + "InfoEnd");
        var icoelem = document.getElementById(elem[1] + "Ico");
        if (mainelem) {
            var currentClassName = " " + mainelem.className + " ";
            if (currentClassName.indexOf(" FormularzInputyAktywne ") > 0) {
                currentClassName = currentClassName.replace(" FormularzInputyAktywne ", " ");
                while (currentClassName.indexOf(" ") == 0) {
                    currentClassName = currentClassName.substr(1, currentClassName.length - 1);
                }
                while (currentClassName.lastIndexOf(" ") == (currentClassName.length - 1)) {
                    currentClassName = currentClassName.substr(0, currentClassName.length - 1)
                }
                mainelem.className = currentClassName;
            }
        }
        if (infoelem) {
            infoelem.style.display = "none";
        }

        if (infoelemend) {
            infoelemend.style.display = "none";
        }
        //removeIcoSign(icoelem);   
    }
    
    function removeIcoSign(icoelem)
    {
        if (icoelem)
        {
            var cssclassname = icoelem.className;
            cssclassname = cssclassname.replace(" FormularzPoprawnieIco ","");
            cssclassname = cssclassname.replace(" FormularzBladIco ","");
            cssclassname = cssclassname.replace(" FormularzPoprawnieIco","");
            cssclassname = cssclassname.replace(" FormularzBladIco","");
            cssclassname = cssclassname.replace("FormularzPoprawnieIco ","");
            cssclassname = cssclassname.replace("FormularzBladIco ","");
            icoelem.className = cssclassname;
        }    
    }
    
    
        function getBlurValidableElementsIds(){
        return blurvalidableelements;
    }
    
    function addBlurValidableElementId(elementid) {
        var simpeelementId = ""
        var blurvalidableelementsdef = "tbxChangeEmail|tbEmail|tbPassword|tbPasswordConfirm|tbName|tbZipCode|tbCity|tbAddress|tbPhone2|tbAfterPhone2|tbPhone3|tbAfterPhone3|tbFax|tbAfterFax|tbMessengerId|tbWebPage|tbLoginPhone|tbLoginEmail|tbLoginPassword|lgnId|lgnPa|tbxPassword|tbxConfirmPassword|CountrySelector|tbPhone";
        var elementexistsinlist = false;
        for (var i = 0; i < blurvalidableelements.length; i++) {
            if (blurvalidableelements[i] == elementid) elementexistsinlist = true;
        }
        if (!elementexistsinlist) {
            var cannaddelement = false;
            allowedBlurValidableElements = blurvalidableelementsdef.split("|");
            var simpeelementId = "";
            for (var i = 0; i < allowedBlurValidableElements.length; i++) {
                if (elementid.toString().indexOf(allowedBlurValidableElements[i]) > 0) {
                    cannaddelement = true;
                    simpeelementId = allowedBlurValidableElements[i];
                }
            }
            if (cannaddelement) {
                blurvalidableelements[focusableElements.length] = new Array(elementid, simpeelementId);
            }
        }
        return simpeelementId;
    }

    function getFocusableElementsIds() {
        return focusableElements;
    }

    function addFocusableElementId(elementid) {
        var simpeelementId = "";
        var focusableelementsdef = "tbxChangeEmail|tbEmail|tbPassword|tbPasswordConfirm|tbName|tbZipCode|tbCity|tbAddress|PhoneThird_tbPhone|PhoneThird_tbAfterPhone|PhoneSecond_tbPhone|PhoneSecond_tbAfterPhone|PhoneFirst_tbAfterPhone|PhoneFirst_tbPhone|tbFax|tbAfterFax|tbMessengerId|tbWebPage|tbLoginPhone|tbLoginEmail|tbLoginPassword|lgnId|lgnPa|tbxPassword|tbxConfirmPassword|CountrySelector|tbPhone";
        var elementexistsinlist = false;
        for (var i = 0; i < focusableElements.length; i++) {
            if (focusableElements[i] == elementid) elementexistsinlist = true;
        }
        if (!elementexistsinlist) {
            var cannaddelement = false;
            allowedFocusElements = focusableelementsdef.split("|");
            var simpeelementId = "";
            for (var i = 0; i < allowedFocusElements.length; i++) {
                if (elementid.toString().indexOf(allowedFocusElements[i]) > 0) {
                    cannaddelement = true;
                    simpeelementId = allowedFocusElements[i];
                }
            }
            if (cannaddelement) {
                focusableElements[focusableElements.length] = new Array(elementid, simpeelementId);
            }
        }
        return simpeelementId;
    }
    
    function RemoveFocus(field) {
        field.className = "FormularzInputyBgr";
    }
    
    function invalidselectdata(inputobj, iconame)
    {
        var simpleelementId = addBlurValidableElementId(inputobj.id);
        var elemIco = GetClientId(simpleelementId + iconame);
        var icoelem = document.getElementById(elemIco);
        if (icoelem)
        {
            removeIcoSign(icoelem);
            var cssclassname = icoelem.className;
            cssclassname += " FormularzBladIco";
            icoelem.className = cssclassname;
            if (inputobj)
            {
                var cssclassname = inputobj.className;
                cssclassname = cssclassname.replace(" FormularzInputyAktywne ","")
                cssclassname = cssclassname.replace(" FormularzInputyAktywne","")
                cssclassname = cssclassname.replace("FormularzInputyAktywne","")
                cssclassname = cssclassname.replace("FormularzInputyBlad","")
                cssclassname += " FormularzInputyBlad";
                inputobj.className = cssclassname;
            }
        }
        //FormularzBladIco
    }

    function setStaticContentPathTitle(title) {
        setTimeout("setStaticContentPathTitleInternal('" + title + "')", 100);
    }
    
    function setStaticContentPathTitleInternal(title) {
        document.getElementById("static_action_title").innerHTML = title;
    }
    
    function JSLink(part1, part2){
	window.open(part1+part2, '');
}

    function CheckField(fieldName, returnValue) {
        if (!CheckIfStaticFieldIsNotEmpty(fieldName)) {
            returnValue = false;
        }

        return returnValue;
    }

    function CheckIfStaticSelectIsNotEmpty(selectName) {
        var tmpSelectNameFieldName = GetClientId(selectName);
        var select = document.getElementById(tmpSelectNameFieldName);
        var selIdx = select.selectedIndex;
        var selValue = select.options[selIdx].value;
        var classname = RemoveInputFieldLayoutStyles(select);

        if (selValue == "") {
            select.className = "FormularzInputyBgr FormularzInputyBlad";
            SetValidIcon(selectName, 3);
            return false;
        } else {
            select.className = "FormularzInputyBgr";
            SetValidIcon(selectName, 2);
            return true;
        }
    }
    
   function ShowHiddenBlock(blockId) {
            var errorLayer = document.getElementById(blockId);
            errorLayer.style.display = "block";
        }
        
        function urlEncodeChar(c){
	var retVal = c;
	var encchars = String.fromCharCode(32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,58,59);
	encchars += String.fromCharCode(60,61,62,63,64,91,92,93,94,95,96,123,124,125,126,127,8364);
	encchars += String.fromCharCode(129,8218,131,8222,8230,8224,8225,136,8240,352,8249,346,356);
	encchars += String.fromCharCode(381,377,144,8216,8217,8220,8221,8226,8211,8212,152,8482,353);
	encchars += String.fromCharCode(8250,347,357,382,378,32,711,728,321,164,260,166,167,168,169);
	encchars += String.fromCharCode(350,171,172,173,174,379,176,177,731,322,180,181,182,183,184);
	encchars += String.fromCharCode(261,351,187,317,733,318,380,340,193,194,258,196,313,262,199);
	encchars += String.fromCharCode(268,201,280,203,282,205,206,270,272,323,327,211,212,336);
	encchars += String.fromCharCode(214215,344,366,218,368,220,221,354,223,341,225,226,259,228);
	encchars += String.fromCharCode(314,263,231,269,233,281,235,283,237,238,271,273,324,328,243);
	encchars += String.fromCharCode(244,337,246,247,345,367,250,369,252,253,355,729);
	var encarray = new Array(
		new Array(String.fromCharCode(32),"+"),
		new Array(String.fromCharCode(33),String.fromCharCode(37)+"21"),
		new Array(String.fromCharCode(92),String.fromCharCode(37)+"22"),
		new Array(String.fromCharCode(35),String.fromCharCode(37)+"23"),
		new Array(String.fromCharCode(36),String.fromCharCode(37)+"24"),
		new Array(String.fromCharCode(37),String.fromCharCode(37)+"25"),
		new Array(String.fromCharCode(38),String.fromCharCode(37)+"26"),
		new Array(String.fromCharCode(39),String.fromCharCode(37)+"27"),
		new Array(String.fromCharCode(40),String.fromCharCode(37)+"28"),
		new Array(String.fromCharCode(41),String.fromCharCode(37)+"29"),
		new Array(String.fromCharCode(42),String.fromCharCode(37)+"2A"),
		new Array(String.fromCharCode(43),String.fromCharCode(37)+"2B"),
		new Array(String.fromCharCode(34),String.fromCharCode(37)+"2C"),
		new Array(String.fromCharCode(45),String.fromCharCode(37)+"2D"),
		new Array(String.fromCharCode(46),String.fromCharCode(37)+"2E"),
		new Array(String.fromCharCode(47),String.fromCharCode(37)+"2F"),
		new Array(String.fromCharCode(58),String.fromCharCode(37)+"3A"),
		new Array(String.fromCharCode(59),String.fromCharCode(37)+"3B"),
		new Array(String.fromCharCode(60),String.fromCharCode(37)+"3C"),
		new Array(String.fromCharCode(61),String.fromCharCode(37)+"3D"),
		new Array(String.fromCharCode(62),String.fromCharCode(37)+"3E"),
		new Array(String.fromCharCode(63),String.fromCharCode(37)+"3F"),
		new Array(String.fromCharCode(64),String.fromCharCode(37)+"40"),
		new Array(String.fromCharCode(91),String.fromCharCode(37)+"5B"),
		new Array(String.fromCharCode(92),String.fromCharCode(37)+"5C"),
		new Array(String.fromCharCode(93),String.fromCharCode(37)+"5D"),
		new Array(String.fromCharCode(94),String.fromCharCode(37)+"5E"),
		new Array(String.fromCharCode(95),String.fromCharCode(37)+"5F"),
		new Array(String.fromCharCode(96),String.fromCharCode(37)+"60"),
		new Array(String.fromCharCode(123),String.fromCharCode(37)+"7B"),
		new Array(String.fromCharCode(44),String.fromCharCode(37)+"7C"),
		new Array(String.fromCharCode(125),String.fromCharCode(37)+"7D"),
		new Array(String.fromCharCode(126),String.fromCharCode(37)+"7E"),
		new Array(String.fromCharCode(127),String.fromCharCode(37)+"7F"),
		new Array(String.fromCharCode(8364),String.fromCharCode(37)+"80"),
		new Array(String.fromCharCode(129),String.fromCharCode(37)+"81"),
		new Array(String.fromCharCode(8218),String.fromCharCode(37)+"82"),
		new Array(String.fromCharCode(131),String.fromCharCode(37)+"83"),
		new Array(String.fromCharCode(8222),String.fromCharCode(37)+"84"),
		new Array(String.fromCharCode(8230),String.fromCharCode(37)+"85"),
		new Array(String.fromCharCode(8224),String.fromCharCode(37)+"86"),
		new Array(String.fromCharCode(8225),String.fromCharCode(37)+"87"),
		new Array(String.fromCharCode(136),String.fromCharCode(37)+"88"),
		new Array(String.fromCharCode(8240),String.fromCharCode(37)+"89"),
		new Array(String.fromCharCode(352),String.fromCharCode(37)+"8A"),
		new Array(String.fromCharCode(8249),String.fromCharCode(37)+"8B"),
		new Array(String.fromCharCode(346),String.fromCharCode(37)+"8C"),
		new Array(String.fromCharCode(356),String.fromCharCode(37)+"8D"),
		new Array(String.fromCharCode(381),String.fromCharCode(37)+"8E"),
		new Array(String.fromCharCode(377),String.fromCharCode(37)+"8F"),
		new Array(String.fromCharCode(144),String.fromCharCode(37)+"90"),
		new Array(String.fromCharCode(8216),String.fromCharCode(37)+"91"),
		new Array(String.fromCharCode(8217),String.fromCharCode(37)+"92"),
		new Array(String.fromCharCode(8220),String.fromCharCode(37)+"93"),
		new Array(String.fromCharCode(8221),String.fromCharCode(37)+"94"),
		new Array(String.fromCharCode(8226),String.fromCharCode(37)+"95"),
		new Array(String.fromCharCode(8211),String.fromCharCode(37)+"96"),
		new Array(String.fromCharCode(8212),String.fromCharCode(37)+"97"),
		new Array(String.fromCharCode(152),String.fromCharCode(37)+"98"),
		new Array(String.fromCharCode(8482),String.fromCharCode(37)+"99"),
		new Array(String.fromCharCode(353),String.fromCharCode(37)+"9A"),
		new Array(String.fromCharCode(8250),String.fromCharCode(37)+"9B"),
		new Array(String.fromCharCode(347),String.fromCharCode(37)+"9C"),
		new Array(String.fromCharCode(357),String.fromCharCode(37)+"9D"),
		new Array(String.fromCharCode(382),String.fromCharCode(37)+"9E"),
		new Array(String.fromCharCode(378),String.fromCharCode(37)+"9F"),
		new Array(String.fromCharCode(32),String.fromCharCode(37)+"A0"),
		new Array(String.fromCharCode(711),String.fromCharCode(37)+"A1"),
		new Array(String.fromCharCode(728),String.fromCharCode(37)+"A2"),
		new Array(String.fromCharCode(321),String.fromCharCode(37)+"A3"),
		new Array(String.fromCharCode(164),String.fromCharCode(37)+"A4"),
		new Array(String.fromCharCode(260),String.fromCharCode(37)+"A5"),
		new Array(String.fromCharCode(166),String.fromCharCode(37)+"A6"),
		new Array(String.fromCharCode(167),String.fromCharCode(37)+"A7"),
		new Array(String.fromCharCode(168),String.fromCharCode(37)+"A8"),
		new Array(String.fromCharCode(169),String.fromCharCode(37)+"A9"),
		new Array(String.fromCharCode(350),String.fromCharCode(37)+"AA"),
		new Array(String.fromCharCode(171),String.fromCharCode(37)+"AB"),
		new Array(String.fromCharCode(172),String.fromCharCode(37)+"AC"),
		new Array(String.fromCharCode(173),String.fromCharCode(37)+"AD"),
		new Array(String.fromCharCode(174),String.fromCharCode(37)+"AE"),
		new Array(String.fromCharCode(379),String.fromCharCode(37)+"AF"),
		new Array(String.fromCharCode(176),String.fromCharCode(37)+"B0"),
		new Array(String.fromCharCode(177),String.fromCharCode(37)+"B1"),
		new Array(String.fromCharCode(731),String.fromCharCode(37)+"B2"),
		new Array(String.fromCharCode(322),String.fromCharCode(37)+"B3"),
		new Array(String.fromCharCode(180),String.fromCharCode(37)+"B4"),
		new Array(String.fromCharCode(181),String.fromCharCode(37)+"B5"),
		new Array(String.fromCharCode(182),String.fromCharCode(37)+"B6"),
		new Array(String.fromCharCode(183),String.fromCharCode(37)+"B7"),
		new Array(String.fromCharCode(184),String.fromCharCode(37)+"B8"),
		new Array(String.fromCharCode(261),String.fromCharCode(37)+"B9"),
		new Array(String.fromCharCode(351),String.fromCharCode(37)+"BA"),
		new Array(String.fromCharCode(187),String.fromCharCode(37)+"BB"),
		new Array(String.fromCharCode(317),String.fromCharCode(37)+"BC"),
		new Array(String.fromCharCode(733),String.fromCharCode(37)+"BD"),
		new Array(String.fromCharCode(318),String.fromCharCode(37)+"BE"),
		new Array(String.fromCharCode(380),String.fromCharCode(37)+"BF"),
		new Array(String.fromCharCode(340),String.fromCharCode(37)+"C0"),
		new Array(String.fromCharCode(193),String.fromCharCode(37)+"C1"),
		new Array(String.fromCharCode(194),String.fromCharCode(37)+"C2"),
		new Array(String.fromCharCode(258),String.fromCharCode(37)+"C3"),
		new Array(String.fromCharCode(196),String.fromCharCode(37)+"C4"),
		new Array(String.fromCharCode(313),String.fromCharCode(37)+"C5"),
		new Array(String.fromCharCode(262),String.fromCharCode(37)+"C6"),
		new Array(String.fromCharCode(199),String.fromCharCode(37)+"C7"),
		new Array(String.fromCharCode(268),String.fromCharCode(37)+"C8"),
		new Array(String.fromCharCode(201),String.fromCharCode(37)+"C9"),
		new Array(String.fromCharCode(280),String.fromCharCode(37)+"CA"),
		new Array(String.fromCharCode(203),String.fromCharCode(37)+"CB"),
		new Array(String.fromCharCode(282),String.fromCharCode(37)+"CC"),
		new Array(String.fromCharCode(205),String.fromCharCode(37)+"CD"),
		new Array(String.fromCharCode(206),String.fromCharCode(37)+"CE"),
		new Array(String.fromCharCode(270),String.fromCharCode(37)+"CF"),
		new Array(String.fromCharCode(272),String.fromCharCode(37)+"D0"),
		new Array(String.fromCharCode(323),String.fromCharCode(37)+"D1"),
		new Array(String.fromCharCode(327),String.fromCharCode(37)+"D2"),
		new Array(String.fromCharCode(211),String.fromCharCode(37)+"D3"),
		new Array(String.fromCharCode(212),String.fromCharCode(37)+"D4"),
		new Array(String.fromCharCode(336),String.fromCharCode(37)+"D5"),
		new Array(String.fromCharCode(214),String.fromCharCode(37)+"D6"),
		new Array(String.fromCharCode(215),String.fromCharCode(37)+"D7"),
		new Array(String.fromCharCode(344),String.fromCharCode(37)+"D8"),
		new Array(String.fromCharCode(366),String.fromCharCode(37)+"D9"),
		new Array(String.fromCharCode(218),String.fromCharCode(37)+"DA"),
		new Array(String.fromCharCode(368),String.fromCharCode(37)+"DB"),
		new Array(String.fromCharCode(220),String.fromCharCode(37)+"DC"),
		new Array(String.fromCharCode(221),String.fromCharCode(37)+"DD"),
		new Array(String.fromCharCode(354),String.fromCharCode(37)+"DE"),
		new Array(String.fromCharCode(223),String.fromCharCode(37)+"DF"),
		new Array(String.fromCharCode(341),String.fromCharCode(37)+"E0"),
		new Array(String.fromCharCode(225),String.fromCharCode(37)+"E1"),
		new Array(String.fromCharCode(226),String.fromCharCode(37)+"E2"),
		new Array(String.fromCharCode(259),String.fromCharCode(37)+"E3"),
		new Array(String.fromCharCode(228),String.fromCharCode(37)+"E4"),
		new Array(String.fromCharCode(314),String.fromCharCode(37)+"E5"),
		new Array(String.fromCharCode(263),String.fromCharCode(37)+"E6"),
		new Array(String.fromCharCode(231),String.fromCharCode(37)+"E7"),
		new Array(String.fromCharCode(269),String.fromCharCode(37)+"E8"),
		new Array(String.fromCharCode(233),String.fromCharCode(37)+"E9"),
		new Array(String.fromCharCode(281),String.fromCharCode(37)+"EA"),
		new Array(String.fromCharCode(235),String.fromCharCode(37)+"EB"),
		new Array(String.fromCharCode(283),String.fromCharCode(37)+"EC"),
		new Array(String.fromCharCode(237),String.fromCharCode(37)+"ED"),
		new Array(String.fromCharCode(238),String.fromCharCode(37)+"EE"),
		new Array(String.fromCharCode(271),String.fromCharCode(37)+"EF"),
		new Array(String.fromCharCode(273),String.fromCharCode(37)+"F0"),
		new Array(String.fromCharCode(324),String.fromCharCode(37)+"F1"),
		new Array(String.fromCharCode(328),String.fromCharCode(37)+"F2"),
		new Array(String.fromCharCode(243),String.fromCharCode(37)+"F3"),
		new Array(String.fromCharCode(244),String.fromCharCode(37)+"F4"),
		new Array(String.fromCharCode(337),String.fromCharCode(37)+"F5"),
		new Array(String.fromCharCode(246),String.fromCharCode(37)+"F6"),
		new Array(String.fromCharCode(247),String.fromCharCode(37)+"F7"),
		new Array(String.fromCharCode(345),String.fromCharCode(37)+"F8"),
		new Array(String.fromCharCode(367),String.fromCharCode(37)+"F9"),
		new Array(String.fromCharCode(250),String.fromCharCode(37)+"FA"),
		new Array(String.fromCharCode(369),String.fromCharCode(37)+"FB"),
		new Array(String.fromCharCode(252),String.fromCharCode(37)+"FC"),
		new Array(String.fromCharCode(253),String.fromCharCode(37)+"FD"),
		new Array(String.fromCharCode(355),String.fromCharCode(37)+"FE"),
		new Array(String.fromCharCode(729),String.fromCharCode(37)+"FF")
	)
	if (encchars.indexOf(c)>0){
		for (i = 0; i < encarray.length; i++){
			carray = encarray[i];
			if (c==carray[0]) retVal = carray[1];
		}
	}
	return retVal;
}

function urlEncode2(s)
{
	ret = "";
	if (s.length>0){
		for (var i=1;i<=s.length;i++) ret = ret+urlEncodeChar(s.charAt(i-1));
	}
	return ret;
}
// End JavaScript -->
