/* **********************************************************************
 *
 *           Copyright (c) 2002 by MillifoonZillion Software, Inc.
 *                     All rights reserved.
 *
 * **********************************************************************
 *
 * $Workfile: common.js $
 * $Author: Mateusz Karwowski $
 *
 * **********************************************************************/
 
var BrowserDetect = {
  init: function () {
    this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
    this.version = this.searchVersion(navigator.userAgent) || this.searchVersion(navigator.appVersion) || "an unknown version";
    this.OS = this.searchString(this.dataOS) || "an unknown OS";
  },

  searchString: function (data) {
    for (var i=0;i<data.length;i++) {
      var dataString = data[i].string;
      var dataProp = data[i].prop;
      this.versionSearchString = data[i].versionSearch || data[i].identity;
      if (dataString) {
        if (dataString.indexOf(data[i].subString) != -1)
	  return data[i].identity;
      }
      else if (dataProp)
        return data[i].identity;
    }
  },
  
  searchVersion: function (dataString) {
    var index = dataString.indexOf(this.versionSearchString);
    if (index == -1) return;
    return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
  },

  dataBrowser: [
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
BrowserDetect.init();

function getWindowScroll() {
  if (screen.width>1024 && screen.height>768) {
    return "no";
  } else {
    return "auto";
  }  
}

function getWindowSize() {
  if (screen.width>1024 && screen.height>768) {
    if(BrowserDetect.browser=="Explorer") {
      return "fullscreen=1";
    } else {
      return "status=0,toolbar=0,location=0,menubar=0,directories=0,resizable=1,scrollbars=0,height="+screen.height+",width="+screen.width;
    }  
  } else if(screen.width>=1024 && screen.height>=768){
    if(BrowserDetect.browser=="Explorer") {
      return "fullscreen=1";  
    } else {
      return "status=0,toolbar=0,location=0,menubar=0,directories=0,resizable=1,scrollbars=0,height="+screen.height+",width="+screen.width;  
    }  
  }  
  return "";
}

function addressPaste(type) {
  with(document.forms[0]){
    if(type==1) {  
      insertBtn.disabled=false;
    } else if(type==2) {
      insertBtn.disabled=false; 
      insertBtn2.disabled=false;
    } else if(type==3) {
      insertBtn.disabled=false;
    } else {
      insertBtn.disabled=false;
    }  
  }
}  

function addressChange(type) {
  with(document.forms[0]){
    if(type==1) {  
      if(imageurl.value.length>0) insertBtn.disabled=false;
      else insertBtn.disabled=true;
    } else if(type==2) {
      if(videourl.value.length>0) { 
        insertBtn.disabled=false; 
        insertBtn2.disabled=false;
      } else { 
        insertBtn.disabled=true; 
        insertBtn2.disabled=true;
      }
    } else if(type==3){
      if(audiourl.value.length>0) insertBtn.disabled=false;
      else insertBtn.disabled=true;
    } else {
      if(docurl.value.length>0) insertBtn.disabled=false;
      else insertBtn.disabled=true;
    }  
  }   
}

function formatName(name) {
    if(name.length > 40)
        return (name.substr(0,35) + "[...]" + name.substr(name.lastIndexOf("."), name.length));
    else
        return name;
}

function enableSystem(){
  if(document.mainForm.invCode.value=="") {
      alert("Enter Code");
      return;
  }
  document.mainForm.action = "http://www.backend.zap2net.com/esfp";
  document.mainForm.command.value = "enable";
  document.mainForm.submit();
}

function selectFile(no) {
  with(document.forms[0]){
    fid.value = no
    submit()
  }
}

////////////////////// select_document.wm /////////////////////////

function selectDocument() {
  with(document.forms[0]){
    if(type.value == "print") {
      window.opener.document.forms[0].vcPrintAddr.value = docurl.value
      window.opener.document.forms[0].fid_vcPrintAddr.value = fid.value;
    } else {
      window.opener.document.forms[0].vcLinkName.value = docname.value
      window.opener.document.forms[0].vcLinkAddr.value = docurl.value
      window.opener.document.forms[0].fid_vcLinkAddr.value = fid.value;
    }
    self.close();
  }   
}  

////////////////////// insert_video.wm /////////////////////////

function insertVideo_2() {
  with(document.forms[0]){
    if(!checkDQuotes(videourl, "You cannot use quotes in the video address.")) return;
    var selIndex = player.selectedIndex;
    var link = "";
    var time = "";
    if(player[selIndex].value == "0") {
      link = "<object width=\"352\" height=\"290\">"+
             "<param name=\"movie\" value=\""+ownurl.value+"/player_s.swf\"></param>"+
             "<param name=\"path\" value=\""+videourl.value+"\"></param>" +
             "<param name=\"wmode\" value=\"transparent\"></param>" +
             ((imageurl.value.length > 0) ? "<param name=\"image\" value=\""+imageurl.value+"\"></param>" : "") +
             ((length.value.length > 0) ? "<param name=\"time\" value=\""+length.value+"\"></param>" : "") +
             "<param name=\"path\" value=\""+videourl.value+"\"></param>"+
             "<param name=\"allowFullScreen\" value=\"true\"></param>"+
             "<embed src=\""+ownurl.value+"/player_s.swf?path="+videourl.value+
             ((imageurl.value.length > 0) ? "&image="+imageurl.value : "")+
             ((length.value.length > 0) ? "&time="+length.value : "") + "\" "+
             "type=\"application/x-shockwave-flash\" "+
             "allowscriptaccess=\"samedomain\" "+
             "allowfullscreen=\"true\" " +
             "wmode=\"transparent\" " +
             "width=\"352\" "+
             "height=\"290\">"+
             "</embed></object>";
    } else {
      link = "<object width=\"640\" height=\"505\">"+
             "<param name=\"movie\" value=\""+ownurl.value+"/player_l.swf\"></param>"+
             "<param name=\"path\" value=\""+videourl.value+"\"></param>"+
             "<param name=\"wmode\" value=\"transparent\"></param>" +
             ((imageurl.value.length > 0) ? "<param name=\"image\" value=\""+imageurl.value+"\"></param>" : "") +
             ((length.value.length > 0) ? "<param name=\"time\" value=\""+length.value+"\"></param>" : "") +
             "<param name=\"allowFullScreen\" value=\"true\"></param>"+
             "<embed src=\""+ownurl.value+"/player_l.swf?path="+videourl.value+
             ((imageurl.value.length > 0) ? "&image="+imageurl.value : "")+
             ((length.value.length > 0) ? "&time="+length.value : "") + "\" "+
             "type=\"application/x-shockwave-flash\" "+
             "allowscriptaccess=\"samedomain\" "+
             "allowfullscreen=\"true\" " +
             "wmode=\"transparent\" " +
             "width=\"640\" "+
             "height=\"505\">"+
             "</embed></object>";
    }
    link += "<!-- video file: "+ videoname.value + ((imageurl.value.length > 0) ? ("image file: "+ imagename.value) : "") +" -->";
    window.opener.insertLinkAtCaret(window.opener.document.forms[0].txtText,link);
    //self.close();
  }
}
/*
function insertVideo_2() {
  with(document.forms[0]){
    if(!checkDQuotes(videourl, "You cannot use quotes in the video address.")) return;      
    var selIndex = player.selectedIndex;  
    var link = "";
    var time = "";
    if(length.value.length > 0){
      time = "&time="+length.value;
    } 
    if(player[selIndex].value == "0") {  
      if(videourl.value.indexOf("http://www.youtube.com/watch?v=")>-1) {
        swfurl = videourl.value.substr(videourl.value.indexOf("?v")+3, videourl.value.length); 
        link = "<img src='http://www.youtube.com/v/" + swfurl + ".swf' id='youtube_" + swfurl + "' width='352' height='290'><!-- video file: video from www.youtube.com --><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>"    
      } else {
        if(imageurl.value.length > 0) {
          link = "<img src='"+ownurl.value+"/player_s.swf?path="+ videourl.value + time + "&image=" + imageurl.value + "' width='352' height='290'><!-- video file: "+ videoname.value +"; image file: "+ imagename.value +" --><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>"    
        } else {
          link = "<img src='"+ownurl.value+"/player_s.swf?path="+ videourl.value + time +"' width='352' height='290'><!-- video file: "+ videoname.value +" --><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>"    
        }
      }  
    } else {
      if(videourl.value.indexOf("http://www.youtube.com/watch?v=")>-1) {
        swfurl = videourl.value.substr(videourl.value.indexOf("?v")+3, videourl.value.length); 
        link = "<img src='http://www.youtube.com/v/" + swfurl + ".swf' id='youtube_" + swfurl + "' width='640' height='504'><!-- video file: video from www.youtube.com --><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>"      
      } else {  
        if(imageurl.value.length > 0) { 
          link = "<img src='"+ownurl.value+"/player_l.swf?path="+ videourl.value + time + "&image=" + imageurl.value + "' width='640' height='504'><!-- video file: "+ videoname.value +"; image file: "+ imagename.value +" --><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>"      
        } else {
          link = "<img src='"+ownurl.value+"/player_l.swf?path="+ videourl.value + time +"' width='640' height='504'><!-- video file: "+ videoname.value +" --><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>"      
        }
      }  
    }
    window.opener.insertLinkAtCaret(window.opener.document.forms[0].txtText,link);
    self.close();
  }   
}  
*/
function insertVideo_3() {
  with(document.forms[0]){
    if(!checkDQuotes(videourl, "You cannot use quotes in the video address.")) return;         
    var selIndex = player.selectedIndex;  
    var link = "";
    var time = "";
    if(player[selIndex].value == "0") {  
      link = "<a href=\"javascript:showVideoSmall('";
    } else {
      link = "<font color='#0000ff'><u><a href=\"javascript:showVideoLarge('";  
    }
    link += videourl.value+"','"+imageurl.value+"','"+length.value+"')\" style=\"text-decoration:underline;color:#0000ff;\">"+videoname.value+"</a>";
    window.opener.insertLinkAtCaret(window.opener.document.forms[0].txtText,link);
    //self.close();
  }   
}  

function previewKPakVideo(){
  with (document.forms[0]){
    if(ir.selectedIndex == 0) {
      alert("Please select kPak")
      return
    } 
    id = ir[ir.selectedIndex].value
    previewWin = window.open("/player.ws?path="+ownurl.value+"/giri?ID="+id,"previewWin","toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,width=640,height=504,left="+getPosX(640)+",top="+getPosY(504));
    previewWin.focus();
  }
}

function selectKPakVideo(){
  with (document.forms[0]){
    if(ir.selectedIndex == 0) {
      alert("Please select kPak")
      return
    } 
    if(confirm("The video file from selected kPak will be automatically added to Your Resources.\n\nDo you wish to continue?")) {
      command.value += "_ir"
      wait2.style.visibility="visible";
      upload2.disabled=true;
      submit()
    } 
  }  
}

function uploadVideo() {
  with(document.forms[0]){
    if(notValid(documentfile,"Select file."))return
    if(notValidVideo(documentfile,"Check whether the file you want to upload is of FLV format.\nIf yes, rename the file so it will have a proper extension."))return
    encoding = "multipart/form-data"
    command.value += "_upload"
    wait.style.visibility="visible";
    upload.disabled=true;
    submit()
  }
}

function selectCoverImage() {
    openPopUpWin("/insertvres?command=image_cover&sort=1&desc=1&ratio=on",'1','550','700','1','1','cimagewindow');
}

////////////////////// insert_audio.wm /////////////////////////

function insertAudio_2() {
  with(document.forms[0]){
    if(!checkDQuotes(audiourl, "You cannot use quotes in the audio address.")) return;
    var selIndex = player.selectedIndex;
    var link = "";
    if(player[selIndex].value == "0") {
      link = "<embed src=\""+audiourl.value+"\" autostart=\"true\" loop=\"true\" width=\"0\" height=\"0\"></embed>"
    } else if(player[selIndex].value == "1") {
      link = "<object width=\"47\" height=\"23\">"+
             "<param name=\"movie\" value=\""+zap2neturl.value+"/audioplayer.swf\"></param>"+
             "<param name=\"path\" value=\""+audiourl.value+"\"></param>"+
             ((auto.checked) ? "<param name=\"auto\" value=\"1\"></param>" : "")+
             "<param name=\"wmode\" value=\"transparent\"></param>" +
             "<embed src=\""+zap2neturl.value+"/audioplayer.swf?path="+audiourl.value+
             ((auto.checked) ? "&auto=1" : "")+"\" "+
             "type=\"application/x-shockwave-flash\" "+
             "allowscriptaccess=\"samedomain\" "+
             "wmode=\"transparent\" " +
             "width=\"47\" "+
             "height=\"23\">"+
             "</embed></object>";
    } else {
      link = "<a href=\""+audiourl.value+"\">"+ audioname.value +"</a>";
    }
    link += "<!-- audio file: "+ audioname.value +" -->";
    window.opener.insertLinkAtCaret(window.opener.document.forms[0].txtText,link);
    //self.close();
  }
}

function uploadAudio() {
  with(document.forms[0]){
    if(notValid(documentfile,"Select file."))return
    if(notValidAudio(documentfile,"Check whether the file you want to upload is of MP3 or WAV format.\nIf yes, rename the file so it will have a proper extension."))return
    encoding = "multipart/form-data"
    command.value += "_upload"
    wait.style.visibility="visible";
    upload.disabled=true;
    submit()
  }
}

////////////////////// insert_audio_zap.wm /////////////////////////

function insertAudio_3() {
  with(document.forms[0]){
    if(!checkDQuotes(audiourl, "You cannot use quotes in the audio address.")) return;
    window.opener.document.forms[0].audio.value = peek.value;
    window.opener.document.forms[0].audiobtn.value = "Remove";
    self.close();
  }
}

////////////////////// insert_txtbgimage.wm ///////////////////////

function selectTxtBgImage_2() {
  window.opener.document.forms[0].vcTxtImageAddr.value = document.forms[0].imageurl.value;
  window.opener.document.forms[0].fid_vcTxtImageAddr.value = document.forms[0].fid.value;
  window.opener.document.forms[0].txtText.style.backgroundImage = "url('/img/image.jpg')";
  self.close();
}

function removeTxtBgImage() {
  window.opener.document.forms[0].vcTxtImageAddr.value = "";
  window.opener.document.forms[0].fid_vcTxtImageAddr.value = "";
  window.opener.document.forms[0].txtText.style.backgroundImage = "";
  self.close();
}

////////////////////// insert_infoimage.wm ///////////////////////

function selectInfoImage_2() {
  window.opener.document.forms[0].vcImageAddr.value = document.forms[0].imageurl.value;
  window.opener.document.forms[0].iImageType.value = document.forms[0].type.value;
  window.opener.document.forms[0].iImageWidth.value = document.forms[0].width.value;
  window.opener.document.forms[0].iImageHeight.value = document.forms[0].height.value;
  window.opener.document.forms[0].command.value = "saveimagedata";
  window.opener.document.getElementById('savebg').style.visibility = "visible";
  window.opener.document.getElementById('savebox').style.visibility = "visible";
  window.opener.document.forms[0].submit();
  self.close();
}

function showImage3() {
  previewWin = window.open("","previewWin","toolbar=0,location=0,directories=0,status=0,menubar=0,resizable=1,scrollbars=1,width=1024,height=768,left="+getPosX(1024)+",top="+getPosY(768));
  previewWin.document.write("<html><head><title>Preview Window</title></head><body bgcolor='#395563' onLoad='self.focus()'><center><img src="+document.forms[0].imageurl.value+"></center></body></html>");
  previewWin.document.close();
  previewWin.focus();
}

////////////////////// insert_bannerimage.wm ///////////////////////

function selectBannerImage_2() {
  window.opener.document.forms[0].vcBannerAddr.value = document.forms[0].imageurl.value;
  window.opener.document.forms[0].command.value = "savebannerimage";
  window.opener.document.forms[0].submit();
  self.close();
}

function previewBannerImage() {
  previewWin = window.open("","previewWin","toolbar=0,location=0,directories=0,status=0,menubar=0,resizable=0,scrollbars=0,width=300,height=100,left="+getPosX(300)+",top="+getPosY(100));
  previewWin.document.write("<html><head><title>Preview Window</title></head><body bgcolor='#395563' onLoad='self.focus()'><center><img src="+document.forms[0].vcBannerAddr.value+" width='290' height='80'></center></body></html>");
  previewWin.document.close();
  previewWin.focus();
}

////////////////////// insert_cimage.wm ///////////////////////

function selectCoverImage_2() {
  if(!checkDQuotes(document.forms[0].imageurl, "You cannot use quotes in the image address.")) return;  
  var shorturl = document.forms[0].imageurl.value;
  if(shorturl.length > 40) {
    shorturl = shorturl.substring(0, 35) + "...";
  }
  window.opener.document.forms[0].shorturl.value = shorturl;
  window.opener.document.forms[0].imageurl.value = document.forms[0].imageurl.value;
  window.opener.document.forms[0].imagename.value = document.forms[0].imagename.value;
  window.opener.document.getElementById('text1').innerHTML = "<a href='javascript:showImage3()' class='small_a'>"+shorturl+"</a>"
  self.close();
}

////////////////////// insert_link.wm /////////////////////////

function insertLink_2() {
  var address =  ((document.forms[0].address.value.indexOf("http://") >= 0) ? document.forms[0].address.value : ("http://" + document.forms[0].address.value));
  var link = "<a href=\""+ address +"\" target=\"_blank\" style=\"text-decoration:underline;color:#0000ff;display:inline;\">"+ document.forms[0].linktext.value +"</a>"
  window.opener.insertLinkAtCaret(window.opener.document.forms[0].txtText,link);
  self.close();
}  

////////////////////// insert_email.wm /////////////////////////

function insertEmail_2() {
  if((document.forms[0].address.value.length==0) || notValidMail(document.forms[0].address,"ERROR: Correct your email address. ")) return;
  var email = "<a href='mailto:"+ document.forms[0].address.value +"?subject="+ escape(document.forms[0].subject.value) +"'>"+ document.forms[0].address.value +"</a>";
  window.opener.insertLinkAtCaret(window.opener.document.forms[0].txtText,email);
  self.close();
}

////////////////////// insert_image.wm /////////////////////////

function insertImage_2() {
  with(document.forms[0]){
    if(!checkDQuotes(imageurl, "You cannot use quotes in the image address.")) return;    
    var selIndex = align.selectedIndex;
    var link;
    if(imageurl.value.endsWith(".swf") || imagename.value.endsWith(".swf")) {
      
      alert("dupa");

      link = "<p style=\"text-align:"+ align[selIndex].value +";display:inline;\">" +
             "<object width=\""+ width.value +"\" height=\""+ height.value +"\">"+
             "<param name=\"movie\" value=\""+ imageurl.value +"\"></param>"+
             "<param name=\"wmode\" value=\"transparent\"></param>" +
             "<embed src=\""+ imageurl.value +"\" "+
             "type=\"application/x-shockwave-flash\" "+
             "allowscriptaccess=\"samedomain\" "+
             "wmode=\"transparent\" " +
             "width=\""+ width.value +"\" "+
             "height=\""+ height.value +"\">"+
             "</embed></object></p>";
    } else {
      if(align.selectedIndex == 1) {
      link = "<p style=\"text-align:"+ align[selIndex].value +";\"><img src=\""+ imageurl.value +"\" style=\"width:"+ width.value +"px;height="+ height.value +"px;display:inline;\"></p><!-- image file: "+ imagename.value +" -->";
      } else {
       link = "<img src=\""+ imageurl.value +"\" style=\"width:"+ width.value +"px;height="+ height.value +"px;display:inline;\" align=\""+ align[selIndex].value +"\"><!-- image file: "+ imagename.value +" -->";
      }
    }
    window.opener.insertLinkAtCaret(window.opener.document.forms[0].txtText,link);
    //self.close();
  }   
}  

function previewKPakImage(){
  with (document.forms[0]){
    if(ir.selectedIndex == 0) {
      alert("Please select kPak")
      return
    } 
    id = ir[ir.selectedIndex].value
    previewWin = window.open("","previewWin","toolbar=0,location=0,directories=0,status=0,menubar=0,resizable=1,scrollbars="+scroll+",width=1024,height=768,left="+getPosX(1024)+",top="+getPosY(768));
    previewWin.document.write("<html><head><title>Preview Window</title></head><body bgcolor='#395563' onLoad='self.focus()'><center><img src=/giri?ID="+id+"&type="+imagetype[imagetype.selectedIndex].value+" border=0></center></body></html>");
    previewWin.document.close();
    previewWin.focus();
  }
}

function selectKPakImage(){
  with (document.forms[0]){
    if(confirm("The selected image file  will be automatically added to Your Resources.\n\nDo you wish to continue?")) {
      command.value += "_ir"
      wait2.style.visibility="visible";
      upload2.disabled=true;
      submit()
    }  
  }  
}

function uploadImage() {
  with(document.forms[0]){
    if(notValid(documentfile,"Select file."))return
    if(notValidImage(documentfile,"Check whether the file you want to upload is of JPG (JPEG), GIF or PNG format.\nIf yes, rename the file so it will have a proper extension."))return
    encoding = "multipart/form-data"
    command.value += "_upload"
    wait.style.visibility="visible";
    upload.disabled=true;
    submit()
  }
}

////////////////////// select_document.wm //////////////////////

function uploadDocument() {
  with(document.forms[0]){
    if(notValid(documentfile,"Select file."))return
    if(notValidDocument(documentfile,"Check whether the file you want to upload is of PDF, DOC, PPT, XLS, TXT or ZIP format.\nIf yes, rename the file so it will have a proper extension."))return
    encoding = "multipart/form-data"
    command.value += "_upload"
    wait.style.visibility="visible";
    upload.disabled=true;
    submit()
  }
}

////////////////////// change_font.wm /////////////////////////

function changeFont_2() {
  if(!valNoHex(document.forms[0].colorid.value, "ffffff")) {
      alert("Please enter correct font color value, from #000000 to #FFFFFF.")
      return
  }
  if(document.forms[0].size.value.length>0) {
    if(!valNo(document.forms[0].size.value, 100)) {
      alert("Please enter correct font size value, from 0 to 100.")
      return
    }
    window.opener.insertTagAtCaret(window.opener.document.forms[0].txtText,"div style=\"font-size:"+ document.forms[0].size.value +"px;color:"+ document.forms[0].colorid.value.toLowerCase() +";display:inline;\"","div");
  } else {
    window.opener.insertTagAtCaret(window.opener.document.forms[0].txtText,"div style=\"color:"+ document.forms[0].colorid.value.toLowerCase() +";display:inline;\"","div");
  }  
  self.close();
}      

////////////////////// select_txtbgcolor.wm /////////////////////////

function selectTxtBgColor2() {
  if(!valNoHex(document.forms[0].colorid.value, "ffffff")) {
      alert("Please enter correct background color value, from #000000 to #FFFFFF.")
      return
  }
  if(document.forms[0].colorid.value == '#FFFFFF') {
    window.opener.document.forms[0].txtText.style.borderColor = document.forms[0].colorid.value
    window.opener.document.forms[0].txtText.style.borderWidth = 2
    window.opener.document.forms[0].txtText.style.borderStyle = 'inset'
  } else {
    window.opener.document.forms[0].txtText.style.borderColor = document.forms[0].colorid.value
    window.opener.document.forms[0].txtText.style.borderWidth = 4
    window.opener.document.forms[0].txtText.style.borderStyle = 'solid'
  }
  window.opener.document.forms[0].vcTxtColor.value = document.forms[0].colorid.value
  self.close();
}

////////////////////// insert_misel.wm /////////////////////////

function insertMISel_2() {
  var link = "<a href=\"javascript:selectItem('"+ document.forms[0].iMenuItem.value;
  if(document.forms[0].iSubitem.value != "-1") link += ("_" + document.forms[0].iSubitem.value);
  link += ("')\">"+ document.forms[0].text.value + "</a>");
  window.opener.insertLinkAtCaret(window.opener.document.forms[0].txtText,link);
  //self.close();
}  

////////////////////// insert_vdoc.wm /////////////////////////

function insertDocSel_2() {
  var link = "<a href=\"javascript:selectDoc('"+ document.forms[0].vcPeek2.value + "')\">"+ document.forms[0].text.value + "</a>";
  window.opener.insertLinkAtCaret(window.opener.document.forms[0].txtText,link);
  //self.close();
}

////////////////////// add_mi.wm /////////////////////////

function addMI_2(type, edit) {
  with (document.forms[0]){
    if(!valNo(iPosition.value, iLastPosition.value)) {
      alert("Please enter correct " + ((type == 0) ? "Article's" : "Sub-Article's") + " position, from 1 to "+iLastPosition.value+".");
      return
    } 
    if(vcTitle.value.length == 0) {
      alert("Please enter " + ((type == 0) ? "Article's" : "Sub-Article's") + " title.")
      return
    }
    if(!valNoHex(vcColor.value, "ffffff")) {
      alert("Please enter correct hexadecimal Article's Entry color value, from #000000 to #FFFFFF.")
      return
    }

    if((type == 0) && (edit == 0)) {
        window.opener.document.forms[2].command.value = "saveaddmenuitem";

    } else if((type == 0) && (edit == 1)) {
        window.opener.document.forms[2].command.value = "saveeditmenuitem";
        window.opener.document.forms[2].iMenuItem.value = document.forms[0].iMenuItem.value;

    } else if((type == 1) && (edit == 0)) {
        window.opener.document.forms[2].command.value = "saveaddsubitem";
        window.opener.document.forms[2].iMenuItem.value = document.forms[0].iMenuItem.value;

    } else if((type == 1) && (edit == 1)) {
        window.opener.document.forms[2].command.value = "saveeditsubitem";
        window.opener.document.forms[2].iMenuItem.value = document.forms[0].iMenuItem.value;
        window.opener.document.forms[2].iSubitem.value = document.forms[0].iSubitem.value;

    }

    window.opener.document.forms[2].vcPeek.value = document.forms[0].vcPeek.value;
    window.opener.document.forms[2].iLastPosition.value = document.forms[0].iLastPosition.value;
    window.opener.document.forms[2].iFont.value = getFont();
    window.opener.document.forms[2].iPosition.value = document.forms[0].iPosition.value;
    window.opener.document.forms[2].vcTitle.value = document.forms[0].vcTitle.value;
    window.opener.document.forms[2].vcColor.value = document.forms[0].vcColor.value;
    window.opener.document.forms[2].submit();
    window.opener.document.getElementById('savebg').style.visibility = "visible";
    window.opener.document.getElementById('savebox').style.visibility = "visible";
    self.close();
  }
}

function selectItemColor() {
  if(BrowserDetect.browser == "Explorer") {
    openPopUpWin("/actions/select_color.wm",'0','326','420','1','1','colorwindow');
  } else {    
    openPopUpWin("/actions/select_color.wm",'0','326','460','1','1','colorwindow');
  }
}

function selectColor2() {
  window.opener.document.forms[0].vcColor.value = document.forms[0].colorid.value;
  self.close();
}   

function getFont() {
    var fnt = 0;
    if(document.forms[0].bBold.checked) fnt += 1;
    if(document.forms[0].bItalic.checked) fnt += 3;
    if(document.forms[0].bUnderline.checked) fnt += 5;
    return fnt;
}

////////////////////// manage_vres.wm /////////////////////////

function showImage(peek, width, height) {
  var winWidth = width + 20;
  var winHeight = height + 20;
  var scroll = 0;
  if(width > 1024) {
    winWidth = 1024;
    scroll = 1;
  } 
  if(height > 768) { 
    winHeight = 768;
    scroll = 1;
  }
  previewWin = window.open("","previewWin","toolbar=0,location=0,directories=0,status=0,menubar=0,resizable=1,scrollbars="+scroll+",width="+winWidth+",height="+winHeight+",left="+getPosX(winWidth)+",top="+getPosY(winHeight));
  previewWin.document.write("<html><head><title>Preview Window</title></head><body bgcolor='#395563' onLoad='self.focus()'><center><img src="+document.forms[0].zap2neturl.value+"/gr?p="+peek+" border=0 height="+height+" width="+width+"></center></body></html>");
  previewWin.document.close();
  previewWin.focus();
}

function showVideo(peek) {
  previewWin = window.open("/player.ws?path="+document.forms[0].zap2neturl.value+"/gr?p="+peek,"previewWin","toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,width=640,height=504,left="+getPosX(640)+",top="+getPosY(504));
  previewWin.focus();
}

function showAudio(peek) {
  previewWin = window.open("/audioplayer.ws?path="+document.forms[0].zap2neturl.value+"/gr?p="+peek,"previewWin","toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,width=100,height=50,left="+getPosX(100)+",top="+getPosY(50));
  previewWin.focus();
}

function showFlash(peek, width, height) {
  var winWidth = width + 20;
  var winHeight = height + 20;
  var scroll = 0;
  if(width > 1024) {
    winWidth = 1024;
    scroll = 1;
  }
  if(height > 768) {
    winHeight = 768;
    scroll = 1;
  }
  previewWin = window.open("/flash.ws?path="+document.forms[0].zap2neturl.value+"/gr?p="+peek+"&width="+width+"&height="+height,"previewWin","toolbar=0,location=0,directories=0,status=0,menubar=0,resizable=1,scrollbars="+scroll+",width="+winWidth+",height="+winHeight+",left="+getPosX(winWidth)+",top="+getPosY(winHeight));
  previewWin.focus();
}

function showResult(){
  alert(document.forms[0].result.value);
}    

function deleteFile(no){
  with (document.forms[0]){
    if(!confirm("Are you sure, you want to delete this file?")) return
    command.value = "delete"
    fid.value = no
    submit()
  }
}

function downloadFile(no){
  location.href="/downfile?id="+no
}

function uploadFile2(){
  with(document.forms[0]){
    if(notValid(documentfile,"Select file."))return;
    if(ftype.value=="1") {
        if(notValidImage2(documentfile,"Check whether the file you want to upload is of JPG (JPEG), GIF or PNG format.\nIf yes, rename the file so it will have a proper extension."))return;
    } else if(ftype.value=="4") {
        if(notValidVideo2(documentfile,"Check whether the file you want to upload is of FLV or MP4 format.\nIf yes, rename the file so it will have a proper extension."))return;
    } else if(ftype.value=="6") {
        if(notValidDocument(documentfile,"Check whether the file you want to upload is of TXT, DOC, PDF, PPT, XLS or ZIP format.\nIf yes, rename the file so it will have a proper extension."))return;
    } else if(ftype.value=="12") {
        if(notValidAudio(documentfile,"Check whether the file you want to upload is of MP3 or WAV.\nIf yes, rename the file so it will have a proper extension."))return;
    } else if(ftype.value=="21") {
        if(notValidAnimation(documentfile,"Check whether the file you want to upload is of SWF format.\nIf yes, rename the file so it will have a proper extension."))return;
    }
    encoding = "multipart/form-data";
    command.value = "uploadfile";
    wait.style.visibility = "visible";
    upload.disabled = true;
    submit();
  }
}

function sortFileList(no) {
  with(document.forms[0]){
    if(desc.value == "1") desc.value = "0"    
    else desc.value = "1"    
    sort.value = no
    submit()
  }  
}

function changeFType(no) {
  with(document.forms[0]){
    ftype.value = no;
    submit();
  }
}

function changeView() {
  with(document.forms[0]){
    if(thumb.value == "1") thumb.value = "0"    
    else thumb.value = "1"    
    submit()
  }  
}

function previewKPakFile(){
  with (document.forms[0]){
    if(ir.selectedIndex == 0) {
      alert("Please select kPak")
      return
    } 
    id = ir[ir.selectedIndex].value
    type = imagetype[imagetype.selectedIndex].value
    if(type == "Video") {
        previewWin = window.open("/player.ws?path="+ownurl.value+"/giri?ID="+id,"previewWin","toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,width=640,height=504,left="+getPosX(640)+",top="+getPosY(504));
    } else {
      previewWin = window.open("/giri?ID="+id+"&type="+imagetype[imagetype.selectedIndex].value,"previewWin","toolbar=0,location=0,directories=0,status=0,menubar=0,resizable=1,scrollbars=1,width=1024,height=768,left="+getPosX(1024)+",top="+getPosY(768));
    }
    previewWin.focus();
  }
}

function uploadKPakFile(){
  with (document.forms[0]){
    command.value = "uploadirfile"
    wait2.style.visibility="visible";
    upload2.disabled=true;
    submit()
  }  
}

function confFileUpload(no, oldsize, newsize) {
  with (document.forms[0]){
    // 1 $ per 100 MB
    if(confirm("The uploaded file increased your vResources size over the current limit of "+ oldsize +" MB.\nTo keep the file, the size limit of your vResources must be increased to "+ newsize +" MB.\nIf you accept this size increase, your account will be charged $"+ (5 * Number(newsize)) / 100 +" (USD) per month until the limit changes.\n\nIf you accept vResources size increase and new charges click \"OK\" button.\nIf you want to keep the current limit and remove the file press \"Cancel\" button.")) return
      command.value = "cancelupload"
      fid.value = no  
      submit()
  }
}

function confFileUpload2(no, oldsize, newsize) {
  with (document.forms[0]){
    // 1 $ per 100 MB
    if(confirm("The uploaded file increased your vResources size over the current limit of "+ oldsize +" MB.\nTo keep the file, the size limit of your vResources must be increased to "+ newsize +" MB.\nIf you accept this size increase, your account will be charged $"+ (5 * Number(newsize)) / 100 +" (USD) per month until the limit changes.\n\nIf you accept vResources size increase and new charges click \"OK\" button.\nIf you want to keep the current limit and remove the file press \"Cancel\" button.")) return
      command.value += "_cancelupload"
      fid.value = no  
      submit()
  }
}

function showResLink(peek, name) {
  link = "http://www.zap2net.com/gr?p="+peek
  if(BrowserDetect.browser == "Explorer") {
    linkWindow = window.open("/doc.ws", "linkWindow", "status=0,toolbar=0,location=0,menubar=0,directories=0,resizable=0,scrollbars=0,width=800,height=290,left="+getPosX(800)+",top="+getPosY(290));
  } else {
    linkWindow = window.open("/doc.ws", "linkWindow", "status=0,toolbar=0,location=0,menubar=0,directories=0,resizable=0,scrollbars=0,width=800,height=290,left="+getPosX(800)+",top="+getPosY(290));
  }  
  linkWindow.document.writeln("<html><head><title>vResources - Editor of Virtual Resources</title><meta http-equiv='Content-Type' content='text/html; charset=UTF-8'><link rel='Stylesheet' type='text/css' href='/common/style1.css'>");
  linkWindow.document.writeln("<script language='JavaScript' type='text/javascript'>");
  linkWindow.document.writeln("<!--");
  linkWindow.document.writeln("function showHelp(){");
  linkWindow.document.writeln("link = \"http://www.zap2net.com/gr?p=B1b6JcKPXOO-M2DB\";");
  linkWindow.document.writeln("helpwindow = window.open(link+\"&s=3_1\",\"helpwindow\",\"status=0,toolbar=0,location=0,menubar=0,directories=0,resizable=0,scrollbars=0,width=990,height=900\");");
  linkWindow.document.writeln("helpwindow.focus();");
  linkWindow.document.writeln("}");
  linkWindow.document.writeln("/-->");
  linkWindow.document.writeln("</script></head>");
  linkWindow.document.writeln("<body bgcolor='#eeeeee'>");
  linkWindow.document.writeln("<table cellpadding='0' cellspacing='0' border='0' width='100%'>");
  linkWindow.document.writeln("<tr><td align='right'><a href=\"javascript:showHelp()\">Help</a>&nbsp;&nbsp;&nbsp;&nbsp;</td></tr></table>");
  linkWindow.document.writeln("<h2 class='h2a'>RESOURCE LINK</h2>");
  linkWindow.document.writeln("<form><fieldset style='margin-left:5px;margin-right:5px;margin-top:5px;'><legend>Resource Link:</legend>");
  linkWindow.document.writeln("<table cellpadding='1' cellspacing='0' border='0' width='710' align='center'>");
  linkWindow.document.writeln("<tr><td>&nbsp;</td></tr>");
  linkWindow.document.writeln("<tr><td>Link to post in Emails, Documents and Browsers (URL):</td><tr>"); 
  linkWindow.document.writeln("<tr><td><input type='text' class='b_1' value='"+link+"' style='width:700px' readonly></td></tr>"); 
  linkWindow.document.writeln("<tr><td>&nbsp;</td></tr>");
  linkWindow.document.writeln("<tr><td>Link to post on Websites and in vDocs and vBooks (HTML):</td></tr>");
  linkWindow.document.writeln("<tr><td><input type='text' class='b_1' value='<a href=\""+link+"\" target=\"_blank\">"+name+"</a>' style='width:700px' readonly></td></tr>"); 
  linkWindow.document.writeln("<tr><td>&nbsp;</td></tr>");
  linkWindow.document.writeln("<tr><td>Peek Code:</td></tr>"); 
  linkWindow.document.writeln("<tr><td><input type='text' class='b_1' value='"+peek+"' style='width:350px' readonly></td></tr>"); 
  linkWindow.document.writeln("<tr><td>&nbsp;</td></tr>");
  linkWindow.document.writeln("<tr><td align='center'><input type='Button' class='b_1' value='Close' onclick='self.close()'></td></tr>");
  linkWindow.document.writeln("<tr><td>&nbsp;</td></tr></table></fieldset></form></body></html>");
  linkWindow.document.close();
  linkWindow.focus();
}

////////////////////// show_link ////////////////////////////

function refreshLink(link) {
  window.opener.document.forms[0].command.value = "selectsi";
  window.opener.document.forms[0].vcPeek2.options[window.opener.document.forms[0].vcPeek2.selectedIndex].value = link
  window.opener.document.forms[0].submit();
}

function showLink() {
  with (document.forms[0]){ 
    openPopUpWin("/editvbook?command=showlink&vcPeek="+vcPeek.value,'0','800','300','1','1','linkwindow');
  }
}

////////////////////// edit_vbook.wm /////////////////////////

function addToWeb(){
  with (document.forms[0]){
    command.value = "addtoweb";
    window.document.getElementById('savebg').style.visibility = "visible";
    window.document.getElementById('savebox').style.visibility = "visible";
    submit()
  }
}

function switchVDoc(){
  with (document.forms[0]){
    command.value = "switchvdoc";
    window.document.getElementById('savebg').style.visibility = "visible";
    window.document.getElementById('savebox').style.visibility = "visible";
    submit();
  }
}

function hideHeader(){
   with (document.forms[0]){
    command.value = "hideheader";
    window.document.getElementById('savebg').style.visibility = "visible";
    window.document.getElementById('savebox').style.visibility = "visible";
    submit();
  }
}

function selectVbook(){
  with (document.forms[0]){
    command.value = "selectvbook";
    iSubitem.value = "-1";
    window.document.getElementById('savebg').style.visibility = "visible";
    window.document.getElementById('loadbox').style.visibility = "visible";
    submit();
  }  
}

function saveVbook(type){
  with (document.forms[0]){
    if(!checkDQuotes(vcName, "You cannot use quotes in " + ((type==1) ? "vDocument's" : "vBook's") + " title.")) return;
    command.value = "savevbook";
    window.document.getElementById('savebg').style.visibility = "visible";
    window.document.getElementById('savebox').style.visibility = "visible";
    submit()
  }  
}

function addVbook(){
  with (document.forms[0]){
    if(vcName.value.length == 0) {
      alert("Please enter document's name.");
      return
    }
    command.value = "addvbook";
    iMenuItem.value = "-1";
    iSubitem.value = "-1";
    window.document.getElementById('savebg').style.visibility = "visible";
    window.document.getElementById('savebox').style.visibility = "visible";
    submit();
  }  
}

function deleteVbook(type){
  with (document.forms[0]){
    if(!confirm("Are you sure, you want to delete this " + ((type==1) ? "vDocument" : "vBook") + "?")) return;
    command.value = "deletevbook";
    iMenuItem.value = "-1";
    iSubitem.value = "-1";
    window.document.getElementById('savebg').style.visibility = "visible";
    window.document.getElementById('savebox').style.visibility = "visible";
    submit();
  }  
}

function selectMI(){
  with (document.forms[0]){
    command.value = "selectmi";
    iSubitem.value = "-1";
    window.document.getElementById('savebg').style.visibility = "visible";
    window.document.getElementById('loadbox').style.visibility = "visible";
    submit();
  }  
}

function selectSI(){
  with (document.forms[0]){
    command.value = "selectsi";
    window.document.getElementById('savebg').style.visibility = "visible";
    window.document.getElementById('loadbox').style.visibility = "visible";
    submit();
  }  
}

function addMI(){
  with (document.forms[0]){ 
    if(BrowserDetect.browser == "Explorer") {
      openPopUpWin("/editvbook?command=addmenuitem&vcPeek="+vcPeek.value,'0','430','225','1','1','AddMI');
    } else {
      openPopUpWin("/editvbook?command=addmenuitem&vcPeek="+vcPeek.value,'0','418','220','1','1','AddMI');
    }
  }  
}
   
function editMI(){
  with (document.forms[0]){ 
    var selIndex = iMenuItem.selectedIndex;
    if(BrowserDetect.browser == "Explorer") {
      openPopUpWin("/editvbook?command=editmenuitem&vcPeek="+vcPeek.value+"&iMenuItem="+iMenuItem[selIndex].value,'0','418','225','1','1','AddMI');
    } else {
      openPopUpWin("/editvbook?command=editmenuitem&vcPeek="+vcPeek.value+"&iMenuItem="+iMenuItem[selIndex].value,'0','418','220','1','1','AddMI');
    }
  }  
}

function deleteMI(){
  with (document.forms[0]){
    if(!confirm("Are you sure, you want to delete this Article?")) return;
    command.value = "deletemenuitem";
    iSubitem.value = "-1";
    window.document.getElementById('savebg').style.visibility = "visible";
    window.document.getElementById('savebox').style.visibility = "visible";
    submit();
  }  
}

function addSI(){
  with (document.forms[0]){ 
    var selIndex = iMenuItem.selectedIndex;
    if(BrowserDetect.browser == "Explorer") {
      openPopUpWin("/editvbook?command=addsubitem&vcPeek="+vcPeek.value+"&iMenuItem="+iMenuItem[selIndex].value,'0','418','225','1','1','AddSI');
    } else {
      openPopUpWin("/editvbook?command=addsubitem&vcPeek="+vcPeek.value+"&iMenuItem="+iMenuItem[selIndex].value,'0','418','220','1','1','AddSI');
    }
  }  
}
   
function editSI(){
  with (document.forms[0]){ 
    var selIndex1 = iMenuItem.selectedIndex;
    var selIndex2 = iSubitem.selectedIndex;
    if(selIndex2 == 0) {
        alert("Please select Sub-Article");
        return;
    }
    if(BrowserDetect.browser == "Explorer") {
      openPopUpWin("/editvbook?command=editsubitem&vcPeek="+vcPeek.value+"&iMenuItem="+iMenuItem[selIndex1].value+"&iSubitem="+iSubitem[selIndex2].value,'0','418','225','1','1','AddSI');
    } else {
      openPopUpWin("/editvbook?command=editsubitem&vcPeek="+vcPeek.value+"&iMenuItem="+iMenuItem[selIndex1].value+"&iSubitem="+iSubitem[selIndex2].value,'0','418','220','1','1','AddSI');
    }
  }  
}

function deleteSI(){
  with (document.forms[0]){
    if(iSubitem.selectedIndex == 0) {
        alert("Please select Sub-Article");
        return;
    }  
    if(!confirm("Are you sure, you want to delete this Sub-Article?")) return;
    command.value = "deletesubitem";
    window.document.getElementById('savebg').style.visibility = "visible";
    window.document.getElementById('savebox').style.visibility = "visible";
    submit();
  }  
}

function selectInfoImage(){
  with (document.forms[0]){ 
    if(vcImageAddr.value!="") {
      openPopUpWin("/insertvres?command=image_info&sort=1&desc=1&ratio=on&itype="+iType.value+"&imageurl="+vcImageAddr.value+"&width="+iImageWidth.value+"&height="+iImageHeight.value+"&ext=1",'1','550','700','1','1','imagewindow');
    } else {
      openPopUpWin("/insertvres?command=image_info&sort=1&desc=1&ratio=on&itype="+iType.value,'1','550','700','1','1','imagewindow');
    }
  }  
}

function showImage4(link, width, height) {
  previewWin = window.open("","previewWin","toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1");
  previewWin.document.write("<html><head><title>Preview Window</title></head><body bgcolor='#395563' onLoad='self.focus()'><center><img src="+link+" width="+width+" height="+height+"></center></body></html>");
  previewWin.document.close();
  previewWin.focus();
}

function removeInfoImage() {
  with (document.forms[0]){
    if(!confirm("Are you sure, you want to remove this image?")) return;
    command.value = "removeinfoimage";
    window.document.getElementById('savebg').style.visibility = "visible";
    window.document.getElementById('savebox').style.visibility = "visible";
    submit();
  }  
}

function selectBannerImage(){
  with (document.forms[0]){
    if(vcBannerAddr.value!="") {
      openPopUpWin("/insertvres?command=image_banner&sort=1&desc=1&ratio=on&imageurl="+vcBannerAddr.value+"&fid="+fid_vcBannerAddr.value+"&ext=1",'1','550','700','1','1','imagewindow');
    } else {
      openPopUpWin("/insertvres?command=image_banner&sort=1&desc=1&ratio=on",'1','550','700','1','1','imagewindow');
    }
  }
}

function removeBannerImage() {
  with (document.forms[0]){
    if(!confirm("Are you sure, you want to remove this image?")) return;
    command.value = "removebannerimage";
    window.document.getElementById('savebg').style.visibility = "visible";
    window.document.getElementById('savebox').style.visibility = "visible";
    submit();
  }
}
/*
function saveDesc() {
  with (document.forms[0]){
    if(!checkDQuotes(print, "You cannot use quotes in the publish document address.")) return;
    if(!checkDQuotes(linkaddr, "You cannot use quotes in \"More info\" document address.")) return;
    command.value = "savedescription"
    submit()
  }  
}
*/
function enlargeDesc(){
  with (document.forms[0]){
    command.value = "enlargedescription";
    window.document.getElementById('savebg').style.visibility = "visible";
    window.document.getElementById('loadbox').style.visibility = "visible";
    submit();
  }
}

function minimizeDesc(){
  with (document.forms[0]){
    command.value = "minimizedescription";
    window.document.getElementById('savebg').style.visibility = "visible";
    window.document.getElementById('loadbox').style.visibility = "visible";
    submit();
  }
}

function showResult(){
  alert(document.forms[0].result.value);
}  

function manageVRes(){
  openPopUpWin("/managevres?command=show&sort=1&desc=1&thumb=0&ftype=6",'1','620','700','1','1','ManageVRes');
}

function storeCaret(textEl) {
 if(BrowserDetect.browser == 'Explorer') {
    if(textEl.createTextRange) 
      textEl.caretPos = document.selection.createRange().duplicate();
  }   
}
  
function getSelection(textEl) {
  if(BrowserDetect.browser == 'Explorer') {
    if(textEl.createTextRange && textEl.caretPos) {
      return textEl.caretPos.text;
    }
  } else {
    return textEl.value.substring(textEl.selectionStart, textEl.selectionEnd);
  }  
}

function insertLinkAtCaret(textEl, link) {
  if(BrowserDetect.browser == 'Explorer') {
    if(textEl.createTextRange && textEl.caretPos) {
      var caretPos = textEl.caretPos;
      caretPos.text = link;
      textEl.focus();
      textEl.caretPos.select();
    }  
  } else {
    if((textEl.selectionStart <= textEl.value.length) && (textEl.selectionStart <= textEl.value.length)) {
      var start = textEl.selectionStart;
      var tag_length = link.length;
      var scrollTop = textEl.scrollTop; 

      var text = textEl.value.substring(0,textEl.selectionStart) + link + 
                 textEl.value.substring(textEl.selectionEnd , textEl.value.length);
        
      textEl.value = text;     
      textEl.selectionStart = start + tag_length;
      textEl.selectionEnd = textEl.selectionStart;
      textEl.scrollTop = scrollTop;
      textEl.focus();
    }
  } 
}

function insertTagAtCaret(textEl, openTag, closeTag) {
  if(BrowserDetect.browser == 'Explorer') {
    if(textEl.createTextRange && textEl.caretPos) {
      var caretPos = textEl.caretPos;
      caretPos.text = '<' + openTag + '>' + caretPos.text + ((closeTag=="div") ? "&nbsp;" : "") + '</' + closeTag + '>';
      textEl.focus();
      textEl.caretPos.select();
    }  
  } else {
    if((textEl.selectionStart <= textEl.value.length) && (textEl.selectionStart <= textEl.value.length)) {
      var start = textEl.selectionStart;
      var tag_length = new String('<' + openTag + '>' + textEl.value.substring(textEl.selectionStart, textEl.selectionEnd) + '</' + closeTag + '>').length;
      var scrollTop = textEl.scrollTop; 

      var text = textEl.value.substring(0,textEl.selectionStart) + 
                 '<' + openTag + '>' + textEl.value.substring(textEl.selectionStart, textEl.selectionEnd) + 
                 '</' + closeTag + '>' + textEl.value.substring(textEl.selectionEnd , textEl.value.length);
        
      textEl.value = text;     
      textEl.selectionStart = start + tag_length;
      textEl.selectionEnd = textEl.selectionStart;
      textEl.scrollTop = scrollTop;
      textEl.focus();
    }
  } 
}
  
function openVbook(peek, selectID) {
  if (screen.width>=1024 && screen.height>=960){	
    openPopUpWin("/vbook.ws?p="+peek+"&s="+selectID,'0','990','900','0','1','vbookwindow');
  } else {
    openPopUpWin("/vbook.ws?p="+peek+"&s="+selectID,'1',(screen.width > 1024 ? 1024 : screen.width),screen.height,'0','1','vbookwindow');
  }
}

function changeFont() {
  openPopUpWin("/editvbook?command=changefont",'0','326',(BrowserDetect.browser == "Explorer") ? '480' : '520','1','1','fontwindow');
}

function selectTxtBgColor() {
  openPopUpWin("/editvbook?command=selecttxtbgcolor",'0','326',(BrowserDetect.browser == "Explorer") ? '420' : '460','1','1','txtbgcolorwindow');
}

function selectTxtBgImage(){
  with (document.forms[0]){ 
    if(vcTxtImageAddr.value!="") {
      openPopUpWin("/insertvres?command=image_txtbg&sort=1&desc=1&ratio=on&itype="+iType.value+"&header="+bHeader.value+"&imageurl="+vcTxtImageAddr.value+"&fid="+fid_vcTxtImageAddr.value+"&ext=1",'1','550','700','1','1','txtimagewindow');
    } else {
      openPopUpWin("/insertvres?command=image_txtbg&sort=1&desc=1&ratio=on&itype="+iType.value+"&header="+bHeader.value,'1','550','700','1','1','imagewindow');
    }
  }  
}

function insertLink() {
  openPopUpWin("",'0','326','195','1','1','ilinkwindow');
  document.forms[1].command.value = "insertlink";
  document.forms[1].text.value = getSelection(document.forms[0].txtText);
  document.forms[1].target = "ilinkwindow";
  document.forms[1].submit();
}

function insertEmail() {
  openPopUpWin("",'0','326','195','1','1','iemailwindow');
  document.forms[1].command.value = "insertemail";
  document.forms[1].text.value = getSelection(document.forms[0].txtText);
  document.forms[1].target = "iemailwindow";
  document.forms[1].submit();
}

function insertZAP() {
  if(BrowserDetect.browser == "Explorer") {
    openPopUpWin("/insertzap?command=zap",'0','430','210','1','1','izapwindow');
  } else {
    openPopUpWin("/insertzap?command=zap",'0','418','215','1','1','izapwindow');
  }
}

function showListKPak(sort) {
  listWindow=window.open("/kpaklist?ss=1&sort="+sort+"&desc=0","listWindow","toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=1,resizable=1,width=565,height=700,left="+getPosX(565)+",top="+getPosY(700));
  listWindow.focus();
}

function insertImage() {
  openPopUpWin("/insertvres?command=image&sort=1&desc=1&ratio=on",'1','550','700','1','1','imagewindow');
}

function insertVideo() {
  openPopUpWin("/insertvres?command=video&sort=1&desc=1",'1','550','700','1','1','videowindow');
}

function insertAudio() {
  openPopUpWin("/insertvres?command=audio&sort=1&desc=1",'1','550','700','1','1','audiowindow');
}

function insertAudioZap() {
  if(document.forms[0].audiobtn.value == "Add") {
    openPopUpWin("/insertvres?command=audio_zap&sort=1&desc=1",'1','550','700','1','1','audiozapwindow');
  } else {
    document.forms[0].audio.value = "";
    document.forms[0].audiobtn.value = "Add";
  }
}

function insertMISel() {
  if(BrowserDetect.browser == "Explorer") {
    openPopUpWin("",'0','430','200','1','1','selectmiwindow');
  } else {
    openPopUpWin("",'0','418','205','1','1','selectmiwindow');
  }
  document.forms[1].command.value = "insertmisel";
  document.forms[1].text.value = getSelection(document.forms[0].txtText);
  document.forms[1].vcPeek.value = document.forms[0].vcPeek.value;
  document.forms[1].target = "selectmiwindow";
  document.forms[1].submit();

}

function insertDocSel() {
  if(BrowserDetect.browser == "Explorer") {
    openPopUpWin("",'0','430','175','1','1','selectdocwindow');
  } else {
    openPopUpWin("",'0','418','185','1','1','selectdocwindow');
  }
  document.forms[1].command.value = "insertdocsel";
  document.forms[1].text.value = getSelection(document.forms[0].txtText);
  document.forms[1].vcPeek.value = document.forms[0].vcPeek.value;
  document.forms[1].target = "selectdocwindow";
  document.forms[1].submit();

}

function selectPDocument() {
  with (document.forms[0]){
    openPopUpWin("/insertvres?command=document&type=print&sort=1&desc=1&fid="+fid_vcPrintAddr.value,'1','550','700','1','1','documentwindow');
  }  
}

function selectIDocument() {
  with (document.forms[0]){
    openPopUpWin("/insertvres?command=document&type=info&sort=1&desc=1&fid="+fid_vcLinkAddr.value,'1','550','700','1','1','documentwindow');
  }
}

//////////////////////////////////////////////////////////

function showHelp(selectID){
  openVbook('B1b6JcKPXOO-M2DB', selectID);  
}

function getPosX(width) {
  return (screen.width - width) / 2;
}

function getPosY(height) {
  return (screen.height - height) / 2;
}

function openPopUpWin(){
  PopUpWinArgs = openPopUpWin.arguments
  if(PopUpWinArgs[0]) docName = PopUpWinArgs[0]; else docName = ""
  if(PopUpWinArgs[1]) winScrollbars = PopUpWinArgs[1]; else winScrollbars = 1
  if(PopUpWinArgs[2]) winWidth = PopUpWinArgs[2]; else winWidth = 550
  if(PopUpWinArgs[3]) winHeight = PopUpWinArgs[3]; else winHeight = 400
  if(PopUpWinArgs[4]) winStatus = PopUpWinArgs[4]; else winStatus = 1
  if(PopUpWinArgs[5]) winResizable = PopUpWinArgs[5]; else winResizable = 0
  if(PopUpWinArgs[6]) winName = PopUpWinArgs[6]; else winName = "PopUpWin"

  PopUpWinProp="toolbar=0,location=0,directories=0,status="+winStatus+",menubar=0,scrollbars="+winScrollbars+",resizable="+winResizable+",width="+winWidth+",height="+winHeight+",left="+getPosX(winWidth)+",top="+getPosY(winHeight)+",screenX=0,screenY=0";
  PopUpWin=window.open(docName,winName,PopUpWinProp);
  PopUpWin.focus();
}

function checkDQuotes(){
  checkDQuotesArgs = checkDQuotes.arguments  
  if(checkDQuotesArgs[0].value.indexOf("\"") > (-1)) {
    alert(checkDQuotesArgs[1])
    return false;
  }
  return true;
}

function valNo(No, max){
  if(No == "") return false
  for (i = 0;i < No.length;i++)
    if ((No.charAt(i) < "0") || (No.charAt(i) > "9")) return false
  if(parseInt(No) > parseInt(max)) return false
  return true
}

function valNoHex(No, max){
  if((No == "")||(No.substr(0,1) != "#")) {
    return false
  } 
  
  No = No.toLowerCase()
  for (i = 1;i < No.length;i++) {
    var code = No.charCodeAt(i)
    if((code < 48) || ((code>57) && (code<97)) || (code>102)) {
      return false
    }
  }
  if(parseInt(No.substr(1),16) > parseInt(max,16)) {
    return false
  }
  return true
}

function valNoMinus(No){
  if(No == "") return false
  if( ((No.charAt(0) < "0") || (No.charAt(0) > "9")) && (No.charAt(0) != "-")) return false
  for (i = 1;i < No.length;i++)
    if ((No.charAt(i) < "0") || (No.charAt(i) > "9")) return false
  return true
}

function onlyDigits(field){
  return
  fieldTMP = ""
  for(i=0;i<field.value.length;i++){
    charTMP = field.value.charAt(i)
    if((charTMP >= "0") && (charTMP <= "9"))
      fieldTMP = fieldTMP + charTMP
  }    
  field.value = fieldTMP
}

function notValid(){
  notValidArgs = notValid.arguments
  if(notValidArgs[0].type == "select-one"){if(notValidArgs[0].selectedIndex != 0) return false}
  if(notValidArgs[0].type == "select-multiple"){ if(notValidArgs[0].selectedIndex != -1) return false}
  if((notValidArgs[0].type == "text") || (notValidArgs[0].type == "hidden") || (notValidArgs[0].type == "password") || (notValidArgs[0].type == "file") || (notValidArgs[0].type == "textarea")){if(notValidArgs[0].value != "") return false}
  if(notValidArgs[1]){
    alert(notValidArgs[1])
    notValidArgs[0].focus()
  }  
  return true;
}

function notValidFile(){
  notValidFileArgs = notValidFile.arguments
  ext=notValidFileArgs[0].value.substring(notValidFileArgs[0].value.lastIndexOf(".")+1,notValidFileArgs[0].value.length).toUpperCase()
  if(ext=="JPEG" || ext=="JPG" || ext=="JPE" || ext=="GIF" || ext=="PNG" || ext=="FLV" || ext=="MP4" || ext=="SWF" || ext=="TXT" || ext=="DOC" || ext=="PDF" || ext=="PPT" || ext=="XLS" || ext=="MP3" || ext=="WAV" || ext=="ZIP")return false
  if(notValidFileArgs[1]){
    alert(notValidFileArgs[1])
    notValidFileArgs[0].focus()
  }
  return true;
}

function notValidImage(){
  notValidImageArgs = notValidImage.arguments
  ext=notValidImageArgs[0].value.substring(notValidImageArgs[0].value.lastIndexOf(".")+1,notValidImageArgs[0].value.length).toUpperCase()
  if(ext=="JPEG" || ext=="JPG" || ext=="JPE" || ext=="SWF")return false
  if(notValidImageArgs[1]){
    alert(notValidImageArgs[1])
    notValidImageArgs[0].focus()
  }  
  return true;
}

function notValidImage2(){
  notValidImage2Args = notValidImage2.arguments
  ext=notValidImage2Args[0].value.substring(notValidImage2Args[0].value.lastIndexOf(".")+1,notValidImage2Args[0].value.length).toUpperCase()
  if(ext=="JPEG" || ext=="JPG" || ext=="JPE" || ext=="GIF" || ext=="PNG")return false
  if(notValidImage2Args[1]){
    alert(notValidImage2Args[1])
    notValidImage2Args[0].focus()
  }
  return true;
}

function notValidDocument(){
  notValidDocumentArgs = notValidDocument.arguments
  ext=notValidDocumentArgs[0].value.substring(notValidDocumentArgs[0].value.lastIndexOf(".")+1,notValidDocumentArgs[0].value.length).toUpperCase()
  if(ext=="PDF" || ext=="DOC" || ext=="PPT" || ext=="XLS" || ext=="TXT" || ext=="ZIP")return false
  if(notValidDocumentArgs[1]){
    alert(notValidDocumentArgs[1])
    notValidDocumentArgs[0].focus()
  }  
  return true;
}

function notValidVideo(){
  notValidVideoArgs = notValidVideo.arguments
  ext=notValidVideoArgs[0].value.substring(notValidVideoArgs[0].value.lastIndexOf(".")+1,notValidVideoArgs[0].value.length).toUpperCase()
  if(ext=="FLV")return false
  if(notValidVideoArgs[1]){
    alert(notValidVideoArgs[1])
    notValidVideoArgs[0].focus()
  }  
  return true;
}

function notValidVideo2(){
  notValidVideo2Args = notValidVideo2.arguments
  ext=notValidVideo2Args[0].value.substring(notValidVideo2Args[0].value.lastIndexOf(".")+1,notValidVideo2Args[0].value.length).toUpperCase()
  if(ext=="FLV" || ext=="MP4")return false
  if(notValidVideo2Args[1]){
    alert(notValidVideo2Args[1])
    notValidVideo2Args[0].focus()
  }
  return true;
}

function notValidAudio(){
  notValidAudioArgs = notValidAudio.arguments
  ext=notValidAudioArgs[0].value.substring(notValidAudioArgs[0].value.lastIndexOf(".")+1,notValidAudioArgs[0].value.length).toUpperCase()
  if(ext=="MP3" || ext=="WAV")return false
  if(notValidAudioArgs[1]){
    alert(notValidAudioArgs[1])
    notValidAudioArgs[0].focus()
  }
  return true;
}

function notValidAnimation(){
  notValidAnimationArgs = notValidAnimation.arguments
  ext=notValidAnimationArgs[0].value.substring(notValidAnimationArgs[0].value.lastIndexOf(".")+1,notValidAnimationArgs[0].value.length).toUpperCase()
  if(ext=="SWF")return false
  if(notValidAnimationArgs[1]){
    alert(notValidAnimationArgs[1])
    notValidAnimationArgs[0].focus()
  }
  return true;
}

function notValidInc(){ //object, error message, max value, is madatory
  notValidIncArgs = notValidInc.arguments
  if(notValidIncArgs[1]) errMsg = notValidIncArgs[1]; else errMsg = "Enter correct value"
  if(notValidIncArgs[3]){
    if(notValidIncArgs[3] == 1) madatory = true; else madatory = false
  }else madatory = false
  if(!madatory && (notValidIncArgs[0].value == "")) return false
  
  if(notValidIncArgs[2]) maxValue = notValidIncArgs[2]; else maxValue = 10000000

  if(valNo(notValidIncArgs[0].value)){
    if(!madatory){
      if(notValidIncArgs[0].value < maxValue) return false
    }else{
      if((notValidIncArgs[0].value < maxValue) && (notValidIncArgs[0].value > 0)) return false
    }  
  }  

  alert(errMsg)
  notValidIncArgs[0].focus()

  return true;
}

function notValidMail(){
  notValidMailArgs = notValidMail.arguments
  if(notValidMailArgs[1]) errMsg = notValidMailArgs[1]; else errMsg = "Enter correct e-mail address"
  if(notValidMailArgs[2]){
    if(notValidMailArgs[2] == 1) madatory = true; else madatory = false
  }else madatory = false
  if(madatory && (notValidMailArgs[0].value != "") && checkMail(notValidMailArgs[0].value)) return false
  if(!madatory && checkMail(notValidMailArgs[0].value)) return false
  alert(errMsg)
  notValidMailArgs[0].focus()
  return true;
}

function checkMail(mail){
  if(mail.length < 6) return false;
  if(mail.indexOf("@") == -1) return false;
  if((mail.indexOf("(") > -1)||(mail.indexOf(")") > -1)||(mail.indexOf("[") > -1)||
     (mail.indexOf("]") > -1)||(mail.indexOf("\\") > -1)||(mail.indexOf(";") > -1)||
     (mail.indexOf(":") > -1)||(mail.indexOf(",") > -1)||(mail.indexOf("<") > -1)||
     (mail.indexOf(">") > -1)||(mail.indexOf(" ") > -1)) return false

  mailHost = mail.substring(mail.indexOf("@")+1,mail.length);
  if(mailHost.indexOf(".") == -1) return false;
  return true;
}

String.prototype.endsWith = function(str){return (this.match(str+"$")==str)}
