// JavaScript Document
function checkAll()
{
	//if (i == 0) { // "All" checkbox selected.
	if (document.formlist.pagesidtop.checked == false)
	{
		for (i = 0; i < document.formlist.pagesid.length; i++)
		{
		document.formlist.pagesid[i].checked = false;
    	for (j=0;j< document.getElementById("baris").rows[i+1].cells.length; j++)
		{
		document.getElementById("baris").rows[i+1].cells[j].style.backgroundColor = document.formlist.apa[i].value;
		//alert(document.getElementById("baris").rows[i+1].cells[j].className);
		}
		}
	}
	else
	{
		for (i = 0; i < document.formlist.pagesid.length; i++)
		{
		document.formlist.pagesid[i].checked = true;
    	for (j=0;j< document.getElementById("baris").rows[i+1].cells.length; j++)
		document.getElementById("baris").rows[i+1].cells[j].style.backgroundColor = "#f2f7de";
		}
    }
}

function changecolor(s)
{
	if (document.formlist.pagesid.length==undefined)
	{
		if (document.formlist.pagesid.checked == true)
		{
			for (j=0;j< document.getElementById("baris").rows[s].cells.length; j++)
			{
				document.getElementById("baris").rows[s].cells[j].style.backgroundColor = "#f2f7de";
			}
		}
		else
		{
			for (j=0;j< document.getElementById("baris").rows[s].cells.length; j++)
				document.getElementById("baris").rows[s].cells[j].style.backgroundColor = document.formlist.apa.value;
		}

	}

	else

	{
		if (document.formlist.pagesid[s-1].checked == true)
		{
			for (j=0;j< document.getElementById("baris").rows[s].cells.length; j++)
			{
				document.getElementById("baris").rows[s].cells[j].style.backgroundColor = "#f2f7de";
			}
		}
		else
		{
			for (j=0;j< document.getElementById("baris").rows[s].cells.length; j++)
				document.getElementById("baris").rows[s].cells[j].style.backgroundColor = document.formlist.apa[s-1].value;
		}
	}

}



function openWindow(targetURL,width,height,winName)
{
	LeftPosition = (screen.width - width )/2 - 5;
	TopPosition = (screen.height-height) / 2 - 50;
	win=window.open(targetURL, winName , "scrollbars=yes,width=" 
	  		+ width + ",height=" + height + ",top=" + TopPosition + ",left=" 
	  		+ LeftPosition + ",resizable");
	win.focus();  
	return win;
}

// By Hengky I. (5/6/2004)
// validate Time format
function checkdate(intDay,intMonth,intYear) {
	var dtDate = new Date(intMonth + '/' + intDay + '/' + intYear )
    if (dtDate.getDate() != intDay && dtDate.getMonth() != intMonth-1) 
    	return false;
    else
    	return true;
}

// By Setiyo G. (16/7/2004)
// Validate email entry
function checkemail(email) {
    if (email.length < 11 || email.indexOf("@")==-1 || email.indexOf(".")==-1 || email.indexOf("!")!=-1 || email.indexOf("..")!=-1 || email.indexOf(".")==0 || email.indexOf(".")==email.length)
		return false;
    else {
		var pos;
		pos = email.indexOf("@");
		var mailbox=email.substring(0,pos);
		var domainname=email.substring(pos+1,email.length);
		var mailboxlast=mailbox.substring(mailbox.length-1,mailbox.length);
		var domainfirst=domainname.substring(0,1);
		var lastdigit=email.substring(email.length-1,email.length);
		var firstdigit=email.substring(0,1)
		if (mailbox.indexOf("-")==-1 && mailbox.indexOf("@")==-1 && domainname.indexOf("_")==-1 && domainname.indexOf("@")==-1 && lastdigit.indexOf(".")==-1 && lastdigit.indexOf("-")==-1 && firstdigit.indexOf(".")==-1 && firstdigit.indexOf("_")==-1 && mailboxlast.indexOf(".")==-1 && mailboxlast.indexOf("_")==-1 && domainfirst.indexOf(".")==-1 && domainfirst.indexOf("-")==-1)
			return true;
		else
			return false;
    }
}


//function gotoPage & movePage punya sub paging

	function gotoPage(SortAlf,lst,ty)
	{
		if (document.formlist.goto.value!="")
		{
			movePage(document.formlist.goto.value,SortAlf,lst,ty);
		}
	}
	function movePage(Page,SortAlf,lst,ty)
	{
		document.formlist.page.value=Page;
		document.formlist.SortAlf.value=SortAlf;
		document.formlist.lst.value=lst;
		document.formlist.ty.value=ty;
		document.formlist.submit();
	}



function popeditor(formname,caller)
{
	strURL = "../../contenteditor/editor.asp?" + "formname=" + formname + "&caller=" + caller;
	win = window.open (strURL ,'editor','location=no,status=no,directories=no,menubar=no,scrollbars=no,resizable=no,width=531,height=395');
	win.focus();
	win.moveTo(0,0);


}

function show(formname,caller,content,domain)
{
	alert();
	var domainname= "http://" + domain;

	content = content.replace (/img (height=[0-9]*) src=\"\.\./gi,"img " + "$1" + " src=\"" + domainname)

	//content = content.replace (/img (height=[0-9]*) src=\"http:[^0-9]*http:/gi,"img " + "$1" + " src=\"" + "http:" )

	var txtContent=document.getElementById(caller);
	var divContent=document.getElementById(caller + "1");
	
	eval("document." + formname + "." + caller ).value =  content  ;
	divContent.innerHTML=content;
	//buildImagePath(document.getElementById(caller + "1"), domainname + "/")
	
	var reg = new RegExp("<[^>]+>");
	if (reg.test(content)){
		txtContent.style.display='none';
		divContent.style.display='inline';
	}else{
		txtContent.style.display='inline';
		divContent.style.display='none';
	}

//	document.getElementById(caller + "1").innerHTML =  content  ;
}

function buildImagePath(objBody, hostName) // handles path for inserted images on content editor -tx-
{
  var objImg = objBody.all.tags("img");
  imgPath = "images/upload/webpage";
  for(var i = 0; i < objImg.length; i++)
  {
    if(objImg[i].src.indexOf(imgPath) >= 0) objImg[i].src = hostName + objImg[i].src.substr(objImg[i].src.indexOf(imgPath));
  }
}
