var confirmMsg  = 'هل حقاً تود الحذف';
var isdrag=false;
var bustcacheparameter = "";
var bustcachevar=1;
var ftrSpeed= new Array(4);
var ftrIntHide= new Array(4);
var ftrIntShow= new Array(4);
var ftri= new Array(4);

function changeHeightDiv(id, height) {
	document.getElementById(id).style.height = height;
}

function changeColorToGallery(id, color) {
	document.getElementById(id).style.color = color;
}

function ftrShowMenu(idDivs, numI) {
	ftrSpeed[numI] = 0;
	ftri[numI] = 160;
	clearInterval(ftrIntHide[numI]);
	ftrIntShow[numI]=setInterval("ftrShow('"+idDivs+"','"+numI+"');",10);
}

function ftrHideMenu(idDivs, numI) {
	ftrSpeed[numI] = 0;
	clearInterval(ftrIntShow[numI]);
	ftrIntHide[numI]=setInterval("ftrHide('"+idDivs+"','"+numI+"');",10);
}

function ftrShow(toIdDiv, numI) {
	if (ftri[numI]>95) {
		ftrSpeed[numI]=ftrSpeed[numI]+2;
		ftri[numI]=ftri[numI]-ftrSpeed[numI];
		if(ftri[numI]<95){
			ftri[numI]=95;
			document.getElementById(toIdDiv).style.marginTop=ftri[numI];
			clearInterval(ftrIntShow[numI]);
			return;
		}
		document.getElementById(toIdDiv).style.marginTop=ftri[numI];
	}
}

function ftrHide(toIdDiv, numI) {
	if (ftri[numI]<160) {
		ftrSpeed[numI]++;
		ftri[numI]=ftri[numI]+ftrSpeed[numI];
		if(ftri[numI]>160){
			ftri[numI]=160;
			document.getElementById(toIdDiv).style.marginTop=ftri[numI];
			clearInterval(ftrIntHide[numI]);
			return;
		}
		document.getElementById(toIdDiv).style.marginTop=ftri[numI];
	}
}

function DoHidedivs(id) {
		document.getElementById(id).style.display = 'none';
}

function makePicDay(numShow) {
	xmlDoc = loadXMLDoc('/beta/xml/xml_picDay_home.xml');
	html = "<div id=\"mLCS4RRTextL\"><div id=\"mLCS4RRTextLAbso\"><div id=\"mLCS4RRTextLAbso1\">";
	html += "<img src=\"/beta/images/pic_day/"+xmlDoc.getElementsByTagName("folder")[numShow].childNodes[0].nodeValue+"/1_"+xmlDoc.getElementsByTagName("name")[numShow].childNodes[0].nodeValue+"\" style=\"width:293px;height:220px;border:0px;\" />";
	html += "</div><div id=\"mLCS4RRTextLAbso2\"><div id=\"mLCS4RRTextLAbso2ToText\">";
	html += "<span class=\"start12\">"+xmlDoc.getElementsByTagName("text")[numShow].childNodes[0].nodeValue+"</span></div></div></div></div><div id=\"mLCS4RRTextR\">";
	for(i=0;i<=3;i++) {
		if(i != numShow) {
			html += "<div class=\"mLCS4RRTextROn\" onclick=\"makePicDay("+i+");\" onmouseover=\"DoHidedivs('mLCS4RRTextROnAbso2IdIs"+i+"');\" onmouseout=\"Doblockdivs('mLCS4RRTextROnAbso2IdIs"+i+"');\">";
			html += "<div class=\"mLCS4RRTextROnAbso\">";
			html += "<div class=\"mLCS4RRTextROnAbso1\"><img src=\"/beta/images/pic_day/"+xmlDoc.getElementsByTagName("folder")[i].childNodes[0].nodeValue+"/2_"+xmlDoc.getElementsByTagName("name")[i].childNodes[0].nodeValue+"\" style=\"width:90px;height:70px;border:0px;\" /></div>";
			html += "<div id=\"mLCS4RRTextROnAbso2IdIs"+i+"\" class=\"mLCS4RRTextROnAbso2\"><div class=\"mLCS4RRTextROnAbso2TOZoom\"></div></div>";
			html += "</div></div>";
		}
	}		
	html += "</div>";
	document.getElementById("mLCS4RRText").innerHTML = html;
}

function makePicDayCats(numCats, numShow, color1, color2) {
	xmlDoc = loadXMLDoc('/beta/xml/xml_picDay_'+numCats+'.xml');
	html = "<div id=\"theCatsCenetrRTextInSmallPic\">";
	for(i=0;i<3;i++) {			
		if(i == numShow) {
			html += "<div class=\"theCatsCenetrRTextSmallPicOpen\" style=\"border-right: 7px solid #"+color1+";\"><img src=\"/beta/images/pic_day/"+xmlDoc.getElementsByTagName("folder")[i].childNodes[0].nodeValue+"/2_"+xmlDoc.getElementsByTagName("name")[i].childNodes[0].nodeValue+"\" style=\"width:106px;height:65px;border:0px;\" /></div>";
		}else {
			html += "<div class=\"theCatsCenetrRTextSmallPicClose\" onclick=\"makePicDayCats("+numCats+", "+i+", '"+color1+"', '"+color2+"');\" onmouseover=\"DoHidedivs('theCatsCenetrRTextSmallPicCloseAbso2IdIs"+i+"');\" onmouseout=\"Doblockdivs('theCatsCenetrRTextSmallPicCloseAbso2IdIs"+i+"');\" style=\"border-right: 4px solid #"+color2+";\">";
			html += "<div class=\"theCatsCenetrRTextSmallPicCloseAbso\">";
			html += "<div class=\"theCatsCenetrRTextSmallPicCloseAbso1\"><img src=\"/beta/images/pic_day/"+xmlDoc.getElementsByTagName("folder")[i].childNodes[0].nodeValue+"/2_"+xmlDoc.getElementsByTagName("name")[i].childNodes[0].nodeValue+"\" style=\"width:106px;height:65px;border:0px;\" /></div>";
			html += "<div class=\"theCatsCenetrRTextSmallPicCloseAbso2\" id=\"theCatsCenetrRTextSmallPicCloseAbso2IdIs"+i+"\"></div>";
			html += "</div></div>";
		}
	}
	html += "</div>";
	html += "<div id=\"theCatsCenetrRTextBigPic\">";
	html += "<div id=\"theCatsCenetrRTextBigPicAbso\">";
	html += "<div id=\"theCatsCenetrRTextBigPicAbso1\"><img src=\"/beta/images/pic_day/"+xmlDoc.getElementsByTagName("folder")[numShow].childNodes[0].nodeValue+"/1_"+xmlDoc.getElementsByTagName("name")[numShow].childNodes[0].nodeValue+"\" style=\"width:350px;height:201px;border:0px;\" /></div>";
	html += "<div id=\"theCatsCenetrRTextBigPicAbso2\"><div id=\"theCatsCenetrRTextBigPicAbso2ToText\"><span class=\"start12\">"+xmlDoc.getElementsByTagName("text")[numShow].childNodes[0].nodeValue+"</span></div></div>";
	html += "</div></div>";
	document.getElementById("theCatsCenetrRText").innerHTML = html;
}

function loadXMLDoc(fileName) {

	try{
		xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
	} catch(e) {
		try {
			xmlDoc=document.implementation.createDocument("","",null);
		} catch(e) {
			alert(e.message);
		}
	} try {
		xmlDoc.async=false;
		xmlDoc.load(fileName);
		return(xmlDoc);
	} catch(e) {
		alert(e.message);
	}
	return(null);
}

function Doblockdivs(id) {
		document.getElementById(id).style.display = 'block';
}

function openWin(my_var,width,height) {
	window.open(my_var,'ADD','menubar=no,resizable=no,scrollbars=yes,width='+width+',height='+height);
}


function ValidateForm() {
	errors = "";
	if (document.frmAddTalkBack.sender.value.length<2){
		errors = 'يتوجب عليك إدخال اسمك';
	}
	if (document.frmAddTalkBack.comment.value.length<2){
		errors = 'يتوجب عليك إدخال تعقيبك';
	}
	if (errors != ""){
		alert(errors);
		return false;
	}else{
		return true;
	}
}

function confirmLink(theLink, theSqlQuery){
    if (confirmMsg == '' || typeof(window.opera) != 'undefined') {
        return true;
    }
    var is_confirmed = confirm(confirmMsg + ' :\n' + theSqlQuery);
    if (is_confirmed) {
        theLink.href += '&is_js_confirmed=1';
    }
    return is_confirmed;
}

function addComments() {
	var v_op = document.frmAddTalkBack.op.value;
	var v_sender = encodeURIComponent(document.getElementById('sender').value);
	var v_city = encodeURIComponent(document.frmAddTalkBack.city.value);
	var v_comment = encodeURIComponent(document.frmAddTalkBack.comment.value);
	var v_sid = document.frmAddTalkBack.sid.value;
	var v_cid = document.frmAddTalkBack.cid.value;
	var v_for_admin = document.frmAddTalkBack.for_admin.value;
	var v_for_plus = document.frmAddTalkBack.for_plus.value;
	if(v_for_plus == 1) {
		var url = "/?path=plus&sec=comments&op="+v_op+"&sender="+v_sender+"&city="+v_city+"&comment="+v_comment+"&sid="+v_sid+"&cid="+v_cid+"&for_admin="+v_for_admin;
		ajax_loadContent('text_the_article_c_text_comments_into', url, 6);
	}else {
		var url = "/?path=article&sec=comments&op="+v_op+"&sender="+v_sender+"&city="+v_city+"&comment="+v_comment+"&sid="+v_sid+"&cid="+v_cid+"&for_admin="+v_for_admin;
		ajax_loadContent('text_the_article_c_text_comments_into', url, 3);
	}
}


function include(url, containerid){
	var page_request = false;
	if (window.XMLHttpRequest)
		page_request = new XMLHttpRequest();
	else if (window.ActiveXObject){
		try {
			page_request = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e){
			try{
				page_request = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e){}
		}
	}else
		return false;
	page_request.onreadystatechange=function(){
		loadpage(page_request, containerid);
	}
	if (bustcachevar)
		bustcacheparameter=(url.indexOf("?")!=-1)? "&"+new Date().getTime() : "?"+new Date().getTime();
	page_request.open('GET', url+bustcacheparameter, true);
	page_request.setRequestHeader("Content-Type","charset=utf-8");
	page_request.send(null);
}

function loadpage(page_request, containerid){
	if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1))
		document.getElementById(containerid).innerHTML=page_request.responseText;
}

function getCookie(id) {
	if (document.cookie.length>0) {
		c_start=document.cookie.indexOf(id + "=");
		if (c_start!=-1) {
			c_start=c_start + id.length+1 ;
			c_end=document.cookie.indexOf(";",c_start);
			if (c_end==-1) c_end=document.cookie.length
			return unescape(document.cookie.substring(c_start,c_end));
		}
	}
	return "";
}

function setCookie(id,value,expiredays) {
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie=id+ "=" +escape(value)+((expiredays==null) ? "" : "; expires="+exdate.toGMTString());
}

function dropdown(id) {
	if (isdrag==true) {
		isdrag=false;
		dobj = document.getElementById(id);
		tx = parseInt(dobj.style.right+0);
		ty = parseInt(dobj.style.top+0);
		setCookie('AdminTools_x',tx,365);
		setCookie('AdminTools_y',ty,365);
	}
	return false;
}