// ---- Window Functions ------------------------------------------------------------------
function ViewPopup(pWidth,pHeight,pName,pScroll, pFid, pAct) {
  var url="index.asp?FID="+pFid+"&ACT="+pAct;
  var argv=ViewPopup.arguments; 
  for(i=6; i<argv.length; i++) url=url+"&"+argv[i];
    
  var popup=window.open(url,pName,"Left=0, Top=0, Height="+pHeight+", Width="+pWidth+", Toolbar=0, Menubar=0, Directories=0, Resizable=0, Scrollbars="+pScroll+", Location=0;");
  var sw = window.screen.availWidth;
  var sh = window.screen.availHeight;
  if((sw>0)&&(sh>0)) popup.moveTo((sw - pWidth) / 2, (sh - pHeight) / 2);
  popup.focus();
}


function AlertError(msg, ctrl) {
  alert(msg);
  if(ctrl && ctrl.focus) ctrl.focus();
  return false;
}

function SearchPressEnter(ev) {
  var code=(ev.charCode!=null)?ev.charCode:ev.keyCode;
  if(code==0) code=ev.keyCode;
  if(code=='13') SearchGo();
}

function SearchGo() {
  if(document.form.CurrentPage) document.form.CurrentPage.value=1;
  if(document.form.SearchText.value!='') mnFullSubmit(1000, 10);
}

// ---- Tables Functions ------------------------------------------------------------------
function GetSelected() {
	if (document.form.ID_Selected.length > 1) {
  	  for(var i=1;i<document.form.ID_Selected.length; i++) {
	    if(document.form.ID_Selected[i].checked) return document.form.ID_Selected[i].value;	
	  }	
	};
	return '';
}

var selectedRow=-1;

function SelectRow(row){
  var selectClass="TB_text_selected";
  var unselectClass="text_main";

  if(selectedRow!=-1) {  
    row_old=libGetElement("R"+selectedRow);
	if(row_old!=null) row_old.className=unselectClass;
  }
  
  if(row!=null) {
    row.className=selectClass;
	selectedRow=parseInt(row.id.substr(1));
	if(selectedRow>=0) document.form.ID_Selected[selectedRow].checked=true;
	return;
  }
}
// ----- Submit Functions --------------------------------------------------------------------
function BackToRoot() {
//alert(location.pathname);
//location.protocol="http:";
  	location.replace("http://"+location.host+location.pathname);  
}

function RefreshPage() {
  document.form.submit();
}

function SelectGroup(ID) {
  with(document.form) {
    ID_Group.value=ID;
	submit();
  }
}

function SelectCategory(ID_Cat) {
	document.form.ID_Cat.value=ID_Cat;
	mnSubmit(2);
}

function DirectSelectCategory(ID_Grp, ID_Cat) {
	var s = document.form.FID.value;
	document.form.FID.value = '2101';
//	document.form.FID.value = s.substr(0,1) + '101';
//	document.form.FID.value=2101;
	document.form.ID_Grp.value=ID_Grp;
	document.form.ID_Cat.value=ID_Cat;
	mnSubmit(2);
}

function SelectTitle(vLetter) {
	document.form.TitleLettet.value=vLetter;
	mnSubmit(3);
}

function SelectArtistTitle(vLetter) {
	document.form.TitleLetter.value=vLetter;
	mnSubmit(1);
}

function DirectSelectProduct(ID_Prd) {
	/*var s = document.form.FID.value;
	if (parseInt(s.substr(0,1)) <= 6 )
		document.form.FID.value = s.substr(0,1) + '101';
	else
		document.form.FID.value = '2101';
	document.form.ID_Grp.value='';
	document.form.ID_Cat.value='';
	document.form.ID_Prd.value=ID_Prd;
	mnSubmit(4);*/
	var s = document.form.FID.value;
	if (parseInt(s.substr(0,1)) <= 6 ) fid = s.substr(0,1) + '101';
	else fid = '2101';
	location.href='index.asp?FID='+fid+'&ACT=4&ID_Prd='+ID_Prd+'&RND='+Math.round(Math.random()*1000000);
}

function SelectProduct(ID_Prd) {
	if (document.form.FID.value.charAt(3) == '0')
		document.form.FID.value = parseInt(document.form.FID.value) + 1;
	document.form.ID_Prd.value=ID_Prd;
	mnSubmit(4);
}

function RunMiniSearch() {
	document.form.FID.value = 1100;
	mnSubmit(2);
}

function SelectArtist(ID_Cat) {
	document.form.ID_Auth.value=ID_Cat;
	mnSubmit(3);
}
function AddProductToCart(ID_Prd) {
	/*document.form.ID_Prd.value=ID_Prd;
	mnFullSubmit(8000,3);*/
	location.href='index.asp?FID=8000&ACT=3&ID_Prd='+ID_Prd+'&RND='+Math.round(Math.random()*1000000);
}
function DelProductFromCart(ID_Prd) {
	document.form.ID_Prd.value=ID_Prd;
	document.form.QTY.value=0;
	mnFullSubmit(8000,3);
}

//----------- Listbox Function -------------------------------------------------------------------
function lstGetValue(listbox) {
  if(listbox.selectedIndex>=0) return listbox.options[listbox.selectedIndex].value;
  else return '';
}

function lstGetText(listbox) {
  if(listbox.selectedIndex>=0) return listbox.options[listbox.selectedIndex].text;
  else return '';
}

function lstAddItem(listbox, value, text, valid) {
   var ind=listbox.options.length;
   if(valid) {
     for(i=0;i<ind; i++) if(listbox.options[i].value==value) return false;
   }
   
   listbox.options.length+=1;
   listbox.options[ind].value=value;
   listbox.options[ind].text=text;
   return true;
}

function lstDeleteItem(listbox, ind) {
  if((ind<0)||(ind>listbox.options.length)) return;
  for(i=ind+1; i<listbox.length; i++) {
    listbox.options[i-1].value=listbox.options[i].value;
    listbox.options[i-1].text=listbox.options[i].text;	
  }
  listbox.options.length=listbox.options.length-1;
}
// ------------- Radio Function ------------------------------------------------------------------
function radGetSelectedIndex(name) {
  var radio=eval('document.form.'+name);
  if(radio.length) {
	  for(i=0; i<radio.length; i++) {
		if(radio[i].checked) return i;
	  }
  }  
  if(radio.checked) return 0;
  else return -1;
}
// ------------- DHTML Function ----------------------------------------------------------------
function libGetElement(name) {
  if(document.getElementById) return document.getElementById(name);
  if(document.layers) return document.layers[name];
  return document.all[name];
}

function libVisible(name, display) {
 var div=libGetElement(name);
 if(div) {
    if(display) {
	   div.style.display="block";
	   div.style.visibility="visible";
	}
	else {
	   div.style.display="none";
	   div.style.visibility="hidden";
	}
 }
}

function libIsVisible(name) {
  var div=libGetElement(name);
  //if(div) return (div.style.display=='block');
  if(div) return (div.style.visibility=='visible');
  else return false;
}
// ---- Date Functions ------------------------------------------------------------------
var arMonth = 
	['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];

function GetMonthName(nM) {
  return arMonth[nM-1];
}
//-------------- Valid Function ---------------------------------------------------------------------
function validEMail(email) {
  var x1=email.indexOf('@');
  if(x1>=0) x2=(email.substr(x1+1)).indexOf('.');
  else return false;
  return (x2>=0);
}

function validNoEmpty(text) {
  return (trim(text)!='');
}

function validDouble(value) {
  var dbl=parseFloat(value);
  return (dbl==value);
}

function validInteger(value) {
  var i=parseInt(value);
  return (i==value);
}

function validCombobox(name) {
  var combo=eval('document.form.'+name);
  return (lstGetValue(combo)!='');
}

//-------------- Other Function ---------------------------------------------------------------------
  function ltrim( source ){
	index = 0;
	while( source.charAt(index) == " " ) index++;
	return source.substr( index );
  }

  function rtrim( source ){
	index = source.length - 1;
	while( source.charAt(index) == " " ) index--;
	return source.substring( 0, index + 1 );
  }

  function trim( source ){
	return ltrim( rtrim( source ) );
  }

function Int2Str(yy) {
  if(yy<10) return "0"+yy;
  else return ""+yy;
}


function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}




