var i = 1;
function textEditor(textareaname,folderName)
{
	// Automatically calculates the editor base path based on the _samples directory.
	// This is usefull only for these samples. A real application should use something like this:
	// oFCKeditor.BasePath = '/fckeditor/' ;	// '/fckeditor/' is the default value.
	
	var sBasePath = document.location.href.substring(0,document.location.href.lastIndexOf('admin/'+folderName+'/')) ;
	var oFCKeditor = new FCKeditor( textareaname ) ;
	oFCKeditor.BasePath	= sBasePath + "/fckeditor/" ;
	oFCKeditor.Width = 600 ;
	oFCKeditor.Height = 300 ;
	oFCKeditor.ReplaceTextarea() ;
}
function nav(divClick,divTarget)
{
	if (i % 2 == 1)
	{
		i++;
		showSubMenu (divClick,divTarget);
	}
	else
	{
		i++;
		hideSubMenu (divClick,divTarget);
	}
}
function showSubMenu (divClick,divTarget)
{
	$("#"+divClick).click(function () {
			$("#"+divTarget).show("slow");
	});
}	
function hideSubMenu (divClick,divTarget)
{
	$("#"+divClick).click(function () {
			$("#"+divTarget).hide("slow");
	});
}

function updRating(obj,tblName,fldName,id,message)
{
	if (window.XMLHttpRequest)
	{// code for IE7+, Firefox, Chrome, Opera, Safari
	  xmlhttp=new XMLHttpRequest();
	}
	else
	{// code for IE6, IE5
	  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function()
	{
		if (xmlhttp.readyState==4 && xmlhttp.status==200)
		{
			alert(message);
		}
	}
	xmlhttp.open("GET","http://www.techno-ad.co.il/admin/updRating.php?rating="+obj.value+"&tblName="+tblName+"&fldName="+fldName+"&id="+id,true);
	xmlhttp.send();
}



function updActive(obj,tblName,fldName,id,message,active_field)
{
	if (window.XMLHttpRequest)
	{// code for IE7+, Firefox, Chrome, Opera, Safari
	  xmlhttp=new XMLHttpRequest();
	}
	else
	{// code for IE6, IE5
	  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function()
	{
		if (xmlhttp.readyState==4 && xmlhttp.status==200)
		{
			alert(message);
		}
	}
	//alert("active: "+obj+" tblName: "+tblName+" fldName: "+fldName +" id: "+id+" active_field: "+active_field);
	xmlhttp.open("GET","http://www.techno-ad.co.il/admin/updActive.php?active="+obj+"&tblName="+tblName+"&fldName="+fldName+"&id="+id+"&active_field="+active_field,true);
	xmlhttp.send();
	
}

function goToArchive(tblName,fldName,id,message,archiveValue)
{
	var j,strToArchive,obj;
	strToArchive = "";
	obj = document.getElementsByName("archive");
	for (j=0; j< obj.length ;j++)
	{
		if (obj[j].checked == true)
		{
			strToArchive = strToArchive + obj[j].value + ",";
		}
		
	}
	if (strToArchive != "")
	{
		strToArchive = ","+strToArchive;
		if (window.XMLHttpRequest)
		{// code for IE7+, Firefox, Chrome, Opera, Safari
		  xmlhttp=new XMLHttpRequest();
		}
		else
		{// code for IE6, IE5
		  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
		xmlhttp.onreadystatechange=function()
		{
			if (xmlhttp.readyState==4 && xmlhttp.status==200)
			{
				alert(message);
				window.location.reload();
			}
		}
		xmlhttp.open("GET","http://www.techno-ad.co.il/admin/updArchive.php?archiveValue="+archiveValue+"&strArchive="+strToArchive+"&tblName="+tblName+"&fldName="+fldName+"&id="+id,true);
		xmlhttp.send();
	}
}
	
function joinToNewsletter(message1,message2,message3,message4)
{
	var email = document.newsletterReg.email.value;
	var isEmail = false;
	if (email == "")
	{
		alert(message1);
		document.newsletterReg.email.focus();
	}
	else
	{
		isEmail	= check_email(email)
		if (isEmail)
		{
			if (window.XMLHttpRequest)
			{// code for IE7+, Firefox, Chrome, Opera, Safari
			  xmlhttp=new XMLHttpRequest();
			}
			else
			{// code for IE6, IE5
			  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
			}
			xmlhttp.onreadystatechange=function()
			{
				if (xmlhttp.readyState==4 && xmlhttp.status==200)
				{
					if(xmlhttp.responseText == "yes")
					{
						alert(message3)
					}
					else
					{
						alert(message4)
					}
				}
			}
			xmlhttp.open("GET","http://www.techno-ad.co.il/insretEmail.php?email="+email,true);
			xmlhttp.send();
		}
		else
		{
			alert(message2);
			document.newsletterReg.email.focus();
		}
	}
}

function isEmailExist(email,lang,mesaage1,message2)
{
	if (window.XMLHttpRequest)
	{// code for IE7+, Firefox, Chrome, Opera, Safari
	  xmlhttp=new XMLHttpRequest();
	}
	else
	{// code for IE6, IE5
	  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function()
	{
		if (xmlhttp.readyState==4 && xmlhttp.status==200)
		{
			if(xmlhttp.responseText == "1")
			{
				alert(message2);
			}
			else
			{
				document.getElementById("error").innerHTML = document.getElementById("error").innerHTML + mesaage1;
			}
		}
	}
	xmlhttp.open("GET","http://www.techno-ad.co.il/insertEmail.php?email="+email+"&lang="+lang,true);
	xmlhttp.send();
}

function check_email(email)
{
	emailRegExp = /^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.([a-z]){2,4})$/;
	var err_mail="Email addres incorect!";
	if(emailRegExp.test(email))
	{
		return true;
	}
	else
	{
		return false;
	}
}
  
function showFullSize(divParent,divFrame,picSource)
{
	document.getElementById(divFrame).style.width = screen.width - 20 + "px";
	document.getElementById(divFrame).style.height = screen.height- 20 + "px";
	document.getElementById(divParent).style.width = screen.width- 20 + "px";
	document.getElementById(divParent).style.height = screen.height- 20 + "px";		
	document.getElementById("image").src = picSource;
	document.getElementById(divParent).style.display = 'block';
	var newImg = new Image();
	newImg.src = document.getElementById("image").src;
	picWidth = newImg.width;
	document.getElementById("divImage").style.width = picWidth + "px";
	var divPositionRight;
	divPositionRight = (screen.width - picWidth) / 2;
	document.getElementById("divImage").style.left = divPositionRight + "px";
}

function validLength(obj,strLength)
{
	if (obj.value.length < strLength)
	{
		return true;
	}
	return false;
	
}
function isEmpty(obj)
{
	if (obj.value.length == 0)
	{
		return true;
	}
	return false;
	
}
function checkLetters(str,message)
{
	strRegExp = /[a-z0-9_-]/;
	if(strRegExp.test(str.value))
	{	
		return true;
	}
	else
	{
		alert(message);
		return false;
	}
}
function isPhone(str)
{
	strRegExp = /^\d{3}-\d{7}$/;
	if(strRegExp.test(str.value))
	{	
		return true;
	}
	else
	{
		return false;
	}
}
