var xmlHttp = createXmlHttpRequest();
var textarea_max_motto = 105;
var current_id = "";
var cache = new Array();
var mode_function = new Array("-","1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24");
mode_function[25] = "sendMsgFromProfileAfter"; 


var keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";

function setCookie(c_name,value,exdays)
{
	var exdate=new Date();
	exdate.setDate(exdate.getDate() + exdays);
	var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString());
	document.cookie=c_name + "=" + c_value;
}

function getCookie(c_name)
{
	var i,x,y,ARRcookies=document.cookie.split(";");
	for (i=0;i<ARRcookies.length;i++)
	{
		x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
		y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
		x=x.replace(/^\s+|\s+$/g,"");
		if (x==c_name)
		{
			return unescape(y);
		}
	}
}

function querySt(ji)
{
	hu = window.location.search.substring(1);
	gy = hu.split("&");
	for (i=0;i<gy.length;i++)
	{
		ft = gy[i].split("=");
		if (ft[0] == ji)
		{
			return ft[1];
		}
	}
}

function replaceChars(entry)
{
	var intIndexOfMatch = entry.indexOf("&");
	while (intIndexOfMatch != -1)
	{
		entry = entry.replace("&", "#amp#");
		intIndexOfMatch = entry.indexOf("&");
	}
	return entry;
}

function encode64(input)
{
     input = escape(input);
     var output = "";
     var chr1, chr2, chr3 = "";
     var enc1, enc2, enc3, enc4 = "";
     var i = 0;
 
     do {
        chr1 = input.charCodeAt(i++);
        chr2 = input.charCodeAt(i++);
        chr3 = input.charCodeAt(i++);
 
        enc1 = chr1 >> 2;
        enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
        enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
        enc4 = chr3 & 63;
 
        if (isNaN(chr2)) {
           enc3 = enc4 = 64;
        } else if (isNaN(chr3)) {
           enc4 = 64;
        }
 
        output = output +
           keyStr.charAt(enc1) +
           keyStr.charAt(enc2) +
           keyStr.charAt(enc3) +
           keyStr.charAt(enc4);
        chr1 = chr2 = chr3 = "";
        enc1 = enc2 = enc3 = enc4 = "";
     } while (i < input.length);
 
     return output;
}
  
  
  function decode64(input) {
	      var output = "";
	      var chr1, chr2, chr3 = "";
	      var enc1, enc2, enc3, enc4 = "";
	      var i = 0;
	  
	      // remove all characters that are not A-Z, a-z, 0-9, +, /, or =
	      var base64test = /[^A-Za-z0-9\+\/\=ó]/g;
	      if (base64test.exec(input)) {
	         alert("There were invalid base64 characters in the input text.\n" +
	               "Valid base64 characters are A-Z, a-z, 0-9, '+', '/',and '='\n" +
	               "Expect errors in decoding.");
	      }
	      input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
	  
	      do {
	         enc1 = keyStr.indexOf(input.charAt(i++));
	         enc2 = keyStr.indexOf(input.charAt(i++));
	         enc3 = keyStr.indexOf(input.charAt(i++));
	         enc4 = keyStr.indexOf(input.charAt(i++));
	  
	         chr1 = (enc1 << 2) | (enc2 >> 4);
	         chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
	         chr3 = ((enc3 & 3) << 6) | enc4;
	  
	         output = output + String.fromCharCode(chr1);
	  
	         if (enc3 != 64) {
	            output = output + String.fromCharCode(chr2);
	         }
	         if (enc4 != 64) {
	            output = output + String.fromCharCode(chr3);
	         }
	  
	         chr1 = chr2 = chr3 = "";
	         enc1 = enc2 = enc3 = enc4 = "";
	  
	      } while (i < input.length);
	  
	      return unescape(output);
	   }  

function createXmlHttpRequest()
{
	var  xmlHttp;
	try
	{
		xmlHttp = new XMLHttpRequest();
	}
	catch(e)
	{
		var XmlHttpVersions = new Array("MSXML2.XMLHTTP.6.0","MSXML2.XMLHTTP.5.0","MSXML2.XMLHTTP.4.0","MSXML2.XMLHTTP.3.0","MSXML2.XMLHTTP","Microsoft.XMLHTTP");
		for(var i=0; i<XmlHttpVersions.length && !xmlHttp; i++)
		{
			try
			{
				xmlHttp = new ActiveXObject(XmlHttpVersions[i]);
			}
			catch(e){}
		}
	}
	if(!xmlHttp)
		alert("Error AJAX");
	else
		return xmlHttp;
}

function createAjaxString(params)
{
	cache.push(params);
}

function sendAjaxRequest(responseFunction)
{
	if(xmlHttp.readyState==4 || xmlHttp.readyState==0)
	{
		var params = "";
		if(cache.length>0)
		{
			params = cache.shift();
			try
			{
				xmlHttp.open("POST","mvc_controller/ajaxcontainer.php",true);
				xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
				xmlHttp.setRequestHeader("Content-length", params.length);
				xmlHttp.onreadystatechange = eval(responseFunction);
				xmlHttp.send(params);
			}
			catch(e)
			{
				alert('1 '+e.description);
			}
		}
	}
}

/* new ajax response functions */
function sendMsgFromProfileAfter()
{
	if(xmlHttp.readyState==4)
	{
		if(xmlHttp.status == 200)
		{
			var xmlResponse = xmlHttp.responseXML;
			xmlRoot = xmlResponse.documentElement;
			modeArray = xmlRoot.getElementsByTagName("mode");
			mode=modeArray.item(0).firstChild.data;
			//if(mode==25);
			alert("Wiadomo¶ć wysłana");
			sendAjaxRequest("sendMsgFromProfileAfter");
		}
		else
			alert("Error AJAX 2 prepare");
	}
}

function addUserToGroupAfter()
{
	if(xmlHttp.readyState==4)
	{
		if(xmlHttp.status == 200)
		{
			var xmlResponse = xmlHttp.responseXML;
			xmlRoot = xmlResponse.documentElement;
		   	communicateArray = xmlRoot.getElementsByTagName("communicate");
		   	groupidArray = xmlRoot.getElementsByTagName("groupid");
		   	communicate=communicateArray.item(0).firstChild.data;
		   	groupid=groupidArray.item(0).firstChild.data;
			//document.getElementById("bgugl_"+groupid).innerHTML=communicate;
		   	alert(communicate);
			//document.getElementById('cover').style.visibility="hidden";
			sendAjaxRequest("addUserToGroupAfter");
		}
		else
			alert("Spróbuj ponownie");
	}
}

function addToFavoriteAfter()
{
	if(xmlHttp.readyState==4)
	{
		if(xmlHttp.status == 200)
		{
			var info;
			var xmlResponse = xmlHttp.responseXML;
			xmlRoot = xmlResponse.documentElement;
		   	infoArray = xmlRoot.getElementsByTagName("information");
			information=infoArray.item(0).firstChild.data;
			alert(information);
			sendAjaxRequest("addToFavoriteAfter");
		}
		else
			alert("Spróbuj ponownie");
	}
}
/* do wywalenia
function assignUserToUniversityAfter()
{
	if(xmlHttp.readyState==4)
	{
		if(xmlHttp.status == 200)
		{
			var xmlResponse = xmlHttp.responseXML;
			xmlRoot = xmlResponse.documentElement;
		   	modeArray = xmlRoot.getElementsByTagName("mode");
		   	universityArray = xmlRoot.getElementsByTagName("university");
			mode=modeArray.item(0).firstChild.data;
			university=universityArray.item(0).firstChild.data;
			document.getElementById("university_list").innerHTML = university;
			
			sendAjaxRequest("assignUserToUniversityAfter");
		}
		else
			alert("Spróbuj ponownie");
	}
}
*/
function refreshUserUniversity()
{
	if(xmlHttp.readyState==4)
	{
		if(xmlHttp.status == 200)
		{
			var xmlResponse = xmlHttp.responseXML;
			xmlRoot = xmlResponse.documentElement;
		   	modeArray = xmlRoot.getElementsByTagName("mode");
		   	universityArray = xmlRoot.getElementsByTagName("university");
		   	summarycntArray = xmlRoot.getElementsByTagName("summarycnt");
			mode=modeArray.item(0).firstChild.data;
			university=universityArray.item(0).firstChild.data;
			summarycnt=summarycntArray.item(0).firstChild.data;
			document.getElementById("university_list").innerHTML = university;
			document.usermodify.alteruniversity.value="";
			document.usermodify.univ_start.selectedIndex=0;
			document.usermodify.univ_stop.selectedIndex=0;
			document.usermodify.university.selectedIndex=0;
			document.getElementById('univer_mode').value = "26";
			document.getElementById('univer_id').value = "0";
			document.getElementById("btn_addjob").value = "dodaj uczelnię";
			//if(summarycnt<2)
				//document.usermodify.up_www.readOnly = true;
			//else
				//document.usermodify.up_www.readOnly = false;
			sendAjaxRequest("refreshUserUniversity");
		}
		else
			alert("Spróbuj ponownie");
	}
}

function refreshUserCourses()
{
	if(xmlHttp.readyState==4)
	{
		if(xmlHttp.status == 200)
		{
			var xmlResponse = xmlHttp.responseXML;
			xmlRoot = xmlResponse.documentElement;
		   	//modeArray = xmlRoot.getElementsByTagName("mode");
		   	courseArray = xmlRoot.getElementsByTagName("course");
		   	summarycntArray = xmlRoot.getElementsByTagName("summarycnt");
			//mode=modeArray.item(0).firstChild.data;
			course=courseArray.item(0).firstChild.data;
			summarycnt=summarycntArray.item(0).firstChild.data;
			document.getElementById("courses_list").innerHTML = course;
			document.usermodify.coursename.value="";
			document.usermodify.course_start.selectedIndex=0;
			document.usermodify.course_stop.selectedIndex=0;
			document.getElementById('course_mode').value = "28";
			document.getElementById('course_id').value = "0";
			document.getElementById("btn_addjob").value = "dodaj kurs";
			//if(summarycnt<2)
				//document.usermodify.up_www.readOnly = true;
			//else
				//document.usermodify.up_www.readOnly = false;
			sendAjaxRequest("refreshUserCourses");
		}
		else
			alert("Spróbuj ponownie");
	}
}

function refreshUserJobs()
{
	if(xmlHttp.readyState==4)
	{
		if(xmlHttp.status == 200)
		{
			var xmlResponse = xmlHttp.responseXML;
			xmlRoot = xmlResponse.documentElement;
		   	modeArray = xmlRoot.getElementsByTagName("mode");
		   	jobArray = xmlRoot.getElementsByTagName("job");
		   	summarycntArray = xmlRoot.getElementsByTagName("summarycnt");
			mode=modeArray.item(0).firstChild.data;
			job=jobArray.item(0).firstChild.data;
			summarycnt=summarycntArray.item(0).firstChild.data;
			document.getElementById("jobs_list").innerHTML = job;
			document.usermodify.company.value="";
			document.usermodify.statement.value="";
			document.usermodify.job_start.selectedIndex=0;
			document.usermodify.job_stop.selectedIndex=0;
			document.getElementById("btn_addjob").value = "dodaj pracę";
			document.getElementById('job_mode').value = "30";
			document.getElementById('job_id').value = "0";
			//if(summarycnt<2)
				//document.usermodify.up_www.readOnly = true;
			//else
				//document.usermodify.up_www.readOnly = false;
			sendAjaxRequest("refreshUserJobs");
		}
		else
			alert("Spróbuj ponownie");
	}
}

function saveInspirationAfter()
{
	if(xmlHttp.readyState==4)
	{
		if(xmlHttp.status == 200)
		{
			var xmlResponse = xmlHttp.responseXML;
			xmlRoot = xmlResponse.documentElement;
		   	inspArray = xmlRoot.getElementsByTagName("inspiration");
			comArray = xmlRoot.getElementsByTagName("info");
			insp=inspArray.item(0).firstChild.data;
			com=comArray.item(0).firstChild.data;
			document.picture.insp_id.value=insp;
			alert(com);
			sendAjaxRequest("saveInspirationAfter");
		}
		else
			alert("Spróbuj ponownie");
	}
}

function getLibrary()
{
	if(xmlHttp.readyState==4)
	{
		if(xmlHttp.status == 200)
		{
			//summary = xmlHttp.responseText;
			var xmlResponse = xmlHttp.responseXML;
			xmlRoot = xmlResponse.documentElement;
		   	imgArray = xmlRoot.getElementsByTagName("image");
			img=imgArray.item(0).firstChild.data;
			document.getElementById("imageslist").innerHTML=img+'<div id="slideEnd"></div>';
			initGalleryScript();
			//document.getElementById('cover').style.visibility="hidden";
			sendAjaxRequest("getLibrary");
		}
		else
			alert("Spróbuj ponownie");
	}
}

function changePictypeAfter()
{
	if(xmlHttp.readyState==4)
	{
		if(xmlHttp.status == 200)
		{
			var response = xmlHttp.responseText;
			document.getElementById('mycrawler2').innerHTML = response;
			marqueeInit({
			uniqueid: 'mycrawler',
			style: {
			'padding': '0px',
			'width': '595px',
			'height': '102px'
			},
			inc: 7, //speed - pixel increment for each iteration of this marquee's movement
			mouse: 'cursor driven', //mouseover behavior ('pause' 'cursor driven' or false)
			moveatleast: 2,
			neutral: 150,
			savedirection: true
			
			});
			if(document.getElementById("only_my_insp")!=null)
				document.getElementById("only_my_insp").disabled=false;
			//document.getElementById('cover').style.visibility="hidden";
		}
		else
			alert("Spróbuj ponownie");
	}
}

function pageAfter()
{
	if(xmlHttp.readyState==4)
	{
		if(xmlHttp.status == 200)
		{
			var xmlResponse = xmlHttp.responseXML;
			xmlRoot = xmlResponse.documentElement;
			partgalleryArray = xmlRoot.getElementsByTagName("partgallery");
			drivelinksArray = xmlRoot.getElementsByTagName("drivelinks");
			partgallery=partgalleryArray.item(0).firstChild.data;
			drivelinks=drivelinksArray.item(0).firstChild.data;
			document.getElementById("documentgallery").innerHTML = partgallery;
			document.getElementById("pagelinkgal").innerHTML = drivelinks;
			sendAjaxRequest("pageAfter");
		}
		else
			alert("Spróbuj ponownie");
	}	
}

function getGroupsByProducerAfter()
{
	
	if(xmlHttp.readyState==4)
	{
		if(xmlHttp.status == 200)
		{
			var response = xmlHttp.responseText;
			document.getElementById('color_group_picker').innerHTML = response;
			//document.getElementById('cover').style.visibility="hidden";
			sendAjaxRequest("getGroupsByProducerAfter");
		}
		else
			alert("Spróbuj ponownie");
	}
}

function openProjectAfter()
{
	if(xmlHttp.readyState==4)
	{
		if(xmlHttp.status == 200)
		{
			var xmlResponse = xmlHttp.responseXML;
			xmlRoot = xmlResponse.documentElement;
			libnameArray = xmlRoot.getElementsByTagName("libnamelist");
			libnamehidArray = xmlRoot.getElementsByTagName("libnamehidden");
			projectidArray = xmlRoot.getElementsByTagName("projectid");
		   	libArray = xmlRoot.getElementsByTagName("library");
			picArray = xmlRoot.getElementsByTagName("picture");
			lmArray = xmlRoot.getElementsByTagName("leftmargin");
			tmArray = xmlRoot.getElementsByTagName("topmargin");
			lmcustomArray = xmlRoot.getElementsByTagName("leftmargincustom");
			tmcustomArray = xmlRoot.getElementsByTagName("topmargincustom");
			colorWallArray = xmlRoot.getElementsByTagName("colorwall");
			priceWallArray = xmlRoot.getElementsByTagName("pricewall");
			colorFloorArray = xmlRoot.getElementsByTagName("colorfloor");
			colorGroupArray = xmlRoot.getElementsByTagName("colorgroup");
			colorOwnerArray = xmlRoot.getElementsByTagName("colorowner");
			sceneArray = xmlRoot.getElementsByTagName("scene");
			prnameArray = xmlRoot.getElementsByTagName("projectname");
			picwidthArray = xmlRoot.getElementsByTagName("picturewidth");
			picheightArray = xmlRoot.getElementsByTagName("pictureheight");
			photonameArray = xmlRoot.getElementsByTagName("photoname");
			photoproviderArray = xmlRoot.getElementsByTagName("photoprovider");
			logofileArray = xmlRoot.getElementsByTagName("logofile");
			scene=sceneArray.item(0).firstChild.data;
			removeAllObjects(scene);
			for(i=0;i<libArray.length;i++)
			{
				photoname=photonameArray.item(i).firstChild.data;
				provider=photoproviderArray.item(i).firstChild.data;
				logofile=logofileArray.item(i).firstChild.data;
				lib=libArray.item(i).firstChild.data;
				libhid=libnamehidArray.item(i).firstChild.data;
				pic=picArray.item(i).firstChild.data;
				lm=lmArray.item(i).firstChild.data;
				tm=tmArray.item(i).firstChild.data;
				lmcustom=lmcustomArray.item(i).firstChild.data;
				tmcustom=tmcustomArray.item(i).firstChild.data;
				width=picwidthArray.item(i).firstChild.data;
				height=picheightArray.item(i).firstChild.data;
				document.getElementById(lib).style.top = tm+'px';
				document.getElementById(lib).style.left = lm+'px';
				if(lmcustom!="-" && tmcustom!="-")
				{
					document.getElementById(lib).style.top = tmcustom+'px';
					document.getElementById(lib).style.left = lmcustom+'px';
					document.getElementById("hidtop"+lib).value = tmcustom;
					document.getElementById("hidleft"+lib).value = lmcustom;
				}
				else
				{
					document.getElementById("hidtop"+lib).value = "";
					document.getElementById("hidleft"+lib).value = "";
				}
				document.getElementById(lib).style.width=width+'px';
				document.getElementById(lib).style.height=height+'px';
				//document.getElementById(lib).style.backgroundImage='url(upload/'+pic+')';
				document.getElementById(lib).innerHTML = '<img src="upload/'+pic+'" width="'+width+'" height="'+height+'" onmousedown="markDiv2(\''+logofile+'\',\''+provider+'\',\''+photoname+'\',\''+lib+'\',event)">';
				document.getElementById("hid"+lib).value = libhid;
			}
			libname=libnameArray.item(0).firstChild.data;
			
			projectid=projectidArray.item(0).firstChild.data;
			prname=prnameArray.item(0).firstChild.data;
			
			
			wall=colorWallArray.item(0).firstChild.data;
			price=priceWallArray.item(0).firstChild.data;
			floor=colorFloorArray.item(0).firstChild.data;
			cgroup=colorGroupArray.item(0).firstChild.data;
			cgowner=colorOwnerArray.item(0).firstChild.data;
			document.test.edit_id.value = projectid;
			document.getElementById("objectonscene_container").innerHTML = libname;
			document.getElementById("project_name").value = prname;
			//document.getElementById("hiddenlayers").innerHTML = libnamehid;

			var mystring1 = wall;
			var mystring2 = floor;
			
			//var result1 = mystring1.split("-");
			//var result2 = mystring2.split("-");
			//document.getElementById('panel1').innerHTML = '<img src="gr.php?r1='+result1[0]+'&g1='+result1[1]+'&b1='+result1[2]+'&alfa1='+result1[3]+'&r2='+result2[0]+'&g2='+result2[1]+'&b2='+result2[2]+'&alfa2='+result2[3]+'&scene='+scene+'">';
			document.getElementById('panel1').innerHTML = '<img src="gr.php?color1='+mystring1+'&color2='+mystring2+'&scene='+scene+'">';
			document.getElementById('buycolor').innerHTML = '<a href="javascript:void(0);" onclick="buyColorSample('+wall+')">kup próbkę</a>'; 
	
	len=document.getElementById('colset2').options.length;
	for(i=0;i<len;i++)
	{
		if(document.getElementById('colset2').options[i].value==floor)
			document.getElementById('colset2').selectedIndex=i;
	}
	
	len=document.getElementById('colorproducer').options.length;
	for(i=0;i<len;i++)
	{
		if(document.getElementById('colorproducer').options[i].value==cgowner)
			document.getElementById('colorproducer').selectedIndex=i;
	}
	//getColorsByGroup(15,cgroup,wall);
	
	getGroupsByProducer(33,cgowner,cgroup);
	setTimeout("getColorsByGroup(15,cgroup,wall)",1000);
	/*
	len=document.getElementById('colorgroup').options.length;
	for(i=0;i<len;i++)
	{
		if(document.getElementById('colorgroup').options[i].value==cgroup)
			document.getElementById('colorgroup').selectedIndex=i;
	}
	*/
	
	
	/*len=document.getElementById('colset1').options.length;
	for(i=0;i<len;i++)
	{
		if(document.getElementById('colset1').options[i].value==wall)
			document.getElementById('colset1').selectedIndex=i;
	}
	*/
		}
		else
			alert("Spróbuj ponownie");
	}
}

function sendSigAfter()
{
	if(xmlHttp.readyState==4)
	{
		if(xmlHttp.status == 200)
		{
			var xmlResponse = xmlHttp.responseXML;
			xmlRoot = xmlResponse.documentElement;
			keycodeArray = xmlRoot.getElementsByTagName("keycode");
			var keycode=keycodeArray.item(0).firstChild.data;
			setTimeout("sendSignal(19,document.getElementById('onlineuid').value)",50000);
		}
	}
}

function getColorsByGroupAfter()
{
	if(xmlHttp.readyState==4)
	{
		if(xmlHttp.status == 200)
		{
			var response = xmlHttp.responseText;
			document.getElementById('color_picker_wall').innerHTML = response;
			//document.getElementById('cover').style.visibility="hidden";
			sendAjaxRequest("getColorsByGroupAfter");
		}
		else
			alert("Spróbuj ponownie");
	}
}

function pgUsersAfter()
{
	if(xmlHttp.readyState==4)
	{
		if(xmlHttp.status == 200)
		{
			var info;
			var xmlResponse = xmlHttp.responseXML;
			xmlRoot = xmlResponse.documentElement;
			tabusersArray = xmlRoot.getElementsByTagName("tabusers");
			linkiArray = xmlRoot.getElementsByTagName("linki");
			tabusers=tabusersArray.item(0).firstChild.data;
			linki=linkiArray.item(0).firstChild.data;
			document.getElementById("tab_userlist_content").innerHTML = tabusers;
			document.getElementById("drivelinksuser").innerHTML = linki;
			sendAjaxRequest("pgUsersAfter");
		}
		else
			alert("Spróbuj ponownie");
	}
}

function pgDesignersAfter()
{
	if(xmlHttp.readyState==4)
	{
		if(xmlHttp.status == 200)
		{
			var info;
			var xmlResponse = xmlHttp.responseXML;
			xmlRoot = xmlResponse.documentElement;
			tabusersArray = xmlRoot.getElementsByTagName("tabusers");
			linkiArray = xmlRoot.getElementsByTagName("linki");
			tabusers=tabusersArray.item(0).firstChild.data;
			linki=linkiArray.item(0).firstChild.data;
			document.getElementById("tab_projektant").innerHTML = tabusers;
			document.getElementById("drivelinksdesigner").innerHTML = linki;
			sendAjaxRequest("pgDesignersAfter");
		}
		else
			alert("Spróbuj ponownie");
	}
}

function pgGroupsAfter()
{
	if(xmlHttp.readyState==4)
	{
		if(xmlHttp.status == 200)
		{
			var info;
			var xmlResponse = xmlHttp.responseXML;
			xmlRoot = xmlResponse.documentElement;
			tabusersArray = xmlRoot.getElementsByTagName("tabgroups");
			linkiArray = xmlRoot.getElementsByTagName("linki");
			tabusers=tabusersArray.item(0).firstChild.data;
			linki=linkiArray.item(0).firstChild.data;
			document.getElementById("tab_grouplist_content").innerHTML = tabusers;
			document.getElementById("drivelinksgroup").innerHTML = linki;
			sendAjaxRequest("pgGroupsAfter");
		}
		else
			alert("Spróbuj ponownie");
	}	
}

function editUniverUserAfter()
{
	if(xmlHttp.readyState==4)
	{
		if(xmlHttp.status == 200)
		{
			var info;
			var xmlResponse = xmlHttp.responseXML;
			xmlRoot = xmlResponse.documentElement;
			alternameArray = xmlRoot.getElementsByTagName("altername");
			useruniveridArray = xmlRoot.getElementsByTagName("useruniverid");
			startArray = xmlRoot.getElementsByTagName("start");
			stopArray = xmlRoot.getElementsByTagName("stop");
			univeridArray = xmlRoot.getElementsByTagName("univerid");
			
			altername=alternameArray.item(0).firstChild.data;
			useruniverid=useruniveridArray.item(0).firstChild.data;
			start=startArray.item(0).firstChild.data;
			stop=stopArray.item(0).firstChild.data;
			univerid=useruniverid;//univeridArray.item(0).firstChild.data;
			
			document.usermodify.alteruniversity.value=altername;
			
			len=document.usermodify.university.options.length;
			for(i=0;i<len;i++)
			{
				if(document.usermodify.university.options[i].value==univerid)
					document.usermodify.university.selectedIndex=i;
			}
			len=document.usermodify.univ_start.options.length;
			for(i=0;i<len;i++)
			{
				if(document.usermodify.univ_start.options[i].value==start)
					document.usermodify.univ_start.selectedIndex=i;
			}
			len=document.usermodify.univ_stop.options.length;
			for(i=0;i<len;i++)
			{
				if(document.usermodify.univ_stop.options[i].value==stop)
					document.usermodify.univ_stop.selectedIndex=i;
			}
			document.getElementById('univer_mode').value = "39";
			document.getElementById('univer_id').value = univerid;
			document.getElementById("btn_adduniver").value = "zapisz zmiany";
			sendAjaxRequest("editUniverUserAfter");
		}
		else
			alert("Spróbuj ponownie");
	}	
}

function editCourseUserAfter()
{
	if(xmlHttp.readyState==4)
	{
		if(xmlHttp.status == 200)
		{
			var info;
			var xmlResponse = xmlHttp.responseXML;
			xmlRoot = xmlResponse.documentElement;
			nameArray = xmlRoot.getElementsByTagName("coursename");
			startArray = xmlRoot.getElementsByTagName("start");
			stopArray = xmlRoot.getElementsByTagName("stop");
			courseidArray = xmlRoot.getElementsByTagName("courseid");
			
			name=nameArray.item(0).firstChild.data;
			start=startArray.item(0).firstChild.data;
			stop=stopArray.item(0).firstChild.data;
			courseid=courseidArray.item(0).firstChild.data;
			
			document.usermodify.coursename.value=name;
			
			
			len=document.usermodify.course_start.options.length;
			for(i=0;i<len;i++)
			{
				if(document.usermodify.course_start.options[i].value==start)
					document.usermodify.course_start.selectedIndex=i;
			}
			len=document.usermodify.course_stop.options.length;
			for(i=0;i<len;i++)
			{
				if(document.usermodify.course_stop.options[i].value==stop)
					document.usermodify.course_stop.selectedIndex=i;
			}
			document.getElementById('course_mode').value = "37";
			document.getElementById('course_id').value = courseid;
			document.getElementById("btn_addcourse").value = "zapisz zmiany";
			sendAjaxRequest("editCourseUserAfter");
		}
		else
			alert("Spróbuj ponownie");
	}	
}

function editJobUserAfter()
{
	if(xmlHttp.readyState==4)
	{
		if(xmlHttp.status == 200)
		{
			var info;
			var xmlResponse = xmlHttp.responseXML;
			xmlRoot = xmlResponse.documentElement;
			companyArray = xmlRoot.getElementsByTagName("company");
			statementArray = xmlRoot.getElementsByTagName("statement");
			startArray = xmlRoot.getElementsByTagName("start");
			stopArray = xmlRoot.getElementsByTagName("stop");
			jobidArray = xmlRoot.getElementsByTagName("jobid");
			
			company=companyArray.item(0).firstChild.data;
			statement=statementArray.item(0).firstChild.data;
			start=startArray.item(0).firstChild.data;
			stop=stopArray.item(0).firstChild.data;
			jobid=jobidArray.item(0).firstChild.data;
			
			document.usermodify.company.value=company;
			document.usermodify.statement.value=statement;
			
			len=document.usermodify.job_start.options.length;
			for(i=0;i<len;i++)
			{
				if(document.usermodify.job_start.options[i].value==start)
					document.usermodify.job_start.selectedIndex=i;
			}
			len=document.usermodify.job_stop.options.length;
			for(i=0;i<len;i++)
			{
				if(document.usermodify.job_stop.options[i].value==stop)
					document.usermodify.job_stop.selectedIndex=i;
			}
			document.getElementById('job_mode').value = "35";
			document.getElementById('job_id').value = jobid;
			document.getElementById("btn_addjob").value = "zapisz zmiany";
			sendAjaxRequest("editJobUserAfter");
		}
		else
			alert("Spróbuj ponownie");
	}	
}

function checkOneInfoPageAfter()
{
	if(xmlHttp.readyState==4)
	{
		if(xmlHttp.status == 200)
		{
			var xmlResponse = xmlHttp.responseXML;
			xmlRoot = xmlResponse.documentElement;
			communicateArray = xmlRoot.getElementsByTagName("communicate");
			communicate=communicateArray.item(0).firstChild.data;
			sendAjaxRequest("checkOneInfoPageAfter");
		}
		else
			alert("Spróbuj ponownie");
	}
}

function pgPicturesAfter()
{
	if(xmlHttp.readyState==4)
	{
		if(xmlHttp.status == 200)
		{
			var info;
			var xmlResponse = xmlHttp.responseXML;
			xmlRoot = xmlResponse.documentElement;
			tabusersArray = xmlRoot.getElementsByTagName("tabusers");
			insppictureArray = xmlRoot.getElementsByTagName("insppicture");
			prevArray = xmlRoot.getElementsByTagName("prev");
			nextArray = xmlRoot.getElementsByTagName("next");
			tabusers=tabusersArray.item(0).firstChild.data;
			insppicture=insppictureArray.item(0).firstChild.data;
			prev=prevArray.item(0).firstChild.data;
			next=nextArray.item(0).firstChild.data;
			
			document.getElementById("mycrawler2").innerHTML = '<div id="left_page_marque"></div><div class="marquee" id="mycrawler">'+tabusers+'</div><div id="right_page_marque"></div>';
			document.getElementById("left_page_marque").innerHTML = prev;
			document.getElementById("right_page_marque").innerHTML = next;
			marqueeInit({
				uniqueid: 'mycrawler',
				style: {
					'padding': '0px',
					'width': '595px',
					'height': '102px'
				},
				inc: 7, //speed - pixel increment for each iteration of this marquee's movement
				mouse: 'cursor driven', //mouseover behavior ('pause' 'cursor driven' or false)
				moveatleast: 2,
				neutral: 150,
				savedirection: true
			});
			sendAjaxRequest("pgPicturesAfter");	
			//document.getElementById('cover').style.visibility='hidden';
		}
		else
			alert("Spróbuj ponownie");
	}	
}

function pgInspAfter()
{
	if(xmlHttp.readyState==4)
	{
		if(xmlHttp.status == 200)
		{
			var info;
			var xmlResponse = xmlHttp.responseXML;
			xmlRoot = xmlResponse.documentElement;
			tabusersArray = xmlRoot.getElementsByTagName("tabusers");
			prtypeArray = xmlRoot.getElementsByTagName("prtype");
			prevArray = xmlRoot.getElementsByTagName("prev");
			nextArray = xmlRoot.getElementsByTagName("next");
			tabusers=tabusersArray.item(0).firstChild.data;
			prtype=prtypeArray.item(0).firstChild.data;
			prev=prevArray.item(0).firstChild.data;
			next=nextArray.item(0).firstChild.data;
			if(prtype==1)
			{
				document.getElementById("sr_lastadd").innerHTML = tabusers;
				document.getElementById("prev_lastadd").innerHTML = prev;
				document.getElementById("next_lastadd").innerHTML = next;
			}
			else if(prtype==2)
			{
				document.getElementById("sr_toprated").innerHTML = tabusers;
				document.getElementById("prev_toprated").innerHTML = prev;
				document.getElementById("next_toprated").innerHTML = next;
			}
			else if(prtype==3)
			{
				document.getElementById("sr_topcommented").innerHTML = tabusers;
				document.getElementById("prev_topcommented").innerHTML = prev;
				document.getElementById("next_topcommented").innerHTML = next;
			}
			
			sendAjaxRequest("pgInspAfter");
		}
		else
			alert("Spróbuj ponownie");
	}	
}

function inviteUserAfter()
{
	if(xmlHttp.readyState==4)
	{
		if(xmlHttp.status == 200)
		{
			var xmlResponse = xmlHttp.responseXML;
			xmlRoot = xmlResponse.documentElement;
			messageArray = xmlRoot.getElementsByTagName("message");
			message=messageArray.item(0).firstChild.data;
			alert(message);
			sendAjaxRequest("inviteUserAfter");
			
		}
		else
			alert("Error AJAX 2 prepare");
	}
}

function voteOnProjectAfter()
{
	if(xmlHttp.readyState==4)
	{
		if(xmlHttp.status == 200)
		{
			var xmlResponse = xmlHttp.responseXML;
			xmlRoot = xmlResponse.documentElement;
			messageArray = xmlRoot.getElementsByTagName("message");
			message=messageArray.item(0).firstChild.data;
			alert(message);
			sendAjaxRequest("voteOnProjectAfter");
			
		}
		else
			alert("Error AJAX 2 prepare");
	}
}

function sendProjectToUserAfter()
{
	if(xmlHttp.readyState==4)
	{
		if(xmlHttp.status == 200)
		{
			var xmlResponse = xmlHttp.responseXML;
			xmlRoot = xmlResponse.documentElement;
			messageArray = xmlRoot.getElementsByTagName("message");
			message=messageArray.item(0).firstChild.data;
			alert(message);
			sendAjaxRequest("sendProjectToUserAfter");
			document.getElementById('sampleemail').value = "email";
		}
		else
			alert("Error AJAX 2 prepare");
	}
}

function sendArticleAfter()
{
	if(xmlHttp.readyState==4)
	{
		if(xmlHttp.status == 200)
		{
			var xmlResponse = xmlHttp.responseXML;
			xmlRoot = xmlResponse.documentElement;
			messageArray = xmlRoot.getElementsByTagName("message");
			message=messageArray.item(0).firstChild.data;
			showSelectedLayer('div_emial_envelope',1);
			showSelectedLayer('div_emial_artilce_id',0);
			alert(message);
			sendAjaxRequest("sendArticleAfter");
		}
		else
			alert("Error AJAX 2 prepare");
	}
}

function shareProjectAfter()
{
	if(xmlHttp.readyState==4)
	{
		if(xmlHttp.status == 200)
		{
			var xmlResponse = xmlHttp.responseXML;
			xmlRoot = xmlResponse.documentElement;
			messageArray = xmlRoot.getElementsByTagName("message");
			message=messageArray.item(0).firstChild.data;
			alert(message);
			sendAjaxRequest("sendArticleAfter");
		}
		else
			alert("Error AJAX 2 prepare");
	}
}

function saveAnswerBoxAfter()
{
	if(xmlHttp.readyState==4)
	{
		if(xmlHttp.status == 200)
		{
			var xmlResponse = xmlHttp.responseXML;
			xmlRoot = xmlResponse.documentElement;
			messageArray = xmlRoot.getElementsByTagName("message");
			message=messageArray.item(0).firstChild.data;
			alert(message);
			sendAjaxRequest("saveAnswerBoxAfter");
		}
		else
			alert("Error AJAX 2 prepare");
	}
}

function pgProjectsAfter()
{
	if(xmlHttp.readyState==4)
	{
		if(xmlHttp.status == 200)
		{
			var info;
			var xmlResponse = xmlHttp.responseXML;
			xmlRoot = xmlResponse.documentElement;
			tabusersArray = xmlRoot.getElementsByTagName("tabusers");
			prtypeArray = xmlRoot.getElementsByTagName("prtype");
			prevArray = xmlRoot.getElementsByTagName("prev");
			nextArray = xmlRoot.getElementsByTagName("next");
			lightboxlinkArray = xmlRoot.getElementsByTagName("lightboxlink");
			lightboxtextArray = xmlRoot.getElementsByTagName("lightboxtext");
			tabusers=tabusersArray.item(0).firstChild.data;
			prtype=prtypeArray.item(0).firstChild.data;
			prev=prevArray.item(0).firstChild.data;
			next=nextArray.item(0).firstChild.data;
			if(prtype==1)
			{
				document.getElementById("sr_lastadd").innerHTML = tabusers;
				document.getElementById("prev_lastadd").innerHTML = prev;
				document.getElementById("next_lastadd").innerHTML = next;
			}
			else if(prtype==2)
			{
				document.getElementById("sr_toprated").innerHTML = tabusers;
				document.getElementById("prev_toprated").innerHTML = prev;
				document.getElementById("next_toprated").innerHTML = next;
			}
			else if(prtype==3)
			{
				document.getElementById("sr_topcommented").innerHTML = tabusers;
				document.getElementById("prev_topcommented").innerHTML = prev;
				document.getElementById("next_topcommented").innerHTML = next;
			}
			else if(prtype==6)
			{
				document.getElementById("sr_popular").innerHTML = tabusers;
				document.getElementById("prev_popular").innerHTML = prev;
				document.getElementById("next_popular").innerHTML = next;
			}
			else if(prtype==7)
			{
				lightboxlink=lightboxlinkArray.item(0).firstChild.data;
				lightboxtext=lightboxtextArray.item(0).firstChild.data;
				document.getElementById("lighthbox_gallery_link_id").href = 'upload/projects/'+lightboxlink+'.jpg';
				document.getElementById("lighthbox_gallery_link_id").title = lightboxtext;
				document.getElementById("sr_byscene").innerHTML = tabusers;
				document.getElementById("prev_byscene").innerHTML = prev;
				document.getElementById("next_byscene").innerHTML = next;
				
				
			}			
			else if(prtype==4)
			{
				document.getElementById("mycrawler2").innerHTML = '<div id="left_page_marque"></div><div class="marquee" id="mycrawler">'+tabusers+'</div><div id="right_page_marque"></div>';
				document.getElementById("left_page_marque").innerHTML = prev;
				document.getElementById("right_page_marque").innerHTML = next;
				marqueeInit({
					uniqueid: 'mycrawler',
					style: {
						'padding': '0px',
						'width': '595px',
						'height': '102px'
					},
					inc: 7, //speed - pixel increment for each iteration of this marquee's movement
					mouse: 'cursor driven', //mouseover behavior ('pause' 'cursor driven' or false)
					moveatleast: 2,
					neutral: 150,
					savedirection: true
				});
			}
			
			if(prtype!=4)
			{
				
			}
			sendAjaxRequest("pgProjectsAfter");
		}
		else
			alert("Spróbuj ponownie");
	}	
}

function showGroupsCommentAfter()
{
	if(xmlHttp.readyState==4)
	{
		if(xmlHttp.status == 200)
		{
			var xmlResponse = xmlHttp.responseXML;
			xmlRoot = xmlResponse.documentElement;
			groupsArray = xmlRoot.getElementsByTagName("groups");
			groups=groupsArray.item(0).firstChild.data;
			//alert(groups);
			//showSelectedLayer('div_emial_envelope',1);
			//showSelectedLayer('div_emial_artilce_id',0);
			//alert(message);
			document.getElementById('grouplist_addcomment').innerHTML=groups;
			sendAjaxRequest("showGroupsCommentAfter");
		}
		else
			alert("Error AJAX 2 prepare");
	}
}

function showThreadsCommentAfter()
{
	if(xmlHttp.readyState==4)
	{
		if(xmlHttp.status == 200)
		{
			var xmlResponse = xmlHttp.responseXML;
			xmlRoot = xmlResponse.documentElement;
			threadsArray = xmlRoot.getElementsByTagName("threads");
			threads=threadsArray.item(0).firstChild.data;
			document.getElementById('grouplist_addcomment').innerHTML=threads;
			sendAjaxRequest("showThreadsCommentAfter");
		}
		else
			alert("Error AJAX 2 prepare");
	}
}

function deleteCommentInfoAfter()
{
	if(xmlHttp.readyState==4)
	{
		if(xmlHttp.status == 200)
		{
			var xmlResponse = xmlHttp.responseXML;
			xmlRoot = xmlResponse.documentElement;
			commentinfoArray = xmlRoot.getElementsByTagName("comment_id");
			commentinfo = commentinfoArray.item(0).firstChild.data;
			document.getElementById('comment_socialinfo'+commentinfo).style.display="none";
			sendAjaxRequest("deleteCommentInfoAfter");
		}
		else
			alert("Error AJAX 2 prepare");
	}
}

////////////////////////////////////////////

///////// ajax request functions ///////////

function saveProjectWidget(mode,layerTab,project_name,color_wall,color_floor,scene_id,user_id,edited_id,widgetowner)
{
	var picture_ids = '';
	var picture_tops = '';
	var picture_lefts = '';
	var picture_widths = '';
	var picture_heighs = '';
	var cmp_id=0;
	if(project_name!="")
	{
		for(i=0;i<layerTab.length;i++)
		{
			if(document.test[layerTab[i]].value!="")
			{
				picture_ids += document.test[layerTab[i]].value+',';
				picture_tops += document.test['top'+layerTab[i]].value+',';
				picture_lefts += document.test['left'+layerTab[i]].value+',';
			}
		}
		createAjaxString("mode="+mode+"&userid="+user_id+"&colors="+color_wall+","+color_floor+"&pictures="+picture_ids+"&tops="+picture_tops+"&lefts="+picture_lefts+"&name="+project_name+"&sceneid="+scene_id+"&editedid="+edited_id+"&widgetowner="+widgetowner);
		sendAjaxRequest("saveProjectAfter");
	}
	else
		alert("Podaj nazwę projektu");
}


function sortProjectByScene(mode,scene_id,start,count,type)
{
	createAjaxString("mode="+mode+"&position="+start+"&paging="+count+"&type="+type+"&scene_id="+scene_id);
	sendAjaxRequest("pgProjectsAfter");
}

function shareItem(mode,item_id,coment_type)
{
	createAjaxString("mode="+mode+"&item_id="+item_id+"&coment_type="+coment_type);
	sendAjaxRequest("shareProjectAfter");
}
	
function sendMsgFromProfile(mode,reciver_id,sender_id,subject)
{
	var message = document.getElementById('usermessage').value;
	if(sender_id=="")
		location.href="user.php?part=login";
	else if(message=="")
		alert("Wpisz wiadomo¶ć")
	else
	{
		createAjaxString("mode="+mode+"&reciver="+reciver_id+"&sender="+sender_id+"&subject="+subject+"&message="+message);
		sendAjaxRequest("sendMsgFromProfileAfter");
	}
}

function addUserToGroup(mode,groupid,userid)
{
	if(userid=="")
		location.href='user.php?part=login';
	else
	{
		createAjaxString("mode="+mode+"&groupid="+groupid+"&userid="+userid);
	//document.getElementById('cover').style.visibility='visible';
		sendAjaxRequest("addUserToGroupAfter");
	}
}

function addToFavorite(project_id,user_id)
{
	createAjaxString("mode=8&projectid="+project_id+"&uid="+user_id);
	sendAjaxRequest("addToFavoriteAfter");
}

function addInspirationToFavorite(mode,inspiration_id,user_id)
{
	createAjaxString("mode="+mode+"&inspid="+inspiration_id+"&uid="+user_id);
	sendAjaxRequest("addToFavoriteAfter");
}

function addProductToFavorite(mode,product_id,keycode)
{
	createAjaxString("mode="+mode+"&pid="+product_id+"&keycode="+keycode);
	sendAjaxRequest("addToFavoriteAfter");
}

function assignUserToUniversity(mode,user_id,university_id,begin,finish,alteruniversity,univer_id)
{
	createAjaxString("mode="+mode+"&university="+university_id+"&uid="+user_id+"&begin="+begin+"&finish="+finish+"&alteruniversity="+alteruniversity+"&univer_id="+univer_id);
	sendAjaxRequest("refreshUserUniversity");
}

function removeUniversityFromUser(mode,id,user_id,question)
{
	if(confirm(question))
	{
		createAjaxString("mode="+mode+"&id="+id+"&uid="+user_id);
		sendAjaxRequest("refreshUserUniversity");
	}
}

function assignUserToCourse(mode,user_id,begin,finish,coursename,course_id)
{
	createAjaxString("mode="+mode+"&uid="+user_id+"&begin="+begin+"&finish="+finish+"&coursename="+coursename+"&course_id="+course_id);
	sendAjaxRequest("refreshUserCourses");
}

function removeCourseFromUser(mode,id,user_id,question)
{
	if(confirm(question))
	{
		createAjaxString("mode="+mode+"&id="+id+"&uid="+user_id);
		sendAjaxRequest("refreshUserCourses");
	}
}

function assignJobToUser(mode,user_id,begin,finish,company,statement,job_id)
{
	createAjaxString("mode="+mode+"&uid="+user_id+"&begin="+begin+"&finish="+finish+"&company="+company+"&statement="+statement+"&job_id="+job_id);
	sendAjaxRequest("refreshUserJobs");
}

function removeJobFromUser(mode,id,user_id,question)
{
	if(confirm(question))
	{
		createAjaxString("mode="+mode+"&id="+id+"&uid="+user_id);
		sendAjaxRequest("refreshUserJobs");
	}
}

function updateInspiration(mode,project_id,inp1,inp2,inp3,inp4,inp5,inp6,inp7,inp8,inputinsp,insp_id)
{
	createAjaxString("mode="+mode+"&projectid="+project_id+"&inp1="+inp1+"&inp2="+inp2+"&inp3="+inp3+"&inp4="+inp4+"&inp5="+inp5+"&inp6="+inp6+"&inp7="+inp7+"&inp8="+inp8+"&insp="+inputinsp+"&insp_id="+insp_id);
	sendAjaxRequest("saveInspirationAfter");

}

function saveInspiration(mode,user_id,project_id,inp1,inp2,inp3,inp4,inp5,inp6,inp7,inp8,inputinsp)
{
	createAjaxString("mode="+mode+"&uid="+user_id+"&projectid="+project_id+"&inp1="+inp1+"&inp2="+inp2+"&inp3="+inp3+"&inp4="+inp4+"&inp5="+inp5+"&inp6="+inp6+"&inp7="+inp7+"&inp8="+inp8+"&insp="+inputinsp,true);
	sendAjaxRequest("saveInspirationAfter");
}


function changeLibrary(mode,library_id,scene_id)
{
	createAjaxString("mode="+mode+"&libraryid="+library_id+"&sceneid="+scene_id);
	sendAjaxRequest("getLibrary");
}

function changeLibraryWdt(mode,library_id,scene_id,owner_id)
{
	createAjaxString("mode="+mode+"&libraryid="+library_id+"&sceneid="+scene_id+"&ownerid="+owner_id);
	sendAjaxRequest("getLibrary");
}

function changePictype(mode,pictype,uid,insppicture,syscolor)
{
	if(pictype==2)
	{
		//document.getElementById("only_my_insp").disabled=false;
		//document.picture.only_my_insp.disabled=false;
		if(document.getElementById("only_my_insp")!=null)
		{
		if(document.getElementById("only_my_insp").checked==false)
		{
			uid=0;
			if(vChangePicType == 0)
				document.getElementById("only_my_insp").disabled=true;
			//vChangePicType = 0;
		}
		else if(document.getElementById("only_my_insp").checked==true)
		{
			if(vChangePicType == 0)
				document.getElementById("only_my_insp").disabled=true;
			//alert("dsf");
			//uid=0;
			//vChangePicType = 0;
		}
		}
	}
	else if(pictype==1)
	{
		document.getElementById("only_my_insp").checked=false;
		//document.getElementById("only_my_insp").disabled=true;
		
		//document.picture.only_my_insp.disabled=true;
	}	
	//document.getElementById('cover').style.visibility="visible";
	
	if(vChangePicType!=pictype || mode==11)
	{
		vChangePicType=pictype;
		createAjaxString("mode="+mode+"&pictype="+pictype+"&uid="+uid+"&insppicture="+insppicture+"&syscolor="+syscolor);
		sendAjaxRequest("changePictypeAfter");
	}
}


function pageDocumentGallery(mode,gal_id,start,count)
{
	createAjaxString("mode="+mode+"&galid="+gal_id+"&position="+start+"&paging="+count);
	sendAjaxRequest("pageAfter");
}

function getGroupsByProducer(mode,owner_id,selected_group)
{
	//document.getElementById('cover').style.visibility="visible";
	createAjaxString("mode="+mode+"&owner_id="+owner_id+"&selected_group="+selected_group);
	sendAjaxRequest("getGroupsByProducerAfter");
}

function openProject(mode,pid)
{
	createAjaxString("mode="+mode+"&projectid="+pid);
	sendAjaxRequest("openProjectAfter");
}

function sendSignal(mode,uid)
{
	createAjaxString("mode="+mode+"&user_id="+uid);
	sendAjaxRequest("sendSigAfter");
}

function getColorsByGroup(mode,cg_id,selectedColor)
{
	//document.getElementById('cover').style.visibility="visible";
	createAjaxString("mode="+mode+"&cgroup_id="+cg_id+"&selectedcolor="+selectedColor);
	sendAjaxRequest("getColorsByGroupAfter");
}

function pgUsers(mode,start,count)
{
	createAjaxString("mode="+mode+"&position="+start+"&paging="+count);
	sendAjaxRequest("pgUsersAfter");
}

function pgDesigners(mode,start,count)
{
	createAjaxString("mode="+mode+"&position="+start+"&paging="+count);
	sendAjaxRequest("pgDesignersAfter");
}

function pgGroups(mode,start,count)
{
	createAjaxString("mode="+mode+"&position="+start+"&paging="+count);
	sendAjaxRequest("pgGroupsAfter");
}

function editJobUser(mode,job_id)
{
	createAjaxString("mode="+mode+"&id="+job_id);
	sendAjaxRequest("editJobUserAfter");
}

function editUniverUser(mode,univer_id)
{
	createAjaxString("mode="+mode+"&id="+univer_id);
	sendAjaxRequest("editUniverUserAfter");
}

function editCourseUser(mode,course_id)
{
	createAjaxString("mode="+mode+"&id="+course_id);
	sendAjaxRequest("editCourseUserAfter");
}

function checkOneInfoPage(user_id,id,page_id)
{
	showSelectedLayer(page_id,'0');
	if(document.getElementById("oneinfo_nomore").checked == true)
	{
		createAjaxString("mode=40&uid="+user_id+"&pageid="+id);
		sendAjaxRequest("checkOneInfoPageAfter");
	}
}

function pgPictures(mode,pictureid,start,count,uid)
{
	createAjaxString("mode="+mode+"&position="+start+"&paging="+count+"&uid="+uid+"&insppicture="+pictureid);
	sendAjaxRequest("pgPicturesAfter");
}

function pgInsp(mode,start,count,type)
{
	createAjaxString("mode="+mode+"&position="+start+"&paging="+count+"&type="+type);
	sendAjaxRequest("pgInspAfter");
}

function inviteUser(mode,user_reciver_keycode,user_sender_keycode)
{
	if(user_sender_keycode=="")
		location.href='user.php?part=login';
	else
	{
		createAjaxString("mode="+mode+"&sender="+user_sender_keycode+"&reciver="+user_reciver_keycode);
		sendAjaxRequest("inviteUserAfter");
	}
}

function voteOnProject(mode,item_id,item_type,user_keycode)
{
	if(user_keycode=="")
		location.href='user.php?part=login';
	else
	{
		createAjaxString("mode="+mode+"&item_id="+item_id+"&item_type="+item_type+"&keycode="+user_keycode);
		sendAjaxRequest("voteOnProjectAfter");
	}	
}

function sendProjectToUser(mode,user_keycode,project_id,email)
{
	if(user_keycode=="")
		location.href='user.php?part=login';
	else
	{
		createAjaxString("mode="+mode+"&pid="+project_id+"&email="+email+"&keycode="+user_keycode);
		sendAjaxRequest("sendProjectToUserAfter");
	}
}

function pgProjects(mode,start,count,type)
{
	createAjaxString("mode="+mode+"&position="+start+"&paging="+count+"&type="+type);
	sendAjaxRequest("pgProjectsAfter");	
}

function deleteComment(mode,comment_id,project_id)
{
	if(confirm("Czy chcesz usun±ć ten wpis?"))
	{
		createAjaxString("mode="+mode+"&cid="+comment_id+"&pid="+project_id);
		sendAjaxRequest("saveProjectCommentAfter");
	}
}

function deletePost(mode,post_id,thread_id)
{
	if(confirm("Czy chcesz usun±ć ten wpis?"))
	{
		createAjaxString("mode="+mode+"&pid="+post_id+"&tid="+thread_id);
		sendAjaxRequest("saveProjectCommentAfter");
	}
}

function sendArticle(mode,art_id,email)
{
	createAjaxString("mode="+mode+"&aid="+art_id+"&email="+email);
	sendAjaxRequest("sendArticleAfter");
}


function saveComment(mode,user_id,project_id,title,comment,cid)
{
	if(cid=="")
		cid=0;
	createAjaxString("mode="+mode+"&uid="+user_id+"&title="+title+"&pid="+project_id+"&content="+comment+"&cid="+cid);
	sendAjaxRequest("saveProjectCommentAfter");
}

function saveInspComment(mode,user_id,insp_id,title,comment,cid)
{
	if(cid=="")
		cid=0;
	createAjaxString("mode="+mode+"&uid="+user_id+"&title="+title+"&inspid="+insp_id+"&content="+comment+"&cid="+cid);
	sendAjaxRequest("saveProjectCommentAfter");	
}

function saveDisComment(mode,user_id,disc_id,comment,cid)
{
	if(cid=="")
		cid=0;
	createAjaxString("mode="+mode+"&uid="+user_id+"&did="+disc_id+"&content="+comment+"&cid="+cid);
	sendAjaxRequest("saveProjectCommentAfter");	
}

function saveCommentArticle(mode,user_id,article_id,title,comment,cid)
{
	if(user_id<0)
		alert("Zaloguj się by dodać komentarz")
	else
	{
		if(cid=="")
			cid=0;
		tid = document.comment.thread_id.value;
		createAjaxString("mode="+mode+"&uid="+user_id+"&title="+title+"&aid="+article_id+"&content="+replaceChars(comment)+"&cid="+cid+"&tid="+tid);
		sendAjaxRequest("saveProjectCommentAfter");
	}
}

function showGroupsComment(mode)
{
	createAjaxString("mode="+mode);
	sendAjaxRequest("showGroupsCommentAfter");
}

function showThreadsCommentAddThread(mode,group_id,description)
{
	createAjaxString("mode="+mode+"&gid="+group_id+"&desc="+description);
	sendAjaxRequest("showThreadsCommentAfter");
}

function showThreadsComment(mode,group_id)
{
	createAjaxString("mode="+mode+"&gid="+group_id);
	sendAjaxRequest("showThreadsCommentAfter");
}

function deleteCommentInfo(mode,comment_id)
{
	if(confirm("Czy chcesz usun±ć monit o komentarzu?"))
	{
		createAjaxString("mode="+mode+"&comment_id="+comment_id);
		sendAjaxRequest("deleteCommentInfoAfter");
	}
}


function saveAnswerBox(mode,comment_type,item_id,comment)
{
	if(comment!="")
	{
		createAjaxString("mode="+mode+"&comment_type="+comment_type+"&item_id="+item_id+"&comment="+comment);
		sendAjaxRequest("saveAnswerBoxAfter");
	}
	else
		alert("Pole nie może być puste");
	showSelectedLayer('answerbox'+comment_type+item_id,0);
	document.getElementById('answerbox'+comment_type+item_id+'text').value = "";
}
////////////////////////////////////////////






function loadDocumentPictureLead(leadlayer,glib,picture)
{
	document.getElementById(leadlayer).innerHTML='<img src="'+glib+'/'+picture+'" width="614">';
}



function saveProject(layerTab,project_name,color_wall,color_floor,scene_id,user_id,edited_id,cmp)
{
	var picture_ids = '';
	var picture_tops = '';
	var picture_lefts = '';
	var picture_widths = '';
	var picture_heighs = '';
	var cmp_id=0;
	if(project_name!="")
	{
		for(i=0;i<layerTab.length;i++)
		{
			if(document.test[layerTab[i]].value!="")
			{
				picture_ids += document.test[layerTab[i]].value+',';
				picture_tops += document.test['top'+layerTab[i]].value+',';
				picture_lefts += document.test['left'+layerTab[i]].value+',';
			}
		}
		if(xmlHttp.readyState==4 || xmlHttp.readyState==0)
		{
			if(cmp!="")
				cmp_id=cmp;
			
			var paramsy = "mode=2&userid="+user_id+"&colors="+color_wall+","+color_floor+"&pictures="+picture_ids+"&tops="+picture_tops+"&lefts="+picture_lefts+"&name="+project_name+"&sceneid="+scene_id+"&editedid="+edited_id+"&cmp="+cmp_id; 
			
			xmlHttp.open("POST","mvc_controller/ajaxcontainer.php",true);
			xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			xmlHttp.setRequestHeader("Content-length", paramsy.length);
			xmlHttp.onreadystatechange = saveProjectAfter;
			xmlHttp.send(paramsy);
		}
	}
	else
		alert("Podaj nazwę projektu");
}


function saveProjectAfter()
{
	if(xmlHttp.readyState==4)
	{
		if(xmlHttp.status == 200)
		{
			var xmlResponse = xmlHttp.responseXML;
			xmlRoot = xmlResponse.documentElement;
		   	libArray = xmlRoot.getElementsByTagName("librarylist");
			comArray = xmlRoot.getElementsByTagName("comunicate");
			uidArray = xmlRoot.getElementsByTagName("uid");
			pridArray = xmlRoot.getElementsByTagName("prid");
			lib=libArray.item(0).firstChild.data;
			com=comArray.item(0).firstChild.data;
			uid=uidArray.item(0).firstChild.data;
			prid=pridArray.item(0).firstChild.data;
			try
			{
				document.getElementById("project_container").innerHTML=lib;
			}
			catch(e){}
			document.getElementById('project_name').value="";
			if(uid>0)
				alert(com);
			else
			{
				var link = window.location.href;
				var alink = link.split("?");
				link = alink[0]; 
				alink = link.split('/');
				alert(com);
				if(alink[alink.length-1] == "user.php")
					document.location.href= "user.php?part=registration&pid="+prid;
				else if(alink[alink.length-1] == "wdt.php")
					window.open("user.php?part=registration&pid="+prid);
			}
		}
		else
			alert("Spróbuj ponownie");
	}
}


function saveGameTime(mode,project_id,time,user_id,click)
{
	if(xmlHttp.readyState==4 || xmlHttp.readyState==0)
	{
		xmlHttp.open("GET","mvc_controller/ajaxcontainer.php?mode="+mode+"&projectid="+project_id+"&uid="+user_id+"&time="+time+"&click="+click,true);
		xmlHttp.onreadystatechange = saveGameTimeAfter;
		xmlHttp.send(null);
	}
}

function saveGameTimeAfter()
{
	if(xmlHttp.readyState==4)
	{
		if(xmlHttp.status == 200)
		{
			var info;
			var xmlResponse = xmlHttp.responseXML;
			xmlRoot = xmlResponse.documentElement;
		   	btimeArray = xmlRoot.getElementsByTagName("besttime");
			buserArray = xmlRoot.getElementsByTagName("bestuser");
			timeArray = xmlRoot.getElementsByTagName("time");
			besttime=btimeArray.item(0).firstChild.data;
			bestuser=buserArray.item(0).firstChild.data;
			time=timeArray.item(0).firstChild.data;
			info = "Twój czas to: "+time;
			if(besttime>0 || bestuser!="nonexxx1")
				info+="\n Najlepszy czas użytkownika "+bestuser+": "+besttime;
			alert(info);
		}
		else
			alert("Spróbuj ponownie");
	}
}




function inspLoadProject(insppic_id,index)
{
	document.getElementById('cover').style.visibility='visible';
	if(insppic_id!="")
	{
		if(xmlHttp.readyState==4 || xmlHttp.readyState==0)
		{		
			xmlHttp.open("GET","mvc_controller/ajaxcontainer.php?mode=9&picture_id="+insppic_id+"&index="+index,true);
			xmlHttp.onreadystatechange = inspLoadProjectAfter;
			xmlHttp.send(null);		
		}
	}
	else
		alert("Wybierz inspirację");
}


function inspLoadProjectAfter()
{
	if(xmlHttp.readyState==4)
	{
		if(xmlHttp.status == 200)
		{
			var xmlResponse = xmlHttp.responseXML;
			var linki="";
			xmlRoot = xmlResponse.documentElement;
		   	nextindexArray = xmlRoot.getElementsByTagName("nextindex");
		   	currindexArray = xmlRoot.getElementsByTagName("currindex");
		   	compositionArray = xmlRoot.getElementsByTagName("composition");
		   	nextindex=nextindexArray.item(0).firstChild.data;
		   	currindex=currindexArray.item(0).firstChild.data;
		   	composition=compositionArray.item(0).firstChild.data;
		   	document.getElementById("user_project2").innerHTML = composition;

		   	if(nextindex>currindex)
		   	{
		   		linki = ' <a href="javascript:void(0)" onclick="inspLoadProject(document.picture.inputinsp.value,'+nextindex+')"><img src="img/arrow_next.gif"></a>';
		   	}
	   	
		   	if(currindex>0)
		   	{
		   		nextindex2 = currindex-1;
		   		linki = ' <a href="javascript:void(0)" onclick="inspLoadProject(document.picture.inputinsp.value,'+nextindex2+')"><img src="img/arrow_prev.gif"></a>'+linki;
		   	}
		   	
		   	document.getElementById("composition_place").innerHTML=linki;
		   	document.getElementById('cover').style.visibility="hidden";
		}
		else
			alert("Spróbuj ponownie");
	}
}



function saveProjectCommentAfter()
{
	if(xmlHttp.readyState==4)
	{
		if(xmlHttp.status == 200)
		{
			var info;
			var xmlResponse = xmlHttp.responseXML;
			xmlRoot = xmlResponse.documentElement;
			commentsArray = xmlRoot.getElementsByTagName("comments");
			comments=commentsArray.item(0).firstChild.data;
			document.getElementById("projectcomments").innerHTML = comments;
			document.getElementById('cover').style.visibility='hidden';
			document.comment.comment_id.value = '';
			document.comment.comment_content.value = '';
		}
		else
			alert("Spróbuj ponownie");
	}	
}

function saveThread(mode,user_id,style_id,title,cid)
{
	if(cid=="")
		cid=0;
	var params = "mode="+mode+"&uid="+user_id+"&title="+title+"&sid="+style_id+"&cid="+cid;
	if(xmlHttp.readyState==4 || xmlHttp.readyState==0)
	{
		document.getElementById('cover').style.visibility='visible';
		xmlHttp.open("POST","mvc_controller/ajaxcontainer.php",true);
		xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlHttp.setRequestHeader("Content-length", params.length);
	  	xmlHttp.onreadystatechange = saveProjectCommentAfter;
		xmlHttp.send(params);
	}
	showSelectedLayer('commentbox','0');
}

/*  do wywalenia obie funkcje
function addObject2competition(obj_tab,cmp_id)			
{
	
	document.getElementById('cover').style.visibility='visible';
	for(i=0;i<obj_tab.length;i++)
		if(obj_tab[i].checked)
			break;

	if(xmlHttp.readyState==4 || xmlHttp.readyState==0)
	{
		
		xmlHttp.open("GET","mvc_controller/ajaxcontainer.php?mode=12&picture_id="+obj_tab[i].value+"&cmp_id="+cmp_id,true);
		xmlHttp.onreadystatechange = addObject2competitionAfter;
		xmlHttp.send(null);		
	}
	
}

function addObject2competitionAfter()
{
	
	if(xmlHttp.readyState==4)
	{
		if(xmlHttp.status == 200)
		{
			//var info;
			//var xmlResponse = xmlHttp.responseXML;
			document.getElementById('cover').style.visibility='hidden';
			alert("Dodano obiekt do konkursu");
		}
		else
			alert("Spróbuj ponownie");
	}
}
*/

function msg_operation(operation)
{
	document.getElementById('cover').style.visibility='visible';
	var chkx=document.getElementsByName("msg_list");
	var strumien='';
	if(xmlHttp.readyState==4 || xmlHttp.readyState==0)
	{
		for(i=0;i<chkx.length;i++)
		{
			if(chkx[i].checked)
				strumien+=chkx[i].value+',';
		}
		xmlHttp.open("GET","mvc_controller/ajaxcontainer.php?mode=14&op="+operation+"&strumien="+strumien,true);
		xmlHttp.onreadystatechange = messageList;
		xmlHttp.send(null);
	}
}

function messageList()
{
	if(xmlHttp.readyState==4)
	{
		if(xmlHttp.status == 200)
		{
			response = xmlHttp.responseText;
			document.getElementById("msglist").innerHTML=response;
			document.getElementById('cover').style.visibility='hidden';
		}
		else
			alert("Spróbuj ponownie");
	}
}



///// stronnicowanie ///////





////////////////////////////////
function resamplelink(sample,pid)
{
	var width;
	var height;
	if(sample.value==0)
	{
		width=800;
		height=488;
	}
	else if(sample.value==1)
	{
		width=400;
		height=244;
	}
	else if(sample.value==2)
	{
		width=200;
		height=122;
	}
	document.getElementById("samplelink").value='http://www.deko-racja.pl/user.php?part=makepic/'+pid+'/'+width+'/'+height;
}

function editComment(comment_id,content)
{
	//showSelectedLayer('commentbox','1');
	document.comment.comment_id.value = comment_id;
	document.comment.comment_content.value = content;
}

function showPreview(provider_logo,provider,photo_name,photo_id,newSrc,layer,layername,top,left,width,height)
{
	var idx;
	ifExist=0;
	document.getElementById(layer).style.top = top+'px';
	document.getElementById(layer).style.left = left+'px';
	document.getElementById(layer).style.visibility='visible';
	document.getElementById(layer).style.width=width+'px';
	document.getElementById(layer).style.height=height+'px';
	//document.getElementById(layer).style.backgroundImage='url(upload/'+newSrc+')';
	
	document.getElementById(layer).innerHTML = '<img src="upload/'+newSrc+'" width="'+width+'" height="'+height+'" alt="Kliknij prawym przycieksiem aby usun±ć obiekt" onmousedown="markDiv2(\''+provider_logo+'\',\''+provider+'\',\''+photo_name+'\',\''+layer+'\',event)" nmouseup="setPos()">';
	document.test[layer].value=photo_id;
	document.test['top'+layer].value='';
	document.test['left'+layer].value='';
	lista = document.getElementById("objset");
	opcje = lista.getElementsByTagName('option'); 
	for(i = 0; i < opcje.length; i++)
	{
		if(opcje[i].value == layer)
		{
			ifExist=1;
		}
	}
	if(ifExist==0)
	{
		option=document.createElement('option'); 
		option.text=layername; 
		option.value=layer; 
		
		idx = document.getElementById('objset').options.length;
		document.getElementById('objset').options.length++;
		document.getElementById('objset').options[idx].value = layer;
		document.getElementById('objset').options[idx].text = layername;
		
		/*
		try
		{
			document.getElementById('objset').appendChild(option); //ff
		}
		
		
		catch(e)
		{
			document.getElementById('objset').add(option); //ie
		}
		*/
	}

}

function changeBGK(color_set1,color_set2,scene)
{
	var mystring2 = color_set2;
	var mystring1 = color_set1;

	var result1 = mystring1.split("-");
	var result2 = mystring2.split("-");
	//document.getElementById('panel1').innerHTML = '<img src="gr.php?r1='+result1[0]+'&g1='+result1[1]+'&b1='+result1[2]+'&alfa1='+result1[3]+'&r2='+result2[0]+'&g2='+result2[1]+'&b2='+result2[2]+'&alfa2='+result2[3]+'&scene='+scene+'">';
	document.getElementById('panel1').innerHTML = '<img src="gr.php?color1='+color_set1+'&color2='+color_set2+'&scene='+scene+'">';
	if(color_set1!="0")
		document.getElementById('buycolor').innerHTML = '<a href="javascript:void(0);" onclick="buyColorSample('+color_set1+')">kup próbkę</a>';
	else
		document.getElementById('buycolor').innerHTML = '';
}

function removeObject(objId)
{
	if(objId!="")
	{
	document.getElementById(objId).innerHTML = "";
	//document.getElementById(objId).style.backgroundImage='';
	lista = document.getElementById("objset");
	opcje = lista.getElementsByTagName('option'); 
	for(i = 0; i < opcje.length; i++)
	{
		if(opcje[i].value == objId)
		{
			lista.removeChild( opcje[ i ] );
			break;
		}
	}
	document.test[objId].value="";
	}
}

function removeAllObjects(scene)
{
	var elementy = document.getElementById("panel").getElementsByTagName("div");

	for(k=0;k<layerTab.length;k++)
	{
		document.test[layerTab[k]].value = "";
	}

	for(j=0;j<elementy.length;j++)
	{
		if(j==0)
			elementy[j].innerHTML='<img src="upload/'+scene+'">';
		else
			elementy[j].innerHTML='';
			//elementy[j].style.backgroundImage="";
	}
	lista = document.getElementById("objset");
	opcje = lista.getElementsByTagName('option'); 
	for(i = 0; i < opcje.length; i++)
	{
		lista.removeChild( opcje[ i ] );
	}
	if(opcje.length==1)
		lista.removeChild( opcje[ 0 ] );
}

function highLightArea(item_id)
{
	current_id = item_id;
	for(i=1;i<=8;i++)
		document.getElementById('item'+i).style.border='1px solid #ffffff';
	document.getElementById('item'+current_id).style.border='1px solid #cad000';
}

function removeInspItem()
{
	document.getElementById('item'+current_id).innerHTML = "<br/><br/>dodaj zdjęcie";//+current_id;
	document.getElementById('input'+current_id).value="";
}

function showSelectedLayer(layerId,visibility)
{
	if(visibility==1)
	{
		document.getElementById(layerId).style.visibility='visible';
		document.getElementById(layerId).style.display='block';
	}
	else if(visibility==0)
	{
		document.getElementById(layerId).style.visibility='hidden';
		document.getElementById(layerId).style.display='none';
	}
}

function cup(inp)
{
	inp.style.backgroundImage='url(img/form_bgk2.jpg)';
	inp.style.color="#ffffff";
}

function cdn(inp)
{
	inp.style.backgroundImage='url(img/form_bgk.jpg)';
	inp.style.color="#ffbbbb";
}

function preapareInspiration(project,user,insp_id)
{
	user_id = user;
	project_id = project;
	inputy1 = document.getElementById('input1').value;
	inputy2 = document.getElementById('input2').value;
	inputy3 = document.getElementById('input3').value;
	inputy4 = document.getElementById('input4').value;
	inputy5 = document.getElementById('input5').value;
	inputy6 = document.getElementById('input6').value;
	inputy7 = document.getElementById('input7').value;
	inputy8 = document.getElementById('input8').value;
	inputinsp  = document.getElementById('inputinsp').value;
	
	if(project_id=="" || inputinsp=="")
	{
		alert("Inspiracja musi zawierać projekt z przymierzalni");
	}
	else
	{
		if(insp_id=="")
			saveInspiration(5,user_id,project_id,inputy1,inputy2,inputy3,inputy4,inputy5,inputy6,inputy7,inputy8,inputinsp);
		else
			updateInspiration(6,project_id,inputy1,inputy2,inputy3,inputy4,inputy5,inputy6,inputy7,inputy8,inputinsp,insp_id);
	}
}


function showColorDD(i)
{
	if(i==1)
	{
		document.picture.inspcolor2.disabled=true;
		document.picture.inspcolor3.disabled=true;
	}
	else if(i==0)
	{
		document.picture.inspcolor2.disabled=false;
		document.picture.inspcolor3.disabled=false;
	}
}

function stoper()
{
	// liczy czas gry w puzzle
	// zmienna game_time zadeklarowana w widoku project_game1.php
	game_time += 1;
	document.getElementById("puzzle_timer").innerHTML= "Czas: "+game_time+" sek";
	setTimeout("stoper()",1000);
}




// ---------------- przesuwanie obiektów po scenie

function myMouseXY(e)
{
	if(block==1)
	{
		prW = document.body.clientWidth;
		prH = document.body.clientHeight;
		if(prW<=1030)
			paramW = 0;
		else if(prW>1030 && prW<=1220)
			paramW = Math.round(document.body.clientWidth/15);
		else if(prW>1220 && prW<=1330)
			paramW = Math.round(document.body.clientWidth/10)+15;
		else if(prW>1330 && prW<=1440)
			paramW = Math.round(document.body.clientWidth/8)+20;
		else if(prW>1400 && prW<=1600)
			paramW = Math.round(document.body.clientWidth/5)-15;
		
		if(prH<=700)
			paramH = 0;
		else if(prH>700 && prH<=800)
			paramH = Math.round(document.body.clientHeight/1);
		else if(prH>800 && prH<=1030)
			paramH = Math.round(document.body.clientHeight/2);
		else if(prH>1030 && prH<=1205)
			paramH = Math.round(document.body.clientHeight/3);
		
		
		
		if (IE)
		{
			paramH = 175;
			
			if (typeof(wdt_ParamH) == 'undefined')
				paramH = 175;
			else
				paramH += wdt_ParamH;
			
			obj.style.top = (event.clientY + document.body.scrollTop)-document.getElementById("panel").offsetTop-Sy-paramH+"px";
			obj.style.left = (event.clientX + document.body.scrollLeft)-document.getElementById("panel").offsetLeft-Sx-paramW+"px";
		}
		else
		{

			if (typeof(wdt_ParamH) == 'undefined')
				paramH = 0;
			else
				paramH = wdt_ParamH;
			obj.style.left = e.pageX-document.getElementById("panel").offsetLeft-Sx-paramW+"px";
			obj.style.top = e.pageY-document.getElementById("panel").offsetTop-Sy-paramH+"px";
		}
		if(parseInt(obj.style.left)<0)
			obj.style.left=0;
		if(parseInt(obj.style.top)<0)
			obj.style.top=0;
		if((parseInt(obj.style.top)+parseInt(obj.style.height))>488)
			obj.style.top=488 - parseInt(obj.style.height)+1;
		if((parseInt(obj.style.left)+parseInt(obj.style.width))>800)
			obj.style.left=800 - parseInt(obj.style.width);
		
		document.test["left"+objname].value = parseInt(obj.style.left);
		document.test["top"+objname].value = parseInt(obj.style.top);
	}
}

function markDiv(o,oname,ev)
{
	var ev = ev || window.event;
		
	if(ev.button==1 || ev.button==0)
	{
		objname = oname;
		obj = o;
		block=1;
		document.getElementById("panel").onmousemove=myMouseXY;
		obj.style.border='1px solid red';
		if (IE)
		{
			Sx = event.offsetX;
			Sy = event.offsetY;
		}
		else
		{
			Sx = e.pageX-obj.offsetLeft;
			Sy = e.pageY-obj.offsetTop;
		}
	}
	/*else if(ev.button==2)
	{
		var new_left = document.getElementById(oname).style.left;
		var new_top = document.getElementById(oname).style.top;
		new_left_value = new_left.indexOf("px");
		new_top_value = new_top.indexOf("px");
		new_left_value = new_left.substr(0,new_left_value);
		new_top_value = new_top.substr(0,new_top_value);
		document.getElementById("object_info").style.display = 'block';
		document.getElementById("object_info").style.top = new_top_value+'px';
		document.getElementById("object_info").style.left = new_left_value+'px';
		document.getElementById("object_info").innerHTML = '<a href="javascript:void(0);" onclick="if(confirm(\'Czy chcesz usun±ć obiekt ze sceny?\'))removeObject(\''+oname+'\');document.getElementById(\'object_info\').style.display=\'none\'">usuń obiekt</a><div style="position:absolute;top:0px;left:135px;"><a href="javascript:void(0);" onclick="document.getElementById(\'object_info\').style.display=\'none\'">x</a></div>';
		
		//if(confirm("Czy chcesz usun±ć obiekt ze sceny?"))removeObject(oname);
	}*/
}

function markDiv2(provider_logo,provider,productname,oname,ev)
{
	var ev = ev || window.event;
		
	if(ev.button==2)
	{
		var new_left = document.getElementById(oname).style.left;
		var new_top = document.getElementById(oname).style.top;
		new_left_value = new_left.indexOf("px");
		new_top_value = new_top.indexOf("px");
		new_left_value = new_left.substr(0,new_left_value);
		new_top_value = new_top.substr(0,new_top_value);
		document.getElementById("object_info").style.display = 'block';
		document.getElementById("object_info").style.top = new_top_value+'px';
		document.getElementById("object_info").style.left = new_left_value+'px';
		document.getElementById("object_info").innerHTML = '<div style="position:absolute;top:0px;left:131px;"><a href="javascript:void(0);" onclick="document.getElementById(\'object_info\').style.display=\'none\'">[x]</a></div>';
		
		
		document.getElementById("object_info").innerHTML += '<div style="position:absolute;top:10px;left:10px;text-align:left;">'+productname+'</b></div>';
		document.getElementById("object_info").innerHTML += '<div style="position:absolute;top:27px;left:10px;text-align:left;">'+provider+'</div>';
		if(provider_logo!="" &&  provider_logo!="-")
		{
			logo = new Image;
			logo.src = "upload/company/"+provider_logo;
			//alert(logo.width);
			document.getElementById("object_info").innerHTML += '<div style="position:absolute;top:44px;left:10px;text-align:left;"><img src="upload/company/'+provider_logo+'" width="70" height="40"/></div>';
		}
		
		document.getElementById("object_info").innerHTML += '<div style="position:absolute;top:90px;left:45px;"><a href="javascript:void(0);" onclick="if(confirm(\'Czy chcesz usun±ć obiekt ze sceny?\'))removeObject(\''+oname+'\');document.getElementById(\'object_info\').style.display=\'none\'">usuń obiekt</a></div>';
		//if(confirm("Czy chcesz usun±ć obiekt ze sceny?"))removeObject(oname);
	}
}

function setPos()
{
	block=0;
	if(obj!=null)
		obj.style.border='0px solid red';
}

function changeSceneWdt(sid,owner)
{
	if(sid!=0)
		document.location.href = 'wdtcustom.php?part=tryroomwdt/'+owner+'/'+sid;
}

/////////////////////////////////////////////////////////

function changeTabBgk(layer,color,bgcolor)
{
	if(color!=0)
		document.getElementById(layer+'a').style.color=color;
	document.getElementById(layer).style.backgroundColor=bgcolor;
}

function setUnderline(layer,underline)
{
	if(underline==0)
		document.getElementById(layer).style.textDecoration='none';
	else
		document.getElementById(layer).style.textDecoration='underline';
}

function popup(adres,w,h)
{
 window.open(adres, '', 'toolbar=no,menubar=no,resizable=no,status=no,margines=no,location=no,directories=no,copyhistory=no,scrollbars=yes,height='+h+',width='+w+',left=0,top=0');
 // definicja otwieranego okienka przy wej¶ciu
}

function loadGalleryPicture(picture)
{
	document.getElementById("gallery_bigphoto").innerHTML = '<img src="upload/pictures/'+picture+'" width="634" height="476">';
}


function confirmDelete(communicate)
{
	if(confirm(communicate))
		return true;
	else
		return false;
}

function buyColorSample(color)
{
	popup('payform.php?color='+color,850,650);
}

function chkProjectEmail(status)
{
	if((status==1 && document.getElementById("sampleemail").value=="email"))
	{
		document.getElementById("sampleemail").value="";
	}
	if(status==0 && document.getElementById("sampleemail").value=="")
	{
		document.getElementById("sampleemail").value="email";
	}
}

 
function counterTextarea(t)
{ 
	if (document.getElementById("motto_txt").value.length>=textarea_max_motto)
	{ 
		window.alert("Wpisałeś zbyt długi tekst. Może on mieć tylko "+textarea_max_motto+" znaków!");
		document.getElementById("motto_txt").value = document.getElementById("motto_txt").value.substr(0,textarea_max_motto); 
	} 
}

function callApp(application,qstring,width,length)
{
	if(qstring.length>0)
		qstring = '?'+qstring;
	document.write('<iframe frameborder=0 width='+width+' height='+length+' src="http://www.deko-racja.pl/external/'+application+qstring+'"></iframe>');
}
