function searchForSN(stringToCompare, errorMsg, lang)
{
	var searchForm 					= document.getElementById("searchForm").value;

	if ((searchForm=="") || (searchForm==stringToCompare))
	{
		alert(errorMsg);
		document.getElementById("searchForm").focus();
		document.getElementById("searchForm").value="";
		return false;
	}
	
//	searchForm = searchForm.replace(/+/gi, 'plus');
	searchForm = searchForm.replace(/ /gi, '+');
	//SearchSortBy = SearchSortBy.replace(/ /gi, '+');
	
	//if (lang=="en")
		document.location = 'http://sn.u-trade.org/search/page_1/'+searchForm;
	//else
		//document.location = 'http://stiri.u-trade.ro/cautare/inregistrari_pe_pagina_'+SearchNumberOfRecorsPerPage+'/sortare_dupa_'+SearchSortBy+'/pagina_1/'+searchForm;
}

function verificaForm(component, reWriteContent, mod)
{
	actualContent = document.getElementById(component).value;

	if (mod == "focus")
	{
		if (actualContent == reWriteContent)
			document.getElementById(component).value = "";
	}
	if (mod == "blur")
	{
		if (actualContent == "")
			document.getElementById(component).value = reWriteContent;
	}
}

function verifyNewMessage()
{
	if (document.getElementById("user_id").value=="")
	{
		alert("You must select a user for who the message will be sent !");
		document.getElementById("user_id").focus();
		return false;
	}
	if (document.getElementById("my_message").value=="")
	{
		alert("Message field cannot be empty !");
		document.getElementById("my_message").focus();
		return false;
	}
}

function selectUser(imageSrc, user_id, username)
{
	document.getElementById("image_to_load").src = imageSrc;
	document.getElementById("user_id").value = user_id;
	document.getElementById("usernameToLoad").innerHTML = '<b>'+username+'</b>';
}

function checkSubmissionPhoto()
{
	switch (document.getElementById("image_tab_position").value)
	{
		case "1":
			if ((document.getElementById("your_url_image").value=="") || (document.getElementById("your_url_image").value=="http://"))
			{
				alert("You must specify an image");
				return false;
			}
		break;
		case "2":
			if (document.getElementById("your_uploaded_image").value=="")
			{
				alert("You must upload an image");
				return false;
			}
			if (document.getElementById("image_editor").innerHTML=="")
			{
				alert("You must load the uploaded image");
				return false;
			}
		break;
		case "3":
			if (document.getElementById("image_from_gallery"))
			{
				if (document.getElementById("image_from_gallery").value=="")
				{
					alert("You must select an image");
					return false;
				}
			}
			else
			{
				alert("You must select an image");
				return false;
			}
		break;
	}
}

function checkSubmission()
{
	if (document.getElementById("inputURL").value=="")
	{
		alert("URL field cannot be empty");	
		document.getElementById("inputURL").focus();
		return false;
	}
	if (document.getElementById("inputURL").value=="http://")
	{
		alert("URL field cannot be empty");	
		document.getElementById("inputURL").focus();
		return false;
	}
	if (document.getElementById("inputTitle").value=="")
	{
		alert("Title field cannot be empty");	
		document.getElementById("inputTitle").focus();
		return false;
	}
	if (document.getElementById("inputKeywords").value=="")
	{
		alert("Keywords field cannot be empty");	
		document.getElementById("inputKeywords").focus();
		return false;
	}
	if (document.getElementById("inputDescription").value=="")
	{
		alert("Description field cannot be empty");	
		document.getElementById("inputDescription").focus();
		return false;
	}
	if (document.getElementById("inputCategory").value=="0")
	{
		alert("You must select a category");	
		document.getElementById("inputCategory").focus();
		return false;
	}
	
	switch (document.getElementById("image_tab_position").value)
	{
		case "1":
			if (document.getElementById("image_from_your_site"))
			{
				if (document.getElementById("image_from_your_site").value=="")
				{
					alert("You must select an image");
					return false;
				}
			}
			else
			{
				alert("You must select an image");
				return false;
			}
		break;
		case "2":
			if ((document.getElementById("your_url_image").value=="") || (document.getElementById("your_url_image").value=="http://"))
			{
				alert("You must specify an image");
				return false;
			}
		break;
		case "3":
			if (document.getElementById("your_uploaded_image").value=="")
			{
				alert("You must upload an image");
				return false;
			}
			if (document.getElementById("image_editor").innerHTML=="")
			{
				alert("You must load the uploaded image");
				return false;
			}
		break;
		case "4":
			if (document.getElementById("image_from_gallery"))
			{
				if (document.getElementById("image_from_gallery").value=="")
				{
					alert("You must select an image");
					return false;
				}
			}
			else
			{
				alert("You must select an image");
				return false;
			}
		break;
	}
}


function checkChars(inputID, innerRelated, inputValue, maxChars, inputNr)
{
	document.getElementById(innerRelated).innerHTML = (maxChars - parseInt(inputValue.length))
	sizeObtained = inputValue.length
	if (maxChars > sizeObtained)
	{
		inputsContent[inputNr] = inputValue;
	}
	else
	{
		document.getElementById(inputID).value = inputsContent[inputNr];
		document.getElementById(innerRelated).innerHTML = "0"
	}
}

function changeItem(itemNr, state)
{
	if (state=="over")
	{
		document.getElementById("item"+itemNr).style.color  = "#fc9e37";
		document.getElementById("item"+itemNr).style.cursor = "pointer";
	}
	else
		document.getElementById("item"+itemNr).style.color = "#FEFFDA"
}

function changeTab(currentTab)
{
	for (var i=1;i<5;i++)
	{
		if (document.getElementById("div"+i))
		{
			document.getElementById("div"+i).style.display='none';
			document.getElementById("tab"+i).className='tabToSelect';
		}
	}
	
	
	document.getElementById("image_tab_position").value=currentTab;
	
	document.getElementById("div"+currentTab).style.display='';
	document.getElementById("tab"+currentTab).className='tabCurrent';
}

function setChossenImage(actualImage, nrImage)
{
	var nr_images = document.getElementById("website_images_nr").value;
	for (var i=1;i<nr_images;i++)
		document.getElementById("scaned_image_"+i).className = 'markedImage';
	document.getElementById("scaned_image_"+nrImage).className = 'markedImageSelected';
	
	document.getElementById("image_editor").innerHTML = '<div style="float:left;padding:2px;border:1px solid #D0802A;"><img src="'+actualImage+'" height="85" /><input type="hidden" name="image_from_your_site" id="image_from_your_site" value="'+actualImage+'" /></div>';
}

function setGalleryImage(actualImage, nrImage)
{
	var nr_images = document.getElementById("gallery_images_nr").value;
	for (var i=1;i<=nr_images;i++)
		document.getElementById("our_gallery_"+i).className = 'markedImage';
	document.getElementById("our_gallery_"+nrImage).className = 'markedImageSelected';
	
	document.getElementById("image_editor").innerHTML = '<div style="float:left;padding:2px;border:1px solid #D0802A;"><img src="'+actualImage+'" height="85" /><input type="hidden" name="image_from_gallery" id="image_from_gallery" value="'+actualImage+'" /></div>';
}

function setYourUrlImage()
{
	var yourImage = document.getElementById("your_url_image").value;
	document.getElementById("image_editor").innerHTML = '<div style="float:left;padding:2px;border:1px solid #D0802A;"><img src="'+yourImage+'" height="85" /></div>';
}

function retrieveDataFromWebsite()
{
	var location = 'http://sn.u-trade.org/submit/';
	location += '?title='+document.getElementById("inputTitle").value;
	location += '&url='+document.getElementById("inputURL").value;
	location += '&keywords='+document.getElementById("inputKeywords").value;
	location += '&description='+document.getElementById("inputDescription").value;
	location += '&category='+document.getElementById("inputCategory").value;
	document.location = location;
}


function loadSmyle(code_smile)
{
	browser = navigator.userAgent.toLowerCase();
	
	if (browser.indexOf('firefox') != -1)
	{
		selStart   = document.getElementById("contentComment").selectionStart;
		selEnd     = document.getElementById("contentComment").selectionEnd;
		allContent = document.getElementById("contentComment").value;
		selBefore  = allContent.substring(0, selStart);
		selAfter   = allContent.substring(selEnd, allContent.length);

		document.getElementById("contentComment").value = selBefore+code_smile+selAfter
	}

	if (browser.indexOf('msie') != -1)
		alert("We are sorry but this function is disabled in Internet Explorer or similar due to of some existing bugs found. You may still insert smilyes using codes from image title.")
}

