/////////////////////////////////////////
//       JavaScript Document           //
//       Armenian Music Center         //
//          Version 1.0                //
/////////////////////////////////////////


  /// globales
var d=document;
var w=window;


function checkall(form_name)
{

    for (i = 0; i < d.forms[form_name].elements.length; i++)
     {
         var item = d.forms[form_name].elements[i];

		 if (item.type == 'checkbox')
		  {
             item.checked=(form_name=='songform'?d.getElementById("all").checked:d.getElementById("alll").checked);
          }

 	 }
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function count(_form)  ///count of checked iteam
 {
    var btnid="";
	var totalcount=0;
	var countofchecked=0;

    for (i = 0; i < d.forms[_form].elements.length; i++)
     {
         var item = d.forms[_form].elements[i];
		 if (item.type == 'checkbox' && item.id != 'vote' && item.value != 'all' )                        {   totalcount++;       }
		 if (item.type == 'checkbox' && item.id != 'vote' && item.value != 'all' && item.checked==true)   {   countofchecked++;   }
	 }

     if(_form=='songform')
	  {
	    btnid='ordermp3';
		allid='all';
	  }
	  else
	  {
	    btnid='ordermp33';
        allid='alll';
	  }

	 d.getElementById(btnid).disabled=(countofchecked!=0)?false:true;
	 d.getElementById(allid).checked=(countofchecked!=totalcount)?false:true;

}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function submiter(act,form_)
{
   if(act=='order')
   {
     d.getElementById(form_).submit();
   }
   else
   {
	 d.getElementById(form_).target="_self";
     d.getElementById(form_).action="vote.php";
	 d.getElementById(form_).submit();
   }
}


//////////////////////////////////////chek the country of reg////////////////////////////////////////////////
function checkcountry(totalweight,subtotal)
{
     if(d.all("country").value=="United States")
	 {
	   d.getElementById("tr1").style.display = "";
	   d.getElementById("state").disabled=false;
//	   d.getElementById("shipreg").value = "2.99";
	 }
	 else
	 {
	   d.getElementById("tr1").style.display = "none";
	   d.getElementById("state").disabled=true;
//	   d.getElementById("shipreg").value = "4.99";
	 }
	 change_shippingprice(d.all("country").value,totalweight,subtotal);
}

/////////////////////////////////////////window opener///////////////////////////////////////////////////////

function winopen(v_FilePath, width, height, resizable, scrollbars)
{
    var w=width, h=height;
	var m_prop="width=" + w + ", height=" + h +
	    ", top="+ (screen.height/2 - h/2) + ", left=" + (screen.width/2 - w/2) +
		", resizable=" + resizable + ", scrollbars=" + scrollbars;
   window.open(v_FilePath , "_blank" , m_prop);
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function order_mp3(form_name)
{
	var str=myhost + "/functions/mp3ordermass.php?";
  //  alert(form_name);
	for(var i=0; i<d.forms[form_name].elements.length; i++)
	{
		if(d.forms[form_name][i].id == 'ordermp3' || d.forms[form_name][i].id == 'all' || d.forms[form_name][i].id == 'alll') break;
		if(d.forms[form_name][i].type == 'checkbox' && d.forms[form_name][i].checked)
		  {
			  str = str + "&c[]=" + d.forms[form_name][i].value;
	      }
	}
	//alert(str);
	winopen(str, 400, 400, 0, 1);
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function order_ringtone(form_name)
{
	var str=myhost + "/functions/ringtoneordermass.php?";
    //alert(form_name);
	for(var i=0; i<d.forms[form_name].elements.length; i++)
	{
		if(d.forms[form_name][i].id == 'ordermp3' || d.forms[form_name][i].id == 'all') break;
		if(d.forms[form_name][i].type == 'checkbox' && d.forms[form_name][i].checked)
		  {
			  str = str + "&c[]=" + d.forms[form_name][i].value;
	      }
	}
//	alert(str);
	winopen(str, 400, 400, 0, 1);
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function order_mvideo(videoid)
{
	var str=myhost + "/order.php?ordermode=mvideo&videoid=" + videoid;

//	for(var i=0; i<d.forms[form_name].elements.length; i++)
//	{
//		if(d.forms[form_name][i].id == 'ordermp3' || d.forms[form_name][i].id == 'all' || d.forms[form_name][i].id == 'alll') break;
//		if(d.forms[form_name][i].type == 'checkbox' && d.forms[form_name][i].checked)
//		  {
//			  str = str + "&c[]=" + d.forms[form_name][i].value;
//	      }
//	}

//alert(str);

	winopen(str, 400, 400, 0, 1);
}


////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function order_one_mp3(form_name,songid)
{
	var str=myhost + "/functions/mp3ordermass.php?";
    var songid="song" + songid;

	if(d.getElementById(songid))
	{
		d.getElementById(songid).checked = true;
		str = str + "&c[]=" + d.getElementById(songid).value;

		count(form_name);
		winopen(str, 400, 400, 0, 1);
	}
}


////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function break_line()
{
	var tmp=document.getElementById("textarea").value;
	tmp+="<br>";
	document.getElementById("textarea").value=tmp;
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function goto_link(str)
{
	document.location=str;
}