/*
 * function for disable&enable form elements, because old NS browsers don't support disable method.
 * Example of usage:
 * DisableControl("form_name.element_name", false);
 * First parameter - form name and el.name as string, second true or false
 * variable oldNSbr may be used from other js scripts to detect browser versions
 */

var oldNSbr = (((navigator.appName == "Netscape") ? true : false) && (parseInt(navigator.appVersion.charAt(0)) < 5));
var DisabledControls = new Array();

if(oldNSbr){
  window.captureEvents(Event.CLICK | Event.FOCUS);
  window.onclick = clickHandler;
  window.onfocus = focusHandler;
}

if (typeof xmlDoc== 'undefined'){

        var xmlDoc, loadStatus;
        var lang="en";
        var xmlFile = "../Admin/Langs-"+lang+".xml";
        if (window.ActiveXObject){
            xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
            xmlDoc.async="false";
            xmlDoc.onreadystatechange=verify;
            loadStatus = xmlDoc.load(xmlFile);
            
        }else {
            xmlDoc=document.implementation.createDocument("","",null)
            if (xmlDoc.load) 
                loadStatus = xmlDoc.load(xmlFile);
            else {
                if (window.XMLHttpRequest) {
                    xmlDoc = new XMLHttpRequest();
                    if (xmlDoc) {
                        xmlDoc.open("GET", xmlFile, false);
                        xmlDoc.onreadystatechange= function(){
                            if (xmlDoc.readyState == 4) {
                             if (xmlDoc.status == 200) {
                                    xmlDoc = xmlDoc.responseXML;
                                    loadStatus=true;
                              }}
                        }
                          xmlDoc.send();
                   }
                }
            }            
        }

        function loadXML(tag){
            var sRez='';
           
            if (loadStatus){
                xmlObj=xmlDoc.documentElement;
                if (xmlObj) 
                  if (xmlObj.getElementsByTagName(tag).item(0))
                    if (window.ActiveXObject)
                        sRez = xmlObj.getElementsByTagName(tag).item(0).text;
                    else
                        sRez = xmlObj.getElementsByTagName(tag).item(0).textContent;
                        
            } 
            return sRez;
        }  
        function verify()
        {
         // 0 Object is not initialized
         // 1 Loading object is loading data
         // 2 Loaded object has loaded data
         // 3 Data from object can be worked with
         // 4 Object completely initialized
         if (xmlDoc.readyState != 4)
         {
           return false;
         }
        }
        
 }
 
function focusHandler(e){
  var routeFlag = false;
  if(!e.target.form) routeFlag = true;
  else{
    var CtrlType = e.target.type;
    if(CtrlType == "button" || CtrlType == "checkbox" || CtrlType == "radio") routeFlag = true;
    else{
      var aCtrl = String(e.target.form.name) + "." + String(e.target.name);
      if(!isDisabled(aCtrl)){
        routeFlag = true;
      }
    }
  }

  if(routeFlag){
    window.routeEvent(e);
    return true;
  }
  else{
    if(String(CtrlType).indexOf("select") != -1){
      var selBox = document.forms[e.target.form.name].elements[e.target.name];
      for(var i=0;i<selBox.options.length;i++){
        if(selBox.options[i].selected) selBox.options[i].selected = true;
      }
    }
    document.forms[e.target.form.name].elements[e.target.name].blur();
    alert("This control is disabled in this context!");
    return false;
  }
}

function clickHandler(e){
//////////////////////////////////////
//  Index Detection for InputArray's
//  the element must have: onfocus="i", where i is the element index in the InputArray :((((
//////////////////////////////////////
//  var boza = String(e.target.onfocus);
//  var start = boza.indexOf("{");
//  var end = boza.indexOf("}");
//  boza = boza.substr(start+1,end-start-1);
//  alert(parseInt(boza));
///////////////////////////////////////
  var routeFlag = false;
  if(!e.target.form) routeFlag = true;
  else{
    var aCtrl = String(e.target.form.name) + "." + String(e.target.name);
    if(!isDisabled(aCtrl)){
      routeFlag = true;
    }
  }

  if(routeFlag){
    window.routeEvent(e);
    return true;
  }
  else{
    alert("This control is disabled in this context!");
    return false;
  }
}

function DisableControl(someCtrl,aBool){
  if (typeof(someCtrl) == "object") {  // case when aCtrl is an object
      var stmp = "";
      if (isNaN(someCtrl.length) )
           stmp = ""+someCtrl.form.name + "."+someCtrl.name
         else
           if (someCtrl.length < 2 || someCtrl.type == "button" || someCtrl.type == "select-one" || someCtrl.type == "text" || someCtrl.type == "hidden")
                 stmp = ""+someCtrl.form.name + "."+someCtrl.name
              else
                 stmp = ""+someCtrl[0].form.name + "."+someCtrl[0].name
      var aCtrl = stmp;
  }
  else var aCtrl = someCtrl;

  if(oldNSbr){
    if(aBool){
      if(isDisabled(aCtrl)) return;
      else{
        DisabledControls[DisabledControls.length] = aCtrl;
      }
    }
    else{
      for(var i=0;i<DisabledControls.length;i++){
        if(String(DisabledControls[i]) == String(aCtrl)){
          DisabledControls.splice(i,1);
          break;
        }
      }
    }
  }
  else{
    var dotPos = String(aCtrl).indexOf(".");
    var aForm = String(aCtrl).substr(0,dotPos);
    var aControl = String(aCtrl).substr(dotPos+1,String(aCtrl).length-dotPos);
    if(document.forms){
      if(document.forms[aForm]){
        if(document.forms[aForm].elements){
          if(document.forms[aForm].elements[aControl]){
                  if ((isNaN(document.forms[aForm].elements[aControl].length)) || (String(document.forms[aForm].elements[aControl].type).indexOf("select") != -1)){

                      document.forms[aForm].elements[aControl].disabled = aBool;}
                   else
                      for (var i = 0; i < document.forms[aForm].elements[aControl].length; i++)
                        document.forms[aForm].elements[aControl][i].disabled = aBool;
          }
        }
      }
    }
  }
}

function isDisabled(aCtrl){
  if(oldNSbr){
    for(var i=0;i<DisabledControls.length;i++){
      if(String(DisabledControls[i]) == String(aCtrl)) return true;
    }
    return false;
  }
  else{
    var dotPos = String(aCtrl).indexOf(".");
    var aForm = String(aCtrl).substr(0,dotPos);
    var aControl = String(aCtrl).substr(dotPos+1,String(aCtrl).length-dotPos);
    if(document.forms){
      if(document.forms[aForm]){
        if(document.forms[aForm].elements){
          if(document.forms[aForm].elements[aControl]){
            return document.forms[aForm].elements[aControl].disabled;
          } else return false;
        } else return false;
      } else return false;
    } else return false;
  }
}

// end function DisableControl

//********************************************************************************************************************************

/*
 * Functions for get and set a form elements values
 * Parameters:
 * get function - object element (format document.form_name.element.name)
 * set functions - first parameter - object element, second - value that would be set, may be a multiple values, separated with ","
 *
 * They are group by element type
 */



// common functions for get and set a form element value
// first check the type of object and then call an appropriate function  ***************************************************
function getElementValue(obj) {
  if (obj == null)  return "";	
  var sElType= "" + obj.type;
  if (""+obj.length !="undefined" && sElType == "undefined") // when object is a array of objects - radio button for example
  	sElType= "" + obj[0].type;     // get a type of first element


  var sResult ;
  switch (sElType)
  {
	case "radio"			: sResult = getRadiobtn(obj);break;					//radio button
	case "text"			: sResult = getTextbox(obj);break;					//text box
	case "hidden"			: sResult = getTextbox(obj);break;
	case "textarea"			: sResult = getTextbox(obj);break;					//text area
	case "button"			: sResult = getTextbox(obj);break;					//button value
	case "checkbox"			: //check box
							  if (""+obj.length !="undefined")  // when object is a array of check boxes
									sResult = getSetCheckbox(obj) // return values separated by "," as string
								else
								    sResult = getCheckbox(obj)  // return true if check box is selected
							  break;
	case "select-one"		: sResult = getListbox(obj);break;					//list box with single selection
	case "select-multiple"	: sResult = getMultipleListvalue(obj);break;		//list box with multiple selection
	default				: sResult = getTextbox(obj);break;

  }

  return sResult;
}
function setElementValue(obj,val) {
  // val would be a multiple values, separated with ","
  if (obj == null)  return ;	
  var sElType= "" + obj.type;
  if (""+obj.length !="undefined" && sElType == "undefined") // when object is a array of objects - radio button for example
  	sElType= "" + obj[0].type;     // get a type of first element


  switch (sElType)
  {
	case "radio"			: setRadiobtn(obj,val);break;					//radio button
	case "text"			: setTextbox(obj,val);break;	//text box
	case "hidden"			: setTextbox(obj,val);break;
	case "textarea"			: setTextbox(obj,val);break;					//text area
	case "button"			: sResult = setTextbox(obj,val);break;			//button value
	case "checkbox"			: //check box
							  if (""+obj.length !="undefined")				// when object is a array of check boxes
									setSetCheckbox(obj,val)					// set values separated by "," as string
								else
								    setCheckbox(obj,val)					// set check box when val is a true
							  break;
	case "select-one"		: setListbox(obj,val);break;					//list box with single selection
	case "select-multiple"	: setListbox(obj,val);break;			//list box with multiple selection
	default					: setTextbox(obj,val);break;

  }

  return true;
}
// end common functions ************************************************************************************************

// text box and text area
function getTextbox(obj) {
    return Trim_String(obj.value);
}
function setTextbox(obj,val) {
	obj.value = Trim_String(val);
}

// Radio button
function getRadiobtn(obj) {
    var rez = "";
    if (""+obj.length != "undefined")
    {
	  	for (var i = 0; i < obj.length; i++)
      		if (obj[i].checked)
        		rez = "" + obj[i].value     ;
    }else{
		 if (obj.checked)
         	rez = "" + obj.value     ;
	}
     return rez;
}
function setRadiobtn(obj,val) {
	for (var i = 0; i < obj.length; i++) {
		if (obj[i].value == val) {
			obj[i].checked = true;
			return true;
		}

	}
}

// Check button
function getCheckbox(obj){
  if (obj.checked)
     return obj.value;
   else
     return "";
}
// get a set of check boxes with same name, but different values
function getSetCheckbox(obj){
   var rz = "";
   for (var j = 0; j < obj.length; j++)
		if (obj[j].checked )
		    rz += "," + obj[j].value ;
   if (rz.length > 0)
	        rz = rz.substring(1,rz.length);
   return rz

}
function setCheckbox(obj,val) {
   if (val && val != " ")
		obj.checked = true;
     else
	    obj.checked = false;
}
function setSetCheckbox(obj,val) {
   if (val.length > 0 ) {
        var arValues = val.split(",");
        for (var i = 0; i < obj.length; i++) {
		    obj[i].checked = false;
            for (var j = 0; j < arValues.length; j++)
			    if (obj[i].value == arValues[j])
			       obj[i].checked = true;


	    }

   }
}

// List box

function getListbox(obj){
  var sResult = "";
  if (obj != null)
	sResult = obj.options[obj.selectedIndex].value			
  return sResult;
}
function getListboxtext(obj){
  return obj.options[obj.selectedIndex].text;
}
function getMultipleListvalue(obj){
    var rz = "";
    for (var j = 0; j < obj.options.length; j++)
		if (obj.options[j].selected )
		    rz += "," + obj.options[j].value ;

	if (rz.length > 0)
	       rz = rz.substring(1,rz.length);
	return rz
 }
function setListbox(obj,val) {
    listvalue = "" + val;

    if (listvalue.indexOf(",") == -1){
    	for (var j = 0; j < obj.options.length; j++)
		   if (obj.options[j].value == listvalue) {
			obj.selectedIndex = j;
            obj.options[j].selected = true;
		   }
        }
	   else {
         var ar = listvalue.split(",");
         for (var j = 0; j < obj.options.length; j++) {
              obj.options[j].selected = false;
              for (var i = 0; i < ar.length; i++)
		           if (obj.options[j].value == ar[i])
		      		      obj.options[j].selected = true;

		 }
	}
}
// add new list items from array
function addListItems(obj,ar,v) {

		targetLength = obj.options.length;
			//Remove all options
			while (obj.options.length > 0) {
				obj.options[obj.options.length-1] = null;
			}
		    //add new options
		for (var i = 0; i < ar.length-1; i = i+2) {
			obj.options[obj.options.length] = new Option(ar[i + 1],ar[i]);
			if(v) if(v==ar[i]) obj.options[obj.options.length-1].selected = true
			}
 }

// end functions for get and set values of form elements



// other useful functions

// function for remove blank space before and after strings
function Trim_String(txtobjvalue) {
	var ichar, icount;
	var strValue = txtobjvalue;
	ichar = strValue.length - 1;
	icount = -1;
	while (strValue.charAt(ichar)==' ' && ichar > icount)
		--ichar;
	if (ichar!=(strValue.length-1))
		strValue = strValue.slice(0,ichar+1);
	ichar = 0;
	icount = strValue.length - 1;
	while (strValue.charAt(ichar)==' ' && ichar < icount)
		++ichar;
	if (ichar!=0)
		strValue = strValue.slice(ichar,strValue.length);
	return strValue;
}

// function for check string for minimal length
function checkTextLength(obj,lmt) {
  if (obj.value.length < lmt ){
     obj.focus();
     alert("This field required " + lmt + " symbols at least")
     return false;
   }
   else
     return true;
}

// function for alerting user when leave page
function alertUser(bIsPageSubmitted) {

    if (!bIsPageSubmitted) {
        if (confirm("Are you sure?\nYou will lost your changes.")){            
            document.forms[0].submit();
            return true;
        } else {
            return false;    
        }    
    }
    return true;
}
// function for show image thumbnail
function showThumb(objSelect,strThumbs, divName) {
    if (divName == null)        divName = "thumbs3";
    if (objSelect.selectedIndex == -1) return false;
    var thumbid = getListbox(objSelect);
    if (thumbid == "")  {
        writeInDIV("","",divName);
        return false;
    }    
    var arSelThumb = getSelThumb(thumbid,strThumbs);
    if (arSelThumb.length != 3 && arSelThumb.length != 4) return false;
    var sName = arSelThumb[1], sImgSrc = arSelThumb[2];
    if (arSelThumb.length == 4)  {
        // have directives
        sName = "<a href=\"javascript:showWindow('showDirectives.asp?ID=" + arSelThumb[3] + "')\">Templates Specifications...</a>";
    } else {
        sName = "&nbsp;";
    }    
    writeInDIV(sImgSrc,sName,divName);
    

}
function showWindow(strURL){
        var LeftPosition;
        var TopPosition;
        var w;
        var h;
        w = 300;
        h = 200;
        LeftPosition = (screen.width) ? (screen.width-w)-5 : 0;
        //TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
        TopPosition = 0;
        hintWindow = window.open(strURL, "Message", 'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars=yes,resizable=yes');
        hintWindow.focus();
        
}


	function PopIt1(strURL,winName){

		var LeftPosition;
		var TopPosition;
		var w;
		var h;
		w = 600;
		h = 500;
		LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
		TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
		//window.open(strURL, winName, 'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars=yes,resizable=yes,location=1,statusbar=1,menubar=1');
		window.open(strURL, winName, 'top='+TopPosition+',left='+LeftPosition+',scrollbars=yes,resizable=yes,location=1,status=1,menubar=1');
	}

function PopIt2(strURL,winName,w,h,sParm){
		var Lp;
		var Tp;
		
		w = (w)?w:((screen.width) ? screen.width : 800 )
		h = (h)?h:((screen.height) ? screen.height: 600 )
		sParm = (sParm)?sParm:'scrollbars=yes,resizable=yes,location=1,statusbar=1,menubar=1'
		
		Lp = (screen.width) ? (screen.width-w)/2 : 0;
		Tp = (screen.height) ? (screen.height-h)/2 : 0;//',scrollbars=yes,resizable=yes,location=1,status=1,menubar=1'
		window.open(strURL, winName, 'height='+h+',width='+w+',top='+Tp+',left='+Lp + ","+ sParm);
	}


function writeInDIV(imgsrc,desc,dvName) {
    var ie4=document.all
    var ns6=document.getElementById
    if (ie4||ns6)
    var contentobj=document.getElementById? document.getElementById(dvName): document.all[dvName]

    if (ie4||ns6)
        if (imgsrc.length > 0) {
	        contentobj.innerHTML='<center>Loading image...</center>';
	        contentobj.innerHTML='<img src="'+imgsrc+'"><br><br>'+desc+'';
        } else contentobj.innerHTML= '';
    else if (document.layers)
	    if (imgsrc.length > 0) {
	        document.thumbs1.document.thumbs2.document.open();
	        document.thumbs1.document.thumbs2.document.write('<img src="'+imgsrc+'"><br><br>'+ desc +'');
	        document.thumbs1.document.thumbs2.document.close();    
        } else {
            document.thumbs1.document.thumbs2.document.open();
            document.thumbs1.document.thumbs2.document.write('');
	        document.thumbs1.document.thumbs2.document.close();
	        }
    else
	    alert('You need NS 4+ or IE 4+ to view the images!')
}
// helper function for finding selecting thumbnail option
function getSelThumb(id,sThumbs) {
    var result = new Array();
    var arItems = sThumbs.split("|");
    var bFound = false;
    var arTemp;
    for (var i=0;i< arItems.length;i++){
        arTemp = arItems[i].split("~");
        if (arTemp[0] == id) {
            bFound = true;
            break;
        }
    }
    if (bFound) result = arTemp;
    return result;
}
// function for string replacment - use regexpr
function ReplaceReg(instr,str,tostr)
{
	var re = eval("/" + str + "/gi");
	return instr.replace(re,tostr);	
}
function checkFiles(objFile){
        
        if (sType == "") {
            alert("File upload is disabled.");
            return false;
        }
        var filename = objFile.value.toLowerCase() ;
        if (filename == "") {
            //skip empty boxes
            return true;
        }
        // all file types are allowed
        if (sType == "1")
            return true;

        var pos = filename.lastIndexOf("\\");
        if (pos > -1)
            filename = filename.substring(pos+1);
        pos = filename.lastIndexOf(".");
        var ext = "";
        if (pos > -1)
            ext = filename.substring(pos+1);

        var bResult = IsInArray(sFileTypes,ext);
        // only this types are allowed
        var sMsg = "";
        if (sType == "3") {
            bResult = ! bResult;
            sMsg    = loadXML("error_dontTry") + " "; ;       //"Don't try ";
        } else
            sMsg    = loadXML("error_try") + " ";            //"Try ";           
        if (! bResult) {
           // alert("You choose wrong file format ["+ ext +"]. "+ sMsg +"with " + sFileTypes + ".");
            alert(loadXML("error_wrongFileFormat") + " ["+ ext +"]. "+ sMsg + loadXML("with") + " " + sFileTypes + ".");
            objFile.focus();
            return false;
        } else
            return true;

    }
    function IsInArray(sTypes,sExt) {
        var arTypes = sTypes.split(",");
        var bResult = false;
        for (var i= 0; i < arTypes.length;i++) {
            if (Trim_String(arTypes[i].toLowerCase()) == Trim_String(sExt.toLowerCase())) {
                bResult = true;
                break;
            }
        }
        return bResult;
    }
    // function for remove blank space before and after strings
function Trim_String(txtobjvalue) {
    var ichar, icount;
    var strValue = "" + txtobjvalue;
    ichar = strValue.length - 1;
    icount = -1;
    while (strValue.charAt(ichar)==' ' && ichar > icount)
        --ichar;
    if (ichar!=(strValue.length-1))
        strValue = strValue.slice(0,ichar+1);
    ichar = 0;
    icount = strValue.length - 1;
    while (strValue.charAt(ichar)==' ' && ichar < icount)
        ++ichar;
    if (ichar!=0)
        strValue = strValue.slice(ichar,strValue.length);
    return strValue;
}

//////////////////////////////////////////////////////////////////////////////////////
// Project Folio Link 
//
// Todor Entcev  ICQ 16198590
// last mod 12 mart 2005
//
//
//////////////////////////////////////////////////////////////////////////////////////


//////////////////////////////////////////////////////////
//
//     in file 
//     var sSkinsList = "<%'=ssSkinsList%>"
//     var sSkinsInfo = "<%'=ssSkinsInfo%>"
//
//     and <select name='FPSkinID' id=...>,<select name='FPTemplateID' id=...>
//
//     and - <div style="position:..." name=SkinThumb id=SkinThumb >
//
//     in on_load 
//    	setSelectSkins()
// 
//////////////////////////////////////////////////////////
var sSep1,sSep2,sSep3
var sSep1_,sSep2_,sSep3_

function setSelectSkins(){
    var oSkinS=top.MM_findObj('ffSkinID',document)
    var oTempS=top.MM_findObj('ffTemplateID',document)
    
    FormFields()
    
    if(typeof(sSep1)=="undefined") sSep1 = "||"
    if(typeof(sSep2)=="undefined") sSep2 = "|"
    if(typeof(sSep3)=="undefined") sSep3 = "~"
   
    var ar1,ar
///    sSkinsList = " SkinsL||SkinsL||SkinsL... "
///    SkinsL is info for skin for one template 
///    SkinsL = "id,Name,id,name,id,name...|SelectedID"
    if(oSkinS && oTempS ){
        ar1 = sSkinsList.split(sSep1);
        i = oTempS.selectedIndex
        i = (i<0)?0:i;
        ar = ar1[i].split(sSep2); aSel = ar[0].split(sSep3); iSel = ar[1];
        restoreSep(aSel)
        addListItems(oSkinS,aSel,iSel);
        
// set URL for this page         
        if(sPageURL) {
//alert(oF)
                if(oF) if(oF['f_URL']) oF['f_URL'].value=sPageURL+"&tid="+oTempS.options[i].value
              //  top.MM_setTextOfLayer('f_URL',document,sPageURL+"&pid="+oTempS.options[i].value)
        }
    }
    setSelectSkinsThumb();
}

function restoreSep(aSourceF){
    var iN_L,i_L

    if(typeof(sSep1_)=="undefined") sSep1_ = "_DLINE_"
    if(typeof(sSep2_)=="undefined") sSep2_ = "_LINE_"
    if(typeof(sSep3_)=="undefined") sSep3_ = "_TILDA_"
    
    if(aSourceF){
        iN_L = aSourceF.length
        for(i_L=0;i_L<iN_L;i_L++){
             aSourceF[i_L] = aSourceF[i_L].replace(eval('/'+sSep1_+'/gi'),sSep1)
             aSourceF[i_L] = aSourceF[i_L].replace(eval('/'+sSep2_+'/gi'),sSep2)
             aSourceF[i_L] = aSourceF[i_L].replace(eval('/'+sSep3_+'/gi'),sSep3)                          
        }
    }
}



function setSelectSkinsThumb(){
    var sText,s
    
    var oSkinS=top.MM_findObj('ffSkinID',document)
    var oTempS=top.MM_findObj('ffTemplateID',document)
    if(oSkinS && oTempS && sSkinsInfo!=''){
        s = sSkinsInfo.split("||")
        j = oTempS.selectedIndex;        j = (j<0)?0:j;        s1 = s[j].split("~")    
        i = oSkinS.selectedIndex;        i = (i<0)?0:i;        imgsrc = s1[i]
        if(imgsrc=='') imgsrc = sNoImg
        else imgsrc = sImgPath + imgsrc
        sText = "<img src=\""+imgsrc+"\">"
        
		sName = ""
		if(sTempInfo!=''){
			
			s = sTempInfo.split("|")
			if(s.length>j){
				s1 = s[j].split("~")
				if(s1.length>1){
					if (parseInt(s1[1]) == 1)  { // parseInt
						// have directives
						sName = "<br><a href=\"javascript:showWindow('showDirectives.asp?ID=" + oTempS.options[oTempS.selectedIndex].value + "')\">Templates Specifications...</a>";
					} 
				}
			}				
		}
		
		sText = sText + sName

        
        top.MM_setTextOfLayer('SkinThumb',document,sText)
    }
}

//////////////////////////////////////////////
// 
// for two tabs Obligation and Optional
//
//
// sLayerOn - name of active layer 
//
//     in on_load() put  	showL('oOb');
//
//////////////////////////////////////////////
var oF
var sLayerOn
sLayerOn  = "x"
var sTabSelBGColor,sTabBGColor
sTabSelBGColor = "Gray"
sTabBGColor = "#F3F3F3"

var sPageURL=""
var isSafari = (navigator.userAgent.indexOf("Safari") > -1)

function showL(sObjName){
    if(sLayerOn!=sObjName) {
        showFox(sLayerOn,'hide');showFox(sObjName,'show')    
        

        var o=document.getElementById(sLayerOn)
        if(o) o.style.display='none'
        var o=document.getElementById(sObjName)
        if(o) { o.style.display='block';o.style.visibility="visible"}
         
	    //top.MM_showHideLayers(sLayerOn,document,'hide',sObjName,document,'show')

	    if(isSafari){
	         
	            
	    
    	    xx=top.MM_findObj(sObjName,document);
	        if(xx) {
		 if(xx.style) xx.style.height=xx.offsetHeight+180

    	        yy=top.MM_findObj('container',document);

	        if(yy)  if(yy.style) if (parseInt(yy.style.height)<xx.offsetHeight) yy.style.height=xx.offsetHeight

    	    }
        }    
/*
	    if(!sTabSelBGColor) sTabSelBGColor="White"
	    if(!sTabBGColor)    sTabBGColor="Gray"
	    top.SetBGC("t"+sObjName,document,sTabSelBGColor)
	    top.SetBGC("t"+sLayerOn,document,sTabBGColor)
*/	    
	    sLayerOn = sObjName;	
	}
}

function showFox(sObjName,sAct){
    var iFox = myFox.length
    var sNewAct
    if(iFox>0 && sObjName!='') 
        for(i=0;i<iFox;i++)
        if(myFox[i].parent==sObjName) {    
            if(sAct=='hide') sNewAct = sAct 
            else             sNewAct = myFox[i].status
            top.MM_showHideLayers(myFox[i].name,document,sNewAct)
        }
}

function checkCopyRight1(sFieldName){
    flReturn = true

    if(oF){
           //////////////////////////////
           ///// sound copyright check
           ///////////////////////////// 
           if(!sFieldName) sFieldName='fSoundFile'

           if(oF[sFieldName]) if(oF[sFieldName].value!=''){
                if(oF.fCopyRightProtect){
                   
                   
                    flReturn = (oF.fCopyRightProtect[0].checked || oF.fCopyRightProtect[1].checked)
                }
           }
           if(!flReturn){
                //if(fl) 
                showL('oOp');
                //oF.fCopyRightProtect[0].focus()
                document.location.href=document.location.href+'#al'
                alert(loadXML("fu_alert"))
           }
    
    }
    return flReturn;
}

function SubmitForm(){
//    var oForm
//    oForm=top.MM_findObj('frm',document)
//    if(oForm)

    if(oF){
           //////////////////////////////
           ///// sound copyright check
           ///////////////////////////// 
           flSoundCopyRight = checkCopyRight1()
           if(flSoundCopyRight){
           /////////////////////////////
               if(checkFrm(oF)){
                    ShowProgress();
                    
                    oF.submit();
               }
           }
       }
}
//////////////////////////////////////////////////////////////////////////////////////


//////////////////////////////////////////////
// 
// 
// function setTagS(this,sTextA) - this i sdrop down 
// and onchange  set to text area named sTextA , value of selected item 
//
// form obj - oF 
// 22 mart 2004
//////////////////////////////////////////////

function setTagS(sSel,sTextA){
    var sVal,oForm,oSel
    oForm = oF
    sVal = ""
    if(!oForm) oForm = top.MM_findObj('frm',document)
    if(oForm) {
        oSel = oForm[sSel]
        if(oSel) sVal = oSel.options[oSel.selectedIndex].value
        if(oForm[sTextA]) oForm[sTextA].value=sVal
    }
}

function ReplaceReg(instr,str,tostr)
{
	var re = eval("/" + str + "/gi");
	return instr.replace(re,tostr);	
}


function GoEditTem(){
    var flIsLocal,aTempInfo,iTempSelN,aTemp//,flRet

    //flRet = false;
    flIsLocal = false;    iTempSelN = -1;    aTempInfo=""; aTemp=""; 
    
    if(oF) if(oF["ffTemplateID"]) iTempSelN = oF["ffTemplateID"].selectedIndex;
    if(sTempInfo) aTempInfo = sTempInfo.split("|")
    if(iTempSelN>=0 && aTempInfo.length>iTempSelN) {
        aTemp = aTempInfo[iTempSelN].split("~");
        if(aTemp.length>3) flIsLocal = (aTemp[2]==1);
    }
//    if(!flIsLocal)  alert("This template is not local!"); OR EXIST ERROR !!!
    if(!flIsLocal)  {
        alert("This template is not local! " );
    }        
    else            {
        if(oF) if(oF["fEditTem"]) oF["fEditTem"].value=1;
        SubmitForm();
    }
    
    return false;    
}

var O_FIELD = "oField";
var blFlagMed,blFlagThu
var sE_text = "<font class=\"textNorm\">"+loadXML("field_not_necessary")+"</font>"        //This field is not necessary
var sTempInfoA=""
function FormFields(){
    var aTempInfo,iTempSelN,aTemp,isNew,aRowCol,aFormI,aFieldI
    var iTRow,iTCol

    isNew = true
    iTempSelN = -1; aTempInfo=""; aTemp=""; aFormI=""; aFieldI=""; sStatus="";aRowCol="";
    iTRow=iTCol=0;
    
    if(oF) if(oF["ffTemplateID"]) iTempSelN = oF["ffTemplateID"].selectedIndex;
    if(oF) if(oF.fIsNew) if(oF.fIsNew.value=='0') isNew=false
    if(sTempInfoA) aTempInfo = sTempInfoA.split("||")

    if(iTempSelN>=0 && aTempInfo.length>iTempSelN) {
        //alert('template info\n\n'+aTempInfo[iTempSelN])
        aTemp = aTempInfo[iTempSelN].split("|"); // 0 - conatain forms info ,1 contain row~col
        //alert('form info\n\n'+aTemp[0]+'\n\n row col \n\n'+aTemp[1])
        if(aTemp[1]!='' && isNew ) {
            aRowCol = aTemp[1].split("~");
            if(aRowCol.length==2) { 
                iTRow = aRowCol[0];iTCol = aRowCol[1];
            }
        }
        if(oF.ICountMax && oF.ICountMaxRows && isNew){
            //alert('1 \n'+iTRow + '-' + iTCol)
            if(iTRow==0 && oF.ICountMaxRowsDef) iTRow = oF.ICountMaxRowsDef.value;
            if(iTCol==0 && oF.ICountMaxDef) iTCol = oF.ICountMaxDef.value;      
            if(iTRow!=0 && iTCol!=0) {
                oF.ICountMaxRows.value = iTRow
                oF.ICountMax.value = iTCol
            }
        }
        aFormI = aTemp[0].split("~"); // razmera e raven na broia na poletata za tazi forma 
        for(i=0;i<aFormI.length;i++){
            //alert('properties for one fied \n'+aFormI[i])
            if(aFormI[i]!=""){
                aFieldI = aFormI[i].split("*") // 5 trebva da e 0 - fieldid,1- visible,2 W,3-H,4-type
                if(aFieldI.length==5){
                    sStatus =(aFieldI[1]=='0')?'hide':'show'
                    if(aFieldI[4]!='2') {
                        SetFox_Status(O_FIELD+aFieldI[0],sStatus)
                        sE_t = (aFieldI[1]=='0')?sE_text:''
                        top.MM_setTextOfLayer(O_FIELD+aFieldI[0]+'E',document,sE_t,true)
                    }
                   // alert('isNew='+isNew)
                    if(isNew && aFieldI[1]=='1' && (aFieldI[4]=='1' || aFieldI[4]=='2')){
                        newW_L=newH_L=0;
                        if(aFieldI[2]>0 && aFieldI[3]>0 ){
                            newW_L = aFieldI[2]
                            newH_L = aFieldI[3]
                        }
                        else{ // get defaults 
                            if(aFieldI[4]=='1' ) {
                                if(oF.fDefWm) newW_L = oF.fDefWm.value
                                if(oF.fDefHm) newH_L = oF.fDefHm.value                                
                            }                                
                            if(aFieldI[4]=='2' ) {
                                if(oF.fDefWt) newW_L = oF.fDefWt.value
                                if(oF.fDefHt) newH_L = oF.fDefHt.value                                
                            }                                
                        }
                        
                        if(newW_L>0 && newH_L>0 ){ 
                            vL = newW_L
                            if(aFieldI[4]=='1' ) {
                                if(oF.fImgSizeWm) {oF.fImgSizeWm.value=newW_L;} 
                                if(oF.fImgSizeHm) {oF.fImgSizeHm.value=newH_L;} 
                                if(blFlagMed) vL = newH_L
                                top.MM_setTextOfLayer('oMedHid',document,vL,false)
                            }
                            if(aFieldI[4]=='2') {
                                if(oF.fImgSizeWt) {oF.fImgSizeWt.value=newW_L;} 
                                if(oF.fImgSizeHt) {oF.fImgSizeHt.value=newH_L;} 
                                if(blFlagThu) vL = newH_L
                                top.MM_setTextOfLayer('oThuHid',document,vL,false)
                            }
                        }
                    }                
                }
            }
        }
    }
}

var myFox=new Array()

function Fox(sParent,sName,sStaus){
    if(sParent!='' && sName!=''){
        this.parent = sParent;
        this.name   = sName;
        this.status = (sStaus)? sStaus:'hide';
        this.getStatus = Fox_getStatus;
        this.setStatus = Fox_setStatus;
    }
}
function Fox_getStatus(){
}
function Fox_setStatus(sNewStatus){
    if(sNewStatus=='show' || sNewStatus=='hide'){
        if(sNewStatus!=this.status){
            if(this.parent==sLayerOn)  top.MM_showHideLayers(this.name,document,sNewStatus)
            this.status = sNewStatus
        }
    }
}

function SetFox_Status(sName_F,sStatus_F){
    var k,kn,fl
    kn = myFox.length
    fl=true

    for(k=0;k<kn&&fl;k++){
        if(myFox[k].name==sName_F) { myFox[k].setStatus(sStatus_F);fl=false;}
    }
}



function SetStatus(sMes,w){
    if(sMes=='')   sMes = "Copyright: ISProductions "
    //if(w) if(w.status) w.status = sMes
    top.status = sMes
}



function getFromTempInfo(iTemI,iFieldI){
    var sRez,aTempInfo,aTemp
    aTempInfo = "".split("")
    if(typeof(sTempInfo)!='undefined') aTempInfo = sTempInfo.split("|")
    if(iTemI>=0 && aTempInfo.length>iTemI) {
        aTemp = aTempInfo[iTemI].split("~");
        if(aTemp.length>=iFieldI+1) sRez = aTemp[iFieldI];
    }
    return sRez;
}


////////////////////////////////////////
// Project Folio Link Services
//
// show hide ExtraCheckBoxs " change the template assignment to ... " 
//
////////////////////////////////////////

function setExtraCheckBoxs(oSel,oDivName,sCheckBoxNames,sFamTemFieldName){
    var iFamilyMember,aCheckBoxNames,sNewStatus
    if(oSel) {
        iFamilyMember = getFromTempInfo(oSel.selectedIndex,3)
        if(!sCheckBoxNames) sCheckBoxNames=""
        aCheckBoxNames = sCheckBoxNames.split(",")
        for(i=0;i<aCheckBoxNames.length;i++)
            if(oF) if(oF[aCheckBoxNames[i]]) oF[aCheckBoxNames[i]].checked=false
        if(iFamilyMember>-1) sNewStatus = 'show'
        else               sNewStatus = 'hide'
        if(oDivName)       oDivName.setStatus(sNewStatus)
        if(oF&&sFamTemFieldName) if(oF[sFamTemFieldName]) oF[sFamTemFieldName].value=iFamilyMember
    }        
}

// for Image resizing tool
function changeImgInfo(sImgNameF,sImgW,sImgH){
    var oImg
    
    oImg = top.MM_findObj("oImage", document)   
    if(oImg){
        oImg.src = sImgNameF
    }   
    if(oF){ 
        if(oF['fImgSizeW']) oF['fImgSizeW'].value = sImgW
        if(oF['fImgSizeH']) oF['fImgSizeH'].value = sImgH
    }
}

function changeImgInfo1(sPar){
    if(oF){ 

        if(!oF["fImgScaling"].checked && oF["fReScale"+sPar].checked ){ 
            s1 = (sPar=='t')?sPar:"";
            if(oF['fOrigImgW'+s1]) iOrigW = iii(oF['fOrigImgW'+s1].value) 
            if(oF['fOrigImgH'+s1]) iOrigH = iii(oF['fOrigImgH'+s1].value)
            
            if(oF['fImgSizeW'+sPar]) { iNewW = iii(oF['fImgSizeW'+sPar].value);  iNewW = (iNewW>iOrigW)?iOrigW:iNewW; }
            if(oF['fImgSizeH'+sPar]) { iNewH = iii(oF['fImgSizeH'+sPar].value);  iNewH = (iNewH>iOrigH)?iOrigH:iNewH; }
             
            if(iOrigH>0&&iOrigW>0){
                if(iOrigW>iOrigH){
                    iNewH = Math.round(iNewW * iOrigH/iOrigW)
                    if(iNewH>iOrigH) iNewH=iOrigH
                }
                else{
                    iNewW = Math.round(iNewH * iOrigW/iOrigH)
                    if(iNewW>iOrigW) iNewW=iOrigW                
                }
            }
            if(oF['fImgSizeW'+sPar]) oF['fImgSizeW'+sPar].value = iNewW
            if(oF['fImgSizeH'+sPar]) oF['fImgSizeH'+sPar].value = iNewH
        }
    }
}


function iii(x){
    if(x!='') x=parseInt(x)
    else x = 0
    return(x)
}

function reCalculate(iM){
    var iWOld, iHOld, iWNew, iHNew, iWBox, iHBox,iWBox1, iHBox1
    var sMax,sAMax
var sMes 

    
    if(oF){
            sAMax = " ["+iii(oF['fMaxWm'].value) +","+iii(oF['fMaxHm'].value) +"]"    
        if(iM==1){    
            if(oF['fImgSizeWm']) iWBox=iWBox1 = iii(oF['fImgSizeWm'].value)
            if(oF['fImgSizeHm']) iHBox=iHBox1 = iii(oF['fImgSizeHm'].value) 
            if(oF['fOrigImgW']) iWOld = iii(oF['fOrigImgW'].value) 
            if(oF['fOrigImgH']) iHOld = iii(oF['fOrigImgH'].value) 
            sMax = " ["+iii(oF['fDefWm'].value) +","+iii(oF['fDefHm'].value) +"]"    
        }
        else {
            if(oF['fImgSizeWt']) iWBox=iWBox1 = iii(oF['fImgSizeWt'].value) 
            if(oF['fImgSizeHt']) iHBox=iHBox1 = iii(oF['fImgSizeHt'].value) 
            if(oF['fOrigImgWt']) iWOld = iii(oF['fOrigImgWt'].value) 
            if(oF['fOrigImgHt']) iHOld = iii(oF['fOrigImgHt'].value) 
            sMax = " ["+iii(oF['fDefWt'].value) +","+iii(oF['fDefHt'].value) +"]"    
            //sAMax = " ["+iii(oF['fMaxWt'].value) +","+iii(oF['fMaxHt'].value) +"]"             
        }
        
        
    }
    iWNew = iHNew = 0
    iWBox = (iWBox>iWOld)?iWOld:iWBox; 
    iHBox = (iHBox>iHOld)?iHOld:iHBox; 
    
       if(iWBox>=iWOld && iHBox>=iHOld) {
           	iWNew = iWOld 
    	    iHNew = iHOld  	    
    	    }
        else {
            if(iHOld>0&&iWOld>0){
                if(iWOld>iHOld){
                    iWNew = iWBox
                    iHNew = Math.round(iWBox * iHOld/iWOld)
                    if(iHNew>iHOld) iHNew=iHOld
                }
                else{
                    iHNew = iHBox
                    iWNew = Math.round(iHBox * iWOld/iHOld)
                    if(iWNew>iWOld) iWNew=iWOld                
                }
            }
       }    
    
    /*
       if(iWBox>=iWOld && iHBox>=iHOld) {
           	iWNew = iWOld 
    	    iHNew = iHOld  	    
    	    }
        else {
            if (iWOld > iHOld) {
                scaleFactor = iWBox/iWOld
                iHNew = Math.round(scaleFactor*iHOld)
                if(iHNew>iHBox){
                    scaleFactor = iHBox/iHOld
                    iWNew = Math.round(scaleFactor*iWOld)
                    iHNew = iHBox
                    }
                else{
                    iWNew = iWBox
                    }
                }
            else{
                scaleFactor = iHBox/iHOld
                iWNew = Math.round(scaleFactor*iWOld)
                if(iWNew>iWBox){
                    scaleFactor = iWBox/iWOld
                    iHNew = Math.round(scaleFactor*iHOld)
                    iWNew = iWBox
                    }
                else{
                    iHNew = iHBox
                    }
                }
            }    
*/
sMes  = "The above Values show you the original image dimensions,\n"
sMes +="the dimension you are modifying (target size) and\n"
sMes +="the new calculated size.\n"
////sMes  = "*Best-Image-Fit (on) Template Maximum Display Area "+sMax+" Absolute max "+sAMax+"\n"
////sMes +="**New Size\n\n"
////sMes +="* The value in this setting comes from the values specified in the template settings for Max Medium and Thumbnail sizes\n"
////sMes +="* If template scaling is being used adjust 'Best-Image-Fit(on) Max Display Area'  by the scaling factor.\n"
////sMes +="** If the template has absolute values like tag(w,h) which are bigger than 'Best-Imaget ge-Fit(on) Max Display Area' the 'New Size' may not match the actual image generated"
            
    alert("Original Size :["+iWOld+"]["+iHOld+"]\nTarget Size:["+iWBox1+"]["+iHBox1+"]\nNew Size ["+iWNew+"]["+iHNew+"]"+"\n\n"+sMes)
}


function ImageResizingTool(sExt){
var sNamS,sNam

     if(oF){
        sNamS   = 'fQualityS'+sExt;sNam    = 'fQuality'+sExt  
        if(oF[sNamS]) if(oF[sNam]) if(oF[sNamS].selectedIndex>-1) oF[sNam].value=oF[sNamS].options[oF[sNamS].selectedIndex].value;
        sNamS   = 'fSharpenS'+sExt;sNam    = 'fSharpen'+sExt
        if(oF[sNamS]) if(oF[sNam]) if(oF[sNamS].selectedIndex>-1) oF[sNam].value=oF[sNamS].options[oF[sNamS].selectedIndex].value;        
        changeImgInfo1(sExt)
    }
}

function KeepOriginal(blFlagF){

    var sStaus,blFlStaus
    var obj
    
    sStaus = (blFlagF)?'none':''
  
    blFlStaus = false
    
    obj = top.MM_findObj('oMainImgS1',document);
    if(obj) if(obj.style) {blFlStaus = true;obj.style.display=sStaus}
    if(!blFlStaus)   top.MM_showHideLayers('oMainImgS1',document,sStaus)

}


function ChangeScaledInfo(blFlagF){
    var sStaus,blFlStaus
   // sStaus = (blFlagF)?'hide':'show'
   // sStaus = (blFlagF)?'style.display=none':'style.display=\'\''
    if(blFlagF){ // set default 
        KeepOriginal(true)
        document.forms[0].fKeepOrg[0].checked=true
    }
    
    sStaus = (blFlagF)?'none':''

      blFlStaus = false
      var obj,sT 
      obj = top.MM_findObj('oMainImgS',document);
      if(obj) if(obj.style) {blFlStaus = true;obj.style.display=sStaus}
      obj = top.MM_findObj('oThumImgS',document);
      if(obj) if(obj.style) {blFlStaus = true;obj.style.display=sStaus}
      if(!blFlStaus)   top.MM_showHideLayers('oMainImgS',document,sStaus,'oThumImgS',document,sStaus)

/*    if(blFlagF)  sT = "Turn \"off\" to select the image size and disable automatic image resiing in this page"
      else         sT = "Turn \"on\" to automatically size all images in this page"
*/     
      if(blFlagF)  sT = loadXML("bestfit_desc_OFF");
      else         sT = loadXML("bestfit_desc_ON");
      
    top.MM_setTextOfLayer('oIsScaled',document,sT)
}  


function SetDisplay(sObjName_F,blFlag_F,oDoc_F){
    var sStatus,objX,blFlStaus
    sStatus = (blFlag_F)?'':'none';
    blFlStaus = false
    
     objX = top.MM_findObj(sObjName_F,oDoc_F);
    
    if(objX) if(objX.style) {blFlStaus = true;objX.style.display=sStatus}

    if(!blFlStaus) {
        sStatus = (blFlag_F)?'hide':'show'
        top.MM_showHideLayers(sObjName_F,oDoc_F,sStatus)
     }
}

function slideShowImg(nextImg,nextGallery,sK){
	if(nextImg || nextGallery){
		setTimeout('action(nextImg,nextGallery,\''+sK+'\')',15000);
	}
}

function action(nextImg,nextGallery,sK){
	if(nextImg){
		location.href="Image.asp?ImageID="+nextImg+"&"+sK;
		}
	if(nextGallery){
		location.href="GalleryMain.asp?GalleryID="+nextGallery+"&"+sK;
		}
}

	function delSound(sLink) {
	    if (confirm("Are you sure?")){
	        document.location.href = sLink + "&ds=1";
    	}    
	}

 
function clearRadio(sName){
    if(oF) if(oF[sName]){
        n1 = oF[sName].length
        if(n1==undefined) {
            oF[sName].checked=false
        }
        else{
            for(i=0;i<n1;i++) oF[sName][i].checked=false
        }
    }
}

function customizeFlash(id,m){

	if(top.frames) if(top.frames['Content']) if(top.frames['Content']['Main']) if(top.frames['Content']['Main']['TemRight']){
		if(m==1){sLi ="CustomizeFlash.asp?ArtistID=" + id }
		else{sLi = "CustomizeFlash_s.asp?ArtistID=" + id}
		top.frames['Content']['Main']['TemRight'].document.location.href = sLi
		
	}
}
