var iframeWin = null;
var BmEdit =null;

function getScrollXY() {
var scrOfX = 0, scrOfY = 0;
if( typeof( window.pageYOffset ) == 'number' ) {
scrOfY = window.pageYOffset; scrOfX = window.pageXOffset;
} else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
scrOfY = document.body.scrollTop; scrOfX = document.body.scrollLeft;
} else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
scrOfY = document.documentElement.scrollTop; scrOfX = document.documentElement.scrollLeft;
}
//window.alert( 'Horizontal scrolling = ' + scrOfX + '\nVertical scrolling = ' + scrOfY );
return scrOfY;
}

function openWindowIframe(tit,url) {

ScrollY = getScrollXY()+10;

if (!iframeWin) {
iframeWin = Zapatec.Window.setup({
left:280,
top:ScrollY,
width:750,
height: 500,
iframeContent : true,
onClose : function() {iframeWin = null;},
title: tit,
theme: 'osx',
urlContent : url
});

} else {
iframeWin.show();
}
}

function openWindowIframeMail() {
var win = null;
var title=getTitle();

cont="<div id=sendmail><input type=text  id=inputmail    name=send       value=\"Ваш e-mail\" onclick=this.value='' /><input type=submit id=sendtext  name=submit value=\"Отправить текст\" onclick=sendMAIL() /><input type=submit  id=sendlink name=submit value=\"Отправить ссылку\"  onclick=sendMAIL('link') /><div style=\"padding-top:20px\" id=\"placeholder\"></div</div>";
if (!win) {
win = Zapatec.Window.setup({
left:580,
top:200,
width:450,
height: 10,
canResize : false,
showStatus: false,
showMaxButton:false,
showMinButton:false,
title: 'Отправка e-mail', 
theme: 'osx',
onClose : function() {win = null;},
content : cont
});
} else {
win.show();
}
}



function openWindowDIV() {
var win = null;
var title=getTitle();
re =/\s/g
title=title.replace(re,'&nbsp;');
cont="<input id=bm_text2 name=bm_name2  type=text value="+  title  + " >" + "<input id=bm_sub type=button  value=\"В закладки\" onClick=bookmarking_good('it') ><br /><div id=\"status\">&nbsp;</div>"
if (!win) {
win = Zapatec.Window.setup({
left:280,
top:200,
width:650,
height: 10,
canResize : false,
showStatus: false,
showMaxButton:false,
showMinButton:false,
theme: 'osx',
onClose : function() {win = null;},
content : cont
});
} else {
win.show();
}
}

function ee(){
alert('asdf')
}


function openWindowBM(title) {
var win2 = null;
title=getBmCaption(title)
cont="<input id=bm_text2 name=bm_name_ed  type=text value="+  title[1]  + " >" + "<input id=bm_sub type=button  value=\"Изменить\" onclick=bm_rename(\"bm_text2\",\""+title[0]+"\",\""+title[1]+"\")>"
if (!win2) {
win2 = Zapatec.Window.setup({
left:20,
top:20,
width:650,
height: 10,
canResize : false,
showStatus: false,
showMaxButton:false,
showMinButton:false,
theme: 'osx',
onClose : function() {win = null;},
content : cont
});
} else {
win2.show();
}
}


function openWindowDel(title) {
var win2 = null;
title=getBmCaption(title)
cont="<span id=bm_text2>"+  title[1]  + "</span >" + "<input id=bm_sub type=button  value=\"Удалить\" onclick=bm_delete(\"bm_text2\",\""+title[0]+"\""+")>"
if (!win2) {
win2 = Zapatec.Window.setup({
left:20,
top:20,
width:650,
height: 10,
canResize : false,
showStatus: false,
showMaxButton:false,
showMinButton:false,
theme: 'osx',
onClose : function() {win = null;},
content : cont
});
} else {
win2.show();
}
}

function sendMAIL(flag){
	var url='/.cmsc/modules/pagemail/index.php';
	var email=document.getElementById('inputmail').value;
	var pars='email=' + email+ '&flag=' + flag;
	    //alert(pars)
	var  my = new Ajax.Request(url, {method: 'post', parameters: pars, onFailure: reportError, onComplete: send_ok});
}
					
				
function send_ok(originalRequest){
    $('placeholder').innerHTML=originalRequest.responseText;
}
						

function getBmCaption(id){
bm=new Array(2)
bm[0]=document.getElementById(id).href
if(bm[1]=document.getElementById(id).innerText) return bm
else {bm[1]=document.getElementById(id).text;return bm }


}

function getTitle(){
var dd=document.getElementsByTagName("title")[0].text;
return dd;
}



function getBmText(id){
   
return document.getElementById(id).value;
   }
	   
	   




function openWindowIframeBM() {
if (!iframeWin) {
iframeWin = Zapatec.Window.setup({
left:580, 
top:200, 
width:400, 
height: 10,
canResize : false,
showStatus: false,
showMaxButton:false,
showMinButton:false,
iframeContent : true,
onClose : function() {iframeWin = null;},
title: 'My Bookmarks', 
theme: 'osx',
urlContent : "/.cmsc/modules/pcabinet/bookmarks/bookmark_it.php"
});
} else {
iframeWin.show();
}
}







function i_html(){
el=document.getElementById("bm")
if (!el.hasChildNodes()){
ifr = document.createElement("iframe");
document.getElementById("bm").appendChild(ifr);
ifr.src='show_bookmarks.php'
ifr.width='180'
ifr.height='300'
}
else
 el.removeChild(el.firstChild);
 

}

function bookmarking_good(action){
	var bm_title=getBmText('bm_text2'); 
	var  url='/.cmsc/modules/pcabinet/bookmarks/func.php';
	var  pars='action='+ action + '&bm_title='+bm_title;
	var  my = new Ajax.Request(url, {method: 'post', parameters: pars, onFailure: reportError, onComplete: ok});
}

function bm_rename(id,key_url,name){
	var  bm_title=getBmText(id); 
	var  url='/.cmsc/modules/pcabinet/bookmarks/func.php';
	var  pars='action=rename'+ '&key_url=' + key_url+'&bm_title='+bm_title;
	var  my = new Ajax.Request(url, {method: 'post', parameters: pars, onFailure: reportError, onComplete: ok});
	setTimeout("document.location.reload()",100)
	$('zpWin0Container').style.display='none'
}

function bm_delete(id,key_url){
	var  url='/.cmsc/modules/pcabinet/bookmarks/func.php';
	var  pars='action=del'+ '&key_url=' + key_url;
	var  my = new Ajax.Request(url, {method: 'post', parameters: pars, onFailure: reportError, onComplete: ok});
	setTimeout("document.location.reload()",100)
	$('zpWin0Container').style.display='none'
}


function bookmarking(action){
openWindowDIV()       
}

function ok(originalRequest){
	$('status').innerHTML=originalRequest.responseText;
}

function reportError(request)
{
	alert('Sorry. There was an error.');
}

//--------------------------------------------------------
