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",siteURL+"admin/updRating.php?rating="+obj.value+"&tblName="+tblName+"&fldName="+fldName+"&id="+id,true);
	xmlhttp.send();
}

function updActive(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",siteURL+"admin/updActive.php?active="+obj.value+"&tblName="+tblName+"&fldName="+fldName+"&id="+id,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",siteURL+"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",siteURL+"insretEmail.php?email="+email,true);
			xmlhttp.send();
		}
		else
		{
			alert(message2);
			document.newsletterReg.email.focus();
		}
	}
}

function isExist(fieldValue,fieldName,message,tableName,id)
{
	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 == "exist")
			{
				document.getElementById(id).innerHTML = "<span style='color:#ff0000;font-weight:bold'>" + message + "</span>";
			}
			else
			{
				document.getElementById(id).innerHTML = "";
			}
		}
	}
	//location.href = siteURL+"isExist.php?fieldValue="+fieldValue+"&fieldName="+fieldName+"&tableName="+tableName
	xmlhttp.open("GET",siteURL+"isExist.php?fieldValue="+fieldValue+"&fieldName="+fieldName+"&tableName="+tableName,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;
	}
}
function hpPics()
{
	var picResults;
	var strProd;
	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 != "")
			{
				strProd = xmlhttp.responseText;
				picResults = strProd.split(",");
				document.getElementById("hpPics").innerHTML = "<a href='"+siteURL+"products/" + picResults[2] + ".html' title='"+ picResults[1] + "'><img src='"+siteURL+"uploads/products/" + picResults[0] + "' width='216' height=\"255\" /></a>";
			}
		}
	}
	xmlhttp.open("GET",siteURL+"hpPics.php");
	xmlhttp.send();
}

function getSalesProd()
{
	if (window.XMLHttpRequest)
	{// code for IE7+, Firefox, Chrome, Opera, Safari
	  xmlhttp1=new XMLHttpRequest();
	}
	else
	{// code for IE6, IE5
	  xmlhttp1=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp1.onreadystatechange=function()
	{
		if (xmlhttp1.readyState==4 && xmlhttp1.status==200)
		{
				document.getElementById("aaaaa").innerHTML = xmlhttp1.responseText
		}
	}
	xmlhttp1.open("GET",siteURL+"salePics.php");
	xmlhttp1.send();
}
function checksize(num,massage,sizes,prod_id,price,success)
{
	if (num > 3)
	{
		var obj = document.sizesToCart.sizes;
		var sizesSelected = "";
		for (i=0; i < obj.length ;i++)
		{
			if (obj[i].checked == true)
			{
				sizesSelected = sizesSelected + obj[i].value + "," ;
			}
		}
		
		if (sizesSelected == "")
		{
			alert(massage);
		}
		else
		{
			//sizesSelected = sizesSelected.substr(0,sizesSelected.length-1);
			sizesSelected = "," + sizesSelected;
			addToCart(sizesSelected,prod_id,price,success);	
		}
	}
	else
	{
		addToCart(sizes,prod_id,price,success);	
	}
}

function addToCart(sizes,prod_id,price,success)
{
	if (window.XMLHttpRequest)
	{// code for IE7+, Firefox, Chrome, Opera, Safari
	  xmlhttp2=new XMLHttpRequest();
	}
	else
	{// code for IE6, IE5
	  xmlhttp2=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp2.onreadystatechange=function()
	{
		if (xmlhttp2.readyState==4 && xmlhttp2.status==200)
		{
			alert(success);
		}
	}
	xmlhttp2.open("GET",siteURL+"products/addtocart.php?act=add&amount=1&price="+price+"&prod_id="+prod_id+"&sizes="+sizes);
	xmlhttp2.send();
}

function delFromCart(ptd,numProd)
{
	if (window.XMLHttpRequest)
	{// code for IE7+, Firefox, Chrome, Opera, Safari
	  xmlhttp3=new XMLHttpRequest();
	}
	else
	{// code for IE6, IE5
	  xmlhttp3=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp3.onreadystatechange=function()
	{
		if (xmlhttp3.readyState==4 && xmlhttp3.status==200)
		{
			window.location.reload();
		}
	}
	xmlhttp3.open("GET",siteURL+"products/addtocart.php?act=del&ptd="+ptd);
	xmlhttp3.send();
}

function updTotal(numProd)
{
	var price,amount;
	var sum = 0;
	for(i=0;i<numProd;i++)
	{
		price = document.getElementById(i+"_price").value;
		amount = document.getElementById(i+"_amount").value;
		sum += parseFloat(price) * parseFloat(amount);	
	}
	
	document.cart.total.value =  sum;
	goToUpdCart(numProd);
}
function goToUpdCart(numProd)
{
	var sessionStr = "";
	for(i=0;i<numProd;i++)
	{
		price = document.getElementById(i+"_price").value;
		amount = document.getElementById(i+"_amount").value;
		size = document.getElementById(i+"_size_id").value;
		prod_id = document.getElementById(i+"_prod_id").value;
		sessionStr = sessionStr + prod_id + "|" + size + "|" + price + "|" + amount + ",";
	}
	updCart(sessionStr);
}

function updCart(sessionStr)
{
	if (window.XMLHttpRequest)
	{// code for IE7+, Firefox, Chrome, Opera, Safari
	  xmlhttp5=new XMLHttpRequest();
	}
	else
	{// code for IE6, IE5
	  xmlhttp5=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp5.onreadystatechange=function()
	{
		if (xmlhttp5.readyState==4 && xmlhttp5.status==200)
		{
		 	window.location.reload();
		}
	}
	
	xmlhttp5.open("GET",siteURL+"products/addtocart.php?act=upd&session="+sessionStr);
	xmlhttp5.send();
}

function updOrderStatus(obj,id,message)
{
	if (window.XMLHttpRequest)
	{// code for IE7+, Firefox, Chrome, Opera, Safari
	  xmlhttp1=new XMLHttpRequest();
	}
	else
	{// code for IE6, IE5
	  xmlhttp1=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp1.onreadystatechange=function()
	{
		if (xmlhttp1.readyState==4 && xmlhttp1.status==200)
		{
		 	alert(message);
		}
	}
	//location.href = siteURL+"admin/orders/form.php?act=upd&order="+id+"&status="+obj;
	
	xmlhttp1.open("GET",siteURL+"admin/orders/form.php?act=upd&order="+id+"&status="+obj);
	xmlhttp1.send();	
}
function getContent(isProd)
{
	document.getElementById("contentToPrint").value = document.getElementById("content").innerHTML;
	document.getElementById("titleToPrint").value = document.getElementById("title").innerHTML;
	if (isProd == "true")
	{
		document.getElementById("picsToPrint").value = document.getElementById("pictures").innerHTML;
	}
	
	document.toPrint.submit();
}
function seturl()
{
	var url = window.location;
	window.open(siteURL+"sendToFriend.php?url="+url,"mywindow","location=0,status=0,scrollbars=0,width=400,height=600");
}

function bookmarksite(title, url)
{
	if (document.all) 
		window.external.AddFavorite(url, title); 
	else 
		if (window.sidebar) 
		window.sidebar.addPanel(title, url, "");
}
function showSabMenu(id)
{
	if (document.getElementById(id).style.display == "none")
		document.getElementById(id).style.display = "block";
	else
		document.getElementById(id).style.display = "none";
		
}
function isEmailExist(email,lang,errorObj,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(errorObj).innerHTML = document.getElementById(errorObj).innerHTML + mesaage1;
			}
		}
	}
	xmlhttp.open("GET","http://www.pelozen.co.il/insertEmail.php?email="+email+"&lang="+lang,true);
	xmlhttp.send();
}

