
// Test javascript

function onFcs(obj,text)
{
   if(text == obj.value)
   {
     obj.value = '';
   }
   
   //obj.attributes['class'].value = 'text_field';
}
function onBlr(obj,text)
{
   if(obj.value == '')
   {
    obj.value = text;
    //obj.attributes['class'].value = 'text_field_blur';
   }
}

function detectImageSize(picName,picTitle)
{
      picURL=picName.src;
      
      picWidth  = ( picName.width  > 800 ) ? 800 : picName.width; 
      picHeight = ( picName.height > 700 ) ? 700 : picName.height; 
      
      newWindow=window.open(picURL,'newWin','toolbar=no,scrollbars=1,width='+picWidth+',height='+picHeight);
      newWindow.document.write('<html><head><title>'+picTitle+'</title></head><body leftmargin = "0" topmargin = "0" bottommargin = "0" rightmargin = "0"><div style="width:'+picName.width+'px;height:'+picName.height+'px;background-image: url('+picURL+');"></div></body></html>');
      newWindow.resizeBy(picWidth-newWindow.document.body.clientWidth,
      picHeight-newWindow.document.body.clientHeight);
      newWindow.focus();
 }


 function openPic(url)
 {
     picTitle = 'Picture';
     picName = new Image();
     picName.src = url;
     detectImageSize(picName,picTitle);
 }

function SetMaxFileId(val){
  MaxFileId = val;
}

function ShowHideBlock(_layer)
{
  layer = document.getElementById(_layer);
  
  if (layer.style.visibility == "hidden")
    {
     layer.style.position = "static";     
     layer.style.visibility = "visible";
    }

  else
    {
     layer.style.position = "absolute";     
     layer.style.visibility = "hidden";
    }
}

 function numbersonly(e, decimal) {
     var key;
     var keychar;
    
     if (window.event) {
       key = window.event.keyCode;
     }
     else if (e) {
       key = e.which;
    }
    else {
       return true;
    }
    keychar = String.fromCharCode(key);
    
    if ((key==null) || (key==0) || (key==8) ||  (key==9) || (key==13) || (key==27) ) {
       return true;
    }
    else if ((("0123456789").indexOf(keychar) > -1)) {
       return true;
    }
    else if (decimal && (keychar == ".")) 
    {
      return true;
    }
    else
       return false;
}
function IsNumeric(strString)
   //  check for valid numeric strings 
   {
   var strValidChars = "0123456789.";
   var strChar;
   var blnResult = true;

   if (strString.length == 0) return false;

   //  test strString consists of valid characters listed above
   for (i = 0; i < strString.length && blnResult == true; i++)
   {
      strChar = strString.charAt(i);
      if (strValidChars.indexOf(strChar) == -1)
      {
         blnResult = false;
      }
   }
   
   if(!isValidDecimal(strString))
   {
      blnResult = false;
   }
   
   return blnResult;
}

function isValidDecimal(strString)
{
   var valid = true;
   var countPoint = 0;
   
   for (i = 0; i < strString.length; i++)
   {
      strChar = strString.charAt(i);
      if(strChar == ".")
      {
         countPoint ++;
      }
   }
   if(countPoint > 1)
   {
      valid = false;
   }
   
   return valid;
}

function allowOnlynumbers(item)
{
  if(item.value != '')
  {
       if(!IsNumeric(item.value))
       {
         alert(item.value+" is not Valid!");
         item.value = '';
       }
  }
}

var MaxFileId = 1000;

function GetMaxFileId(Prefix_)
{
   retMaxId = 1;
   for(i = 1; i < MaxFileId; i++){
     item_ = document.getElementById(Prefix_+i);     
     if(item_ != null){
       
        if(i > retMaxId){
          retMaxId = i;
        }
     }     
   }
   
   return retMaxId;
}

function createHTMLNode(htmlCode, elementName,id) {
    // create html node
    var htmlNode = document.createElement(elementName);
    htmlNode.setAttribute('id',id);
    //htmlNode.setAttribute('style','-moz-user-select: none;');
    //htmlNode.setAttribute('tabindex','-1');
    htmlNode.innerHTML = htmlCode;    
    return htmlNode;
}

function AddArticleVideo(_layer,Link_,Remove_){
  layer = document.getElementById(_layer);  
  
  FileId = GetMaxFileId("ArticleVideo_Link_")+1;
  
  
         var Html = ''
                  +  '<table cellpadding="0" cellspacing="0" border="0">'
			      +  '<tr>'
			      +  '<td style="height:10px;">' 
				  +  '</td>'
				  +  '</tr>'
				  +  '<tr>'
				  +  '<td style="width:50px;" align="center">'
				  +  FileId
				  +	 '</td>'
				  +  '<td style="width:50px;" align="center">'
				  +  Link_+':'
				  +	 '</td>'
				  +  '<td align="left">'
				  +  '<input name="ArticleVideo_Link_'+FileId+'" type="text" id="ArticleVideo_Link_'+FileId+'" value="" class="text_12" style="width:480px;" />' 
				  +  '</td>' 
				  +  '</tr>'
				  +  '<tr>'
				  +  '<td style="height:10px;">'
				  +  '</td>'
				  +  '</tr>'
				  +  '<tr>'
				  +  '<td style="height:10px;" colspan="2" align="left">'
				  +  '&nbsp;<a href="#1" onclick="RemoveArticleVideo(\'ArticleVideo_'+FileId+'\')" class="text_b_11">'+Remove_+'</a>'
				  +  '</td>'
				  +  '</tr>'
				  +  '</table>'
			      +  '';
			      
    var HtmlNode = createHTMLNode(Html,'div','ArticleVideo_'+FileId);    
    layer.appendChild(HtmlNode);
}
function RemoveArticleVideo(_layer)
{
   parentDiv = document.getElementById('ArticleVideo_');
   layer = document.getElementById(_layer);   
   parentDiv.removeChild(layer);  
}

function AddArtistImage()
{
   
}

function AddPageImage()
{
   
}

function AddImageFile(_prefix,_layer,Title_,Image_,Remove_){
 layer = document.getElementById(_layer);
 FileId = GetMaxFileId(_prefix+"_Image_")+1;
 
    var   Html   = ''
                 +  '<table border="0" cellspacing="1" cellpadding="1">'
                 +  '<tr>'
                 +  '<td colspan="3" style="height:10px;"></td>'
                 +  '</tr>'
                 +  '<tr>'
                 +  '<td colspan="3" style="height:1px;background-image:url(./images/dottedline.jpg)"></td>'
                 +  '</tr>'
                 +  '<tr>' 
                 +  '<td colspan="3" style="height:10px;"></td>'
                 +  '</tr>'
                 +  '<tr>'
                 +  '<td style="width:50px;" rowspan="2" align="center">'
                 +  '<input id="'+_prefix+'_Image_SortNum_'+FileId+'" name="'+_prefix+'_Image_SortNum_'+FileId+'" type="text" class = "textorderfield" value="'+FileId+'" size="2" maxlength="3" onKeyPress="return numbersonly(event, false)">'
		         +  '</td>'		           
		         +  '</tr>'    
		         +  '<tr>'
		         +  '<td align="right" style="width:50px" class="text_12">'+Image_+'&nbsp;:&nbsp;</td>'
		         +  '<td align="left" style="height:30px;">'
		         +  '<input name="'+_prefix+'_Image_'+FileId+'" type="file" id="'+_prefix+'_Image_'+FileId+'" style="background-color:#FFFFFF;width:400px;" size="50">'
		         +  '</td>' 
		         +  '</tr>'
		         +  '<tr>'
		         +  '<td colspan="3" style="height:15px;" align="left">'
		         +  '<a href="#1" onclick="RemoveImageFile(\''+_prefix+'\',\''+_prefix+'Images_'+FileId+'\')" class="text_b_11">'+Remove_+'</a>'
		         +  '</td>'
		         +  '</tr>'
		         +  '</table>';    

    var HtmlNode = createHTMLNode(Html,'div',''+_prefix+'Images_'+FileId);    
    layer.appendChild(HtmlNode);
}
function RemoveImageFile(_prefix,_layer)
{
   parentDiv = document.getElementById(''+_prefix+'Images_');
   layer = document.getElementById(_layer);   
   parentDiv.removeChild(layer);   
}


function AddArticleFile(_layer,Title_,File_,Remove_){
  layer = document.getElementById(_layer);  
  
  FileId = GetMaxFileId("Article_File_")+1;
  
        var Html = ''
                 +  '<table border="0" cellspacing="0" cellpadding="0">'
                 +  '<tr>'
                 +  '<td colspan="3" style="height:10px;"></td>'
                 +  '</tr>'
                 +  '<tr>'
                 +  '<td colspan="3" style="height:1px;background-image:url(./images/dottedline.jpg)"></td>'
                 +  '</tr>'
                 +  '<tr>' 
                 +  '<td colspan="3" style="height:10px;"></td>'
                 +  '</tr>'
                 +  '<tr>'
                 +  '<td style="width:50px;" rowspan="2" align="center">'
                 +  '<input id="Article_File_SortNum_'+FileId+'" name="Article_File_SortNum_'+FileId+'" type="text" class = "textorderfield" value="'+FileId+'" size="2" maxlength="3" onKeyPress="return numbersonly(event, false)">'
		         +  '</td>'		         
		         +  '<td style="width:50px" align="right">'+Title_+':</td>'
		         +  '<td align="left" style="width:480px;height:30px;margin-top:5px;margin-bottom:5px;">'   
		         +  '<input name="Article_FileTitle_'+FileId+'" type="text" id="Article_FileTitle_'+FileId+'" value="" class="text_12" style="width:480px;"/>'     
		         +  '</td>'   
		         +  '</tr>'    
		         +  '<tr>'
		         +  '<td align="right" style="width:50px">'+File_+':</td>'
		         +  '<td align="left" style="height:30px;">'
		         +  '<input name="Article_File_'+FileId+'" type="file" id="Article_File_'+FileId+'" style="background-color:#FFFFFF;width:480px;" size="64">'
		         +  '</td>' 
		         +  '</tr>'
		         +  '<tr>'
		         +  '<td colspan="3" style="height:15px;" align="left">'
		         +  '<a href="#1" <a href="#1" onclick="RemoveArticleFile(\'AttachedFile_'+FileId+'\')" class="text_b_11">'+Remove_+'</a>'
		         +  '</td>'
		         +  '</tr>'
		         +  '</table>'
		         +  '';
  
    var HtmlNode = createHTMLNode(Html,'div','AttachedFile_'+FileId);    
    layer.appendChild(HtmlNode);   
}
function RemoveArticleFile(_layer)
{
   parentDiv = document.getElementById('ArticleFiles_');
   layer = document.getElementById(_layer);   
   parentDiv.removeChild(layer);
}

