var ie=document.all;
var nn6=document.getElementById&&!document.all;
var isdrag=false;
var x,y;
var dobj;
var lx, ly;
var confirmMsg  = 'هل حقا تود حذف';
var currentFontSize = 11;
var MicroscopeCounter = 1;
var SizeFactor = 3;
var MaxMicroscope	= 5;

function MSIE_VER() {
	agt=navigator.userAgent.toLowerCase();
	pos=agt.indexOf('msie')+1;
	if(pos)return agt.charAt(pos+4);
	return 0;
}


function addComments() {
	var v_op = document.frmAddTalkBack.op.value;
	var v_sender = document.frmAddTalkBack.sender.value;
	var v_mail = document.frmAddTalkBack.mail.value;
	var v_city = document.frmAddTalkBack.city.value;
	var v_show_mail = document.frmAddTalkBack.show_mail.value;
	var v_comment = document.frmAddTalkBack.comment.value;
	var v_sid = document.frmAddTalkBack.sid.value;
	var v_cid = document.frmAddTalkBack.cid.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+"&mail="+v_mail+"&city="+v_city+"&show_mail="+v_show_mail+"&comment="+v_comment+"&sid="+v_sid+"&cid="+v_cid;
	}else {
		var url = "?path=article&sec=comments&op="+v_op+"&sender="+v_sender+"&mail="+v_mail+"&city="+v_city+"&show_mail="+v_show_mail+"&comment="+v_comment+"&sid="+v_sid+"&cid="+v_cid;
	}
	ajax_loadContent('inAddComments', url, 3, 0, 0);
}

function showBan(divName,width,height,wmode,src,spec,xparams)
{
	var d=document.getElementById(divName);
	d.innerHTML='<OBJECT '+spec+' classid=clsid:D27CDB6E-AE6D-11cf-96B8-444553540000 codebase=http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0	 WIDTH='+width+' HEIGHT='+height+'><PARAM NAME=movie VALUE="'+src+'"><PARAM NAME=wmode value='+wmode+'><PARAM NAME=quality VALUE=high><PARAM NAME=AllowScriptAccess VALUE=always>'+xparams+'<EMBED src="'+src+'" quality=high WIDTH='+width+' HEIGHT='+height+' WMODE='+wmode+' AllowScriptAccess=always TYPE=application/x-shockwave-flash PLUGINSPAGE=http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash  type=application/x-shockwave-flash></EMBED></OBJECT>';
}

function ZoomPic(my_var) {

	window.open(my_var,'ZoomPic','menubar=no,resizable=yes,scrollbars=yes,width=640,height=550');
}
function displayeffect(){
	if(document.body.clientWidth <= 1005){
		var dcOzen = document.getElementById('left_big_banner');
		dcOzen.style.display = 'none';
		dcHidden = true;
	}
	else if(document.body.clientWidth > 1005){
		var dcOzen = document.getElementById('left_big_banner');
		dcOzen.style.display = 'block';
		dcHidden = false;
	}
}

function changecolor(id,onw){
	if(onw == 0){
		document.getElementById(id).style.background = "#C6ED80";
	}else if(onw == 1){
		document.getElementById(id).style.background = "#F2F7E9";
	}
}

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 ValidateForm_samsem(url, var1, var1, for_admin)
{
	errors = "";
	if (document.frmAddTalkBack2.sender.value.length<2){
		errors = "يتوجب عليك إدخال اسمك";
	}
	if (document.frmAddTalkBack2.subject.value.length<2){
		errors = "يتوجب عليك إدخال موضوع";
	}
	if (errors != ""){
		alert(errors);
		return false;
	}else {
		ajax_loadContent('alert_c_c', url, var1, var1, for_admin);
		return false;
	}

}

function allComments(id) {
	w=465;
	h=465;
	l=(screen.availWidth - w)/2;
	t=(screen.availHeight - h)/2;
	url = '?path=article&sec=comments&op=allComments&id='+id;
	Features = 'width='+w+',height='+h+',left='+l+',top='+t+',scrollbars=yes';
	var x = window.open(url,'ShowComments',Features)
}

function DisplayFlash(adname, width, height,IsTrans,style){

		if(style==undefined)
			style = ''

		document.write("<OBJECT " + style + " CLASSID='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0' ID='"+adname+"_66' WIDTH='"+width+"' HEIGHT='"+height+"'>\n");
		document.write("<PARAM NAME='movie' VALUE='"+adname+"'>");
		document.write("<PARAM NAME=play VALUE=true>");
		document.write("<PARAM NAME=loop VALUE=true>");
		document.write("<PARAM NAME=menu VALUE=false>");
		document.write("<PARAM NAME=wmode VALUE=transparent>");
		document.write("<PARAM NAME=quality VALUE=high>");
		document.write("<EMBED wMode='transparent' SRC='"+adname+"' id='"+adname+"_60' type=application/x-shockwave-flash  SWLiveConnect=TRUE play=true loop=false menu=false  WIDTH='"+width+"' HEIGHT='"+height+"' quality=best bgcolor=#ffffff loop=true pluginspage='http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash'></EMBED></OBJECT>")

}

function dcOnResizes(){
	if(!dcHidden && document.body.clientWidth <= 990){
		dcHidden = true;
		var dcOzen = document.getElementById('left_big_banner');
		dcOzen.style.display = "none";
	}
	else if(dcHidden && document.body.clientWidth > 990){
		dcHidden = false;
		var dcOzen = document.getElementById('left_big_banner');
		dcOzen.style.display = "inline";
	}
}

function chnDivChat() {
	include('/?path=admin&op=chnDivChat', 1);
}

function chnDivChatOnline() {
	include('/?path=admin&op=ChatOnlineDiv', 2);
}

function AddChat(inputItem) {
	with (inputItem.form) {
  		if (inhalt.value != "") {
   			include('?path=admin&op=AddChat&inhalt='+inhalt.value, 1);
   			inhalt.value = '';
		}
	}
}

function showComment(id){
	if(document.getElementById(id).style.display == "none"){
		document.getElementById(id).style.display = "block";
	} else{
		document.getElementById(id).style.display = "none";
	}
}

function changeFontSizeObj(Obj, maximize) {
	if (Obj && Obj.style.fontSize) {
		theFontSize = parseInt(Obj.style.fontSize);
		if (maximize == 1) {
			Obj.style.fontSize = theFontSize + SizeFactor;
		} else {
			Obj.style.fontSize = theFontSize - SizeFactor;
		}
	} else if (Obj) {
		temp = currentFontSize + 'px';
		Obj.style.fontSize = temp;
	}
}

function changeFontSize(containerObj, maximize) {
	changeFontSizeObj(containerObj, maximize);
	var tagsTypes = new Array("DIV", "FONT", "A", "TD", "P");
	if (maximize == 1) {
		currentFontSize = currentFontSize + SizeFactor;
		MicroscopeCounter++;
	} else {
		currentFontSize = currentFontSize - SizeFactor;
		MicroscopeCounter--;
	}
	var tagsNum = 0
	for (var i = 0; i < tagsTypes.length; i++) {
		elements = containerObj.getElementsByTagName(tagsTypes[i]);
		for (var j = 0; (node = elements.item(j)); j++) changeFontSizeObj(node, maximize);
	}
	if (MicroscopeCounter == MaxMicroscope) {
		document.getElementById('increase').style.display = 'none'
	} else if (MicroscopeCounter == 1) {
		document.getElementById('decrease').style.display = 'none'
	} else {
		document.getElementById('increase').style.display = 'inline'
		document.getElementById('decrease').style.display = 'inline'
	}
}
		
function openWin(my_var,width,height) {
	window.open(my_var,'ADD','menubar=no,resizable=no,scrollbars=yes,width='+width+',height='+height);
}

function emptyChat() {
	include('/?path=admin&op=emptychnDivChat', 1);
}


function shortcut(sc) {
    if (!sc) { return; }
    code = sc;
    form = document.forms['frmAddTalkBack'];
    if (form['comment'].createTextrange && form['comment'].caretPos) {
    var caretPos = form['comment'].caretPos;
    caretPos.text = code;
    } else { form['comment'].value += code; }
    form['comment'].focus();
    setTimeout('form["shortc"].options[0].selected = true',10);
}

function chnage_bg(id, check, name){
	obj=document.getElementById (id);
 	if(check){
		obj.style.background="url('http://www.samsem.net/includes/templates/images/samsem/"+name+"_onmouseover.png')";
 	}else{
		obj.style.background="url('http://www.samsem.net/includes/templates/images/samsem/"+name+"_onmouseout.png')";
 	}
}

function DoHidedivs(id) {
		document.getElementById(id).style.display = 'none';
}

function Doblockdivs(id) {
		document.getElementById(id).style.display = 'block';
}

function getCookie(c_name) {
	if (document.cookie.length>0) {
		c_start=document.cookie.indexOf(c_name + "=");
		if (c_start!=-1) {
			c_start=c_start + c_name.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 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 setCookie(c_name ,value)  {
	var date = new Date();
	date.setTime(date.getTime()+(1*24*60*60*1000));
	var expires = date.toGMTString();
	document.cookie = +c_name+'='+tx+'; expires='+ expires +';';
}

function movemouse(e) {
	if (isdrag) {
		lx = nn6 ? tx + e.clientX - x : tx + event.clientX - x;
		ly  = nn6 ? ty + e.clientY - y : ty + event.clientY - y;
		var	max_x = document.body.clientWidth - (document.getElementById('admin_box').clientWidth + 17);
		var	max_y = document.body.clientHeight - (document.getElementById('admin_box').clientHeight + 17);
		if (lx < 0) lx = 0;
		if (lx > max_x) lx = max_x;
		if (ly < 0) ly = 0;
		dobj.style.left = lx;
		dobj.style.top  = ly;
		return false;
	}
}

function selectmouse(e) {
	var fobj = nn6 ? e.target : event.srcElement;
	var topelement = nn6 ? "HTML" : "BODY";
	while (fobj.tagName != topelement && fobj.className != "dragme") {
		fobj = nn6 ? fobj.parentNode : fobj.parentElement;
	}
	if (fobj.className=="dragme") {
		isdrag = true;
		dobj = fobj;
		tx = parseInt(dobj.style.left+0);
		ty = parseInt(dobj.style.top+0);
		x = nn6 ? e.clientX : event.clientX;
		y = nn6 ? e.clientY : event.clientY;
		document.onmousemove=movemouse;
		return false;
	}
}

function dropdown() {
	if (isdrag==true) {
		isdrag=false;
		var date = new Date();
		date.setTime(date.getTime()+(1*24*60*60*1000));
		var expires = date.toGMTString();
		var fobj = nn6 ? e.target : event.srcElement;
		var topelement = nn6 ? "HTML" : "BODY";
		while (fobj.tagName != topelement && fobj.className != "dragme") {
			fobj = nn6 ? fobj.parentNode : fobj.parentElement;
		}
		dobj = fobj;
		tx = parseInt(dobj.style.left+0);
		ty = parseInt(dobj.style.top+0);
		document.cookie = 'AdminTools_x='+tx+'; expires='+ expires +';';
		document.cookie = 'AdminTools_y='+ty+'; expires='+ expires +';';
	}
}

document.onmousedown=selectmouse;
document.onmouseup=dropdown;

