/* mgscripts.js
 This file will contain all javascripts used by monsoongallery pages. 
 To be placed in the Library folder
 */

function addToCart(prodid) {
  //alert(prodid);
   document.location.href="cartprocess.php?user_action=a&prod_id="+prodid;
}

 function showCart(divID,prod_id) {
   	// this function has a dependency on ajaxdelegate.js'
   	//alert("In showcart");
   	npid=document.getElementById("new_prodid");
   	if(npid.value != "")
   	{
   		if(parseInt(npid.value) != parseInt(prod_id))
   	   	prod_id=npid.value;
   	}   	
    //alert(prod_id);	
   	var requestUrl = 'showcartbutton.php?prod_id=' + prod_id ;
 	  var ajax = new AjaxDelegate(requestUrl, showCartButton, divID, prod_id);
    ajax.Fetch();
  }

function showCartButton(url, response,divID, prod_code) {
	// the callback method
	obj=document.getElementById(divID);
	if(obj != null){
		obj.innerHTML = response;
	}
} 

function goshop() {
	location.href="showartists.php";
}	

function validateCoupon() {
   cid=document.getElementById('couponid').value;
   code=document.getElementById('couponcode');
   code.value=cid;
   document.location.href="cartprocess.php?user_action=v&cid="+cid;
}
/*function checkout() {
		document.getElementById('user_action').value = 'c';
	  document.form[0].submit();



	 cid=document.getElementById('couponid').value;
   document.location.href="cartprocess.php?user_action=c";
}*/

function makepayment() {
	document.getElementById('user_action').value = 'p';
	document.form[0].submit();
}

function showNewValues(obj)
{
 //Price
  var nprice=document.getElementById("price");
  var strp= "<B> Sale Price : </B> $"+obj.value;
  nprice.innerHTML=strp;
  //Title
  var ntitle=document.getElementById("ptitle");
  var indx = obj.selectedIndex;
  var selected_text = obj.options[indx].text;
	var strt= "<B> Title : </B>"+selected_text;
	ntitle.innerHTML=strt;
	//Change new_prodid
	pid=document.getElementById("prod_id");
  npid=document.getElementById("new_prodid");
  npid.value=parseInt(pid.value) + parseInt(indx);
	alert(npid.value);
 }



/*
function checkAll(obj) {
	var flg = false ;
  if (obj.checked) { flg = true; }
  obj1 = document.getElementsByName(obj.name);
	for (i=1;i<obj1.length; i++)
	{
	  obj1[i].checked = flg;
	}
}

function getCheckedValue(name) {
  var st=document.location.href;
  var chkdIDs = '0' ;
  obj1 = document.getElementsByName(name);
	for (i=0;i<obj1.length; i++)
	{
		if(obj1[i].checked){
			chkdIDs = chkdIDs + ',' + obj1[i].value;
		}
	}
	if ( chkdIDs == '0'||chkdIDs == ''){
	   alert ("No records selected");
	   return false;
	 }else{
 	 var ans= confirm("Selected records will be deleted.Do you wish to continue?");
   if (ans==true)
    {
     // R>> Add code here to remove the '0 from the string
      var redirectTo=document.location.href;
     if (st.indexOf("prod_list.php") != -1){
       redirectTo+="prod_process.php?prodIds="+chkdIDs;
       window.location=redirectTo;
      }
    }
	} 
}
*/
/*Code from :  http://wcs.wayne.edu/blog/2008/05/28/javascript-on-window-close-event/ - Using jquery

$(window).bind('load', function(e){
  close_window = true;
  logged_out = false;
  $("a").bind('click', function(e){
    if(!$(this).hasClass('clickable'))
      close_window = false;
    });
  $("form").bind('submit', function(e){
    close_window = false;
  });
  if (window.addEventListener) {
    window.addEventListener('beforeunload', message, false);
  } else {
    window.attachEvent('onbeforeunload', message);
  }
});

function message(ev) {
  if(close_window){
    if (ev.stopPropagation) {
      ev.stopPropagation();
    } else {
      ev.cancelBubble = true;
    }
    if (ev.preventDefault) {
      logout();
    } else {
      logout();
      ev.returnValue = "Leaving?";
    }
  }
}

function logout(){
  if(!logged_out){
    $.ajax({
      type: "GET",
      url: '../admin/logout.php',
      data: "logout=true",
      async: false,
      cache: false,
      success: function(msg){
        console.log("Ajax Repsonse: "+msg);
        logged_out = true;
      }
    });
  }
}
*/