// 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;
    }
}
// By Setiyo G. (7/9/2004)
// validate phone entry, no repetition more than maxrep
function checkphone(strphone,maxrep)
{
    var i = 0;
    var j = 0;
    var repdigit = new Array(14);
    var digit= new Array(14);
    var repcnt=0;

    if (strphone.indexOf("12345")!=-1 || strphone.indexOf("00000")!=-1 || strphone.indexOf("11111")!=-1 || strphone.indexOf("22222")!=-1 || strphone.indexOf("33333")!=-1 || strphone.indexOf("44444")!=-1 || strphone.indexOf("55555")!=-1 || strphone.indexOf("66666")!=-1 || strphone.indexOf("77777")!=-1 || strphone.indexOf("88888")!=-1 || strphone.indexOf("99999")!=-1)
		return false;
    else {
	
    for (i = 0; i < strphone.length; i++) {
        repdigit[i] = 0;
	digit[i] = 0;
    }
    for (i = 0; i < strphone.length; i++) {
	digit[i]=strphone.substring(i,i+1);
    	for (j = 0; j <= i; j++) {
	    if (digit[j]==digit[i]) {
		repdigit[j]=repdigit[j]+1;
	    }
        }
    }
    for (i = 0; i < strphone.length; i++) {
	if (repdigit[i]>=maxrep) {
		repcnt=repcnt+1;
	}
    }
    if (repcnt>0)
		return false;
	else
		return true;   
    }
}

// By Setiyo G. (1/12/2005)
// Validate Script/HTML Tags
function checktags(chkstr) {
		if (chkstr.indexOf("i>")==-1 && chkstr.indexOf("b>")==-1 && chkstr.indexOf("p>")==-1 && chkstr.indexOf("h1>")==-1 && chkstr.indexOf("h2>")==-1 && chkstr.indexOf("h3>")==-1 && chkstr.indexOf("h4>")==-1 && chkstr.indexOf("h5>")==-1 && chkstr.indexOf("h6>")==-1 && chkstr.indexOf("body>")==-1 && chkstr.indexOf("html>")==-1 && chkstr.indexOf("br>")==-1 && chkstr.indexOf("hr>")==-1 && chkstr.indexOf("font>")==-1 && chkstr.indexOf("'")==-1 && chkstr.indexOf("script>")==-1 && chkstr.indexOf("-->>")==-1 && chkstr.indexOf("<\!--")==-1 && chkstr.indexOf("form>")==-1 && chkstr.indexOf("div>")==-1 && chkstr.indexOf("u>")==-1 && chkstr.indexOf("ol>")==-1 && chkstr.indexOf("ul>")==-1 && chkstr.indexOf("select>")==-1 && chkstr.indexOf("<input")==-1 && chkstr.indexOf("location.href")==-1 && chkstr.indexOf("response.redirect")==-1 && chkstr.indexOf("<%")==-1 && chkstr.indexOf("http")==-1 && chkstr.indexOf("ftp")==-1 && chkstr.indexOf(".js")==-1 && chkstr.indexOf("%>")==-1)
		{
			return true;
		}
		else
		{
			return false;
		}

}
function checkname(name) {
    if (name.indexOf("wedsite")!=-1 || name.indexOf("website")!=-1 || name.indexOf(".info")!=-1 || name.indexOf(".biz")!=-1 || name.indexOf(".or")!=-1 || name.indexOf(".net")!=-1 || name.indexOf(".co")!=-1 || name.indexOf("www")!=-1 || name.indexOf("@")!=-1 || name.indexOf("tanyadokter")!=-1 || name.indexOf("test")!=-1 || name.indexOf("hjkl")!=-1 || name.indexOf("yuio")!=-1 || name.indexOf("zxcv")!=-1 || name.indexOf("asdf")!=-1 || name.indexOf("qwer")!=-1)
		return false;
	else
		return true;
}

//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();
	}
	
//page2	
	function movePage2(Page2,SortAlf,lst,ty)
	{
		document.formlist.page2.value=Page2;
		//document.formlist.SortAlf.value=SortAlf;
		//document.formlist.lst.value=lst;
		//document.formlist.ty.value=ty;
		document.formlist.submit();
	}
//end page2		
	
	function loadpagelist1(){
		document.formlist.page.value=document.formlist.pagelist1.value;
		document.formlist.submit();
	}
	function loadpagelist2(){
		document.formlist.page.value=document.formlist.pagelist2.value;
		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)
{
	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));
  }
}