var myImage = new Image;
myImage.src = "/images/uraan/sliderddBar.gif";
function waitfun(dvid)
{
	$(dvid).innerHTML = '<img boder="0" src="/images/uraan/sliderddBar.gif" alt="Wait...">';	
}
function waitspan(dvid)
{
	$(dvid).innerHTML = '<span style="padding-left:300px" align="center"><img boder="0" src="/images/uraan/sliderddBar.gif" alt="Wait..."></span>';	
}
function pageRedirection(action,pageurl,formid)
{
	if(action=='delete' || action == 'cancel')
	{
		if(document.getElementById('chk_count'))
		{
			test = 0;
			var count=document.getElementById('chk_count').value;
			for(var i=1;i<=count;i++)
			{
				if(document.getElementById('chk_'+i).checked==true)
				{test = 1;break;}
			}
			if(test == 1) 
			{
				//item_name = document.getElementById('item_name').innerHTML; 
				if(confirm('Are you sure you want to '+action))
				{ 
					document.getElementById(formid).action=pageurl;
					document.getElementById(formid).submit();
				}
			}
			else
			{
			  alert('Please select the record');
			}
		}
	}
	else if(action=='edit')
	{
		if(document.getElementById('chk_count'))
		{
			test = 0;
			var count=document.getElementById('chk_count').value;
			for(var i=1;i<=count;i++)
			{
				if(document.getElementById('chk_'+i).checked==true)
				{
					var chkid=document.getElementById('chk_'+i).value;
					test ++ ;
					
				}
			}
			if(test == 1)
			{	  
			  location.href=pageurl+'/'+chkid;
			  //document.getElementById(formid).submit();	
			}
			else
			{
			  alert('Please select one record');
			}
		}
			
	}
	
}


//  Portion Start (Tanveer)

function add(fieldname,formid,flag)
{

  val = document.getElementById(fieldname).value
  if(val!='') {
	  
	  if(flag == 'category')	
	  {	
	    if(confirm("Are you sure you want to create a main category as '"+val+"'?"))
		{ 
			document.getElementById(formid).submit();
		}
		return false;
	  }
	  else if(flag == 'subcategory')
	  {
		catname = document.getElementById('catname').value
		if(confirm("Are you sure you want to create a subcategory as '"+val+"' for '"+catname+"' ?"))
		{ 
			document.getElementById(formid).submit();
		} 
		return false;
		  
	  }
	  
  }
  else
    document.getElementById(formid).submit();
	
	
}

function edit(fieldname,formid,flag)
{

  val_old = document.getElementById('oldname').value
  val_new = document.getElementById(fieldname).value
  if(val_new!='') {
	  
	  if(flag == 'category')
	  {
		if(confirm("Are you sure you want to change from '"+val_old+"' to '"+val_new+"' ?"))
		{ 
			document.getElementById(formid).submit();
		}
		return false; 
	  }
	  else if(flag == 'subcategory')
	  {
		catname = document.getElementById('catname').value
		if(confirm("Are you sure you want to change from '"+val_old+"' to '"+val_new+"' for '"+catname+"' ?"))
		{ 
			document.getElementById(formid).submit();
		} 
		return false;
		  
	  }
  }
  else
    document.getElementById(formid).submit();
	
	
}

function addset()
{
	
	setname =  document.getElementById('setname').value
	limit =  document.getElementById('limit').value
	stock_qty = document.getElementById('qty').value
	fdate = document.getElementById('txt_fdate').value
	tdate = document.getElementById('txt_edate').value
	var itemprice = ''
	itemprice = document.getElementById('items_price').innerHTML
	document.getElementById('totalprice').value = itemprice
    items_list = '';
	item_list = document.getElementsByName('txt_list[]')
   if(setname != '' && limit != '' && item_list[0].length > 0 )
   {
	   a = document.getElementsByName('txt_list[]')
       for(i=0; i < a[0].length; i++)
       {
	      //alert(a[0][i].text)
		  items_list += a[0][i].text+'\n';
       }
		
		if(confirm("Are you sure you want to create a set with the following information?\n\nName: "+setname+"\nPurchase limit: "+limit+"\nStock Quantity Limit: "+stock_qty+"\nAvailable from "+fdate+" to "+tdate+"\nHaving price = $ "+itemprice+" for items:\n"+items_list+""))
		{ 
			checkSetValidation();
			document.getElementById('set_frm').submit();
		} 
	    return false;
   }
   checkSetValidation();
   document.getElementById('set_frm').submit();
		  
		
}

function editset()
{
	setname =  document.getElementById('setname').value
	limit =  document.getElementById('limit').value
	stock_qty = document.getElementById('qty').value
	fdate = document.getElementById('txt_fdate').value
	tdate = document.getElementById('txt_edate').value
	var itemprice = ''
	itemprice = document.getElementById('items_price').innerHTML
	document.getElementById('totalprice').value = itemprice
    items_list = '';
   
   item_list = document.getElementsByName('txt_list[]')
   if(setname != '' && limit != '' && item_list[0].length > 0)
   {
		
       a = document.getElementsByName('txt_list[]')
       for(i=0; i < a[0].length; i++)
       {
	      //alert(a[0][i].text)
		  items_list += a[0][i].text+'\n';
       }
	
	  
	
		if(confirm("Are you sure you want to change a set with the following information?\n\nName: "+setname+"\nPurchase limit: "+limit+"\nStock Quantity Limit: "+stock_qty+"\nAvailable from "+fdate+" to "+tdate+"\nHaving price = $ "+itemprice+" for items:\n"+items_list+""))
		{ 
			checkSetValidation();
			document.getElementById('set_frm').submit();
		} 
	    return false;
   }
   checkSetValidation();
   document.getElementById('set_frm').submit();
	
			
}

function creatcopyset()
{
	setname =  document.getElementById('setname').value
	limit =  document.getElementById('limit').value
	stock_qty = document.getElementById('qty').value
	fdate = document.getElementById('txt_fdate').value
	tdate = document.getElementById('txt_edate').value
	var itemprice = ''
	itemprice = document.getElementById('items_price').innerHTML
	document.getElementById('totalprice').value = itemprice
    items_list = '';
   
   item_list = document.getElementsByName('txt_list[]')
   if(setname != '' && limit != '' && item_list[0].length > 0)
   {
		
       a = document.getElementsByName('txt_list[]')
       for(i=0; i < a[0].length; i++)
       {
	      //alert(a[0][i].text)
		  items_list += a[0][i].text+'\n';
       }
	
	  
	
		if(confirm("Are you sure you want to create a set with the following information?\n\nName: "+setname+"\nPurchase limit: "+limit+"\nStock Quantity Limit: "+stock_qty+"\nAvailable from "+fdate+" to "+tdate+"\nHaving price = $ "+itemprice+" for items:\n"+items_list+""))
		{ 
			checkSetValidation();
			document.getElementById('set_frm').action='/admin/set/newsetcopy';
			document.getElementById('set_frm').submit();
		} 
	    return false;
   }
   checkSetValidation();
   document.getElementById('set_frm').action='/admin/set/newsetcopy';
   document.getElementById('set_frm').submit();
	
			
}

function checkSetValidation()
{
   
   var ListB = document.getElementById("txt_list");
   if(ListB.length>0)
   {
	   for (var i=0; i < ListB.length; i++) {
					
			ListB.options[i].selected = true;
					
	   }
   }
   //else
   //{
	//	  alert('Please select items');
		//  return false;
   //} 
   
   var ListTag = document.getElementById("tag_list");
   if(ListTag.length>0)
   {
	   for (var i=0; i < ListTag.length; i++) {
					
			ListTag.options[i].selected = true;
					
	   }
   }
   

}

// End Portion

function checkAll()
{
	if(document.getElementById('chk_count'))
	{
		var count=parseInt(document.getElementById('chk_count').value);
		if(document.getElementById('toggle').checked==true){
			for(var i=1; i<=count; i++){document.getElementById('chk_'+i).checked=true;}
		}else{
			for(var i=1; i<=count; i++){document.getElementById('chk_'+i).checked=false;}
		}
	}
}
function uncheck()
{
	var total=parseInt(document.getElementById('chk_count').value);
	//alert(document.getElementById('chk_count').value)
	for(var i=1; i<=total; i++){if(document.getElementById('chk_'+i).checked==false){document.getElementById('toggle').checked=false;return false;}
		else{document.getElementById('toggle').checked=true;}
	}
	
}
// -------------------------------------------------------------------
// hasOptions(obj)
// Utility function to determine if a select object has an options array
// Imran Munawar Khan
// -------------------------------------------------------------------
function hasOptions(obj) {
	if (obj!=null && obj.options!=null) { return true; }
	return false;
	}
// -------------------------------------------------------------------
// swapOptions(select_object,option1,option2)
// Swap positions of two options in a select list
// Imran Munawar Khan
// -------------------------------------------------------------------
function swapOptions(obj,i,j) {
	var o = obj.options;
	var i_selected = o[i].selected;
	var j_selected = o[j].selected;
	var temp = new Option(o[i].text, o[i].value, o[i].defaultSelected, o[i].selected);
	var temp2= new Option(o[j].text, o[j].value, o[j].defaultSelected, o[j].selected);
	o[i] = temp2;
	o[j] = temp;
	o[i].selected = j_selected;
	o[j].selected = i_selected;
	}
// -------------------------------------------------------------------
// moveOptionUp(select_object)
// Move selected option in a select list up one
// Imran Munawar Khan
// -------------------------------------------------------------------
function moveOptionUp(obj) {
	if (!hasOptions(obj)) { return; }
	for (i=0; i<obj.options.length; i++) {
		if (obj.options[i].selected) {
			if (i != 0 && !obj.options[i-1].selected) {
				swapOptions(obj,i,i-1);
				obj.options[i-1].selected = true;
				}
			}
		}
	}
// -------------------------------------------------------------------
// moveOptionDown(select_object)
// Move selected option in a select list down one
// Imran Munawar Khan
// -------------------------------------------------------------------
function moveOptionDown(obj) {
	if (!hasOptions(obj)) { return; }
	for (i=obj.options.length-1; i>=0; i--) {
		if (obj.options[i].selected) {
			if (i != (obj.options.length-1) && ! obj.options[i+1].selected) {
				swapOptions(obj,i,i+1);
				obj.options[i+1].selected = true;
				}
			}
		}
	}
// -------------------------------------------------------------------
// removeOprion(select_object)
// Move selected option in a select list down one
// Imran Munawar Khan
// -------------------------------------------------------------------
function removeOprion(theSel)
{
	var selIndex = theSel.selectedIndex;
	
	if (selIndex != -1) {
		for(i=theSel.length-1; i>=0; i--)
		{
		  if(theSel.options[i].selected)
		  {
			theSel.options[i] = null;
		  }
		}
		if (theSel.length > 0) {
		  theSel.selectedIndex = selIndex == 0 ? 0 : selIndex - 1;
		}
	}
}
// -------------------------------------------------------------------
// selectAllOprion(select_object)
// Move selected option in a select list down one
// Imran Munawar Khan
// -------------------------------------------------------------------
function selectAllOprion(selectBox,selectAll) {
	// have we been passed an ID
	if (typeof selectBox == "string") {
		selectBox = document.getElementById(selectBox);
	}
	// is the select box a multiple select box?
	if (selectBox.type == "select-multiple") {
		for (var i = 0; i < selectBox.options.length; i++) {
			selectBox.options[i].selected = selectAll;
		}
	}
}
// -------------------------------------------------------------------
// searchDetail()
// Move selected option in a select list down one
// Imran Munawar Khan
// -------------------------------------------------------------------
function searchDetail(fun)
{
	document.getElementById('product').action='/admin/module/'+fun;
	document.getElementById('product').submit();
}
// -------------------------------------------------------------------
// optionDetail()
// Move selected option in a select list down one
// Imran Munawar Khan
// -------------------------------------------------------------------
function optionDetail()
{
	tchk=parseInt(document.getElementById('chk_count').value);
	list = document.getElementById('txt_list');
	//list.length=0;
	for(i=1;i<=tchk;i++)
	{
		if(document.getElementById('chk_'+i).checked)
		{
			schk=document.getElementById('chk_'+i).value
			schk=schk.split('_');
			list[list.length]=new Option(schk[1],schk[0],false,false);
		}
	}
}
// -------------------------------------------------------------------
// optionDetail()
// Move selected option in a select list down one
// Imran Munawar Khan
// -------------------------------------------------------------------
function listOptionDetail()
{
	tchk=parseInt(document.getElementById('chk_count').value);
	list = document.getElementById('txt_list');
	list.length=0;
	for(i=1;i<=tchk;i++)
	{
		if(document.getElementById('chk_'+i).checked)
		{
			schk=document.getElementById('hd_'+i).value
			schk=schk.split('_');
			list[list.length]=new Option(schk[1],schk[0],false,false);
		}
	}
}
// -------------------------------------------------------------------
// optionDetail()
// Move selected option in a select list down one
// Imran Munawar Khan
// -------------------------------------------------------------------
function editOptionDetail()
{
	tchk=parseInt(document.getElementById('chk_count').value);
	list = document.getElementById('txt_list');
	for(i=1;i<=tchk;i++)
	{
		if(document.getElementById('chk_'+i).checked)
		{
			schk=document.getElementById('chk_'+i).value
			schk=schk.split('_');
			list[list.length]=new Option(schk[1],schk[0],false,false);
		}
	}
}


function editsubcat(action,pageurl,formid)
{
   if(document.getElementById('chk_count'))
   {
	   if(action=='edit')
		{
			test = 0;
			var count=document.getElementById('chk_count').value;
			for(var i=1;i<=count;i++)
			{
				if(document.getElementById('chk_'+i).checked==true)
				{
					var chkid=document.getElementById('chk_'+i).value;
					test = 1;
					break;
				}
			}
			if(test == 1)
			{	  
			  catid=document.getElementById('catid').value;
			  location.href=pageurl+'/'+chkid+"?catid="+catid;
			  //document.getElementById(formid).submit();	
			}
			else
			{
			  alert('Please select the record');
			}
			
		}	
   }
}
function editFun(action,pageurl,formid)
{
   if(action=='edit')
	{
		test = 0;
		var count=document.getElementById('chk_count').value;
		for(var i=1;i<=count;i++)
		{
			if(document.getElementById('chk_'+i).checked==true)
			{
				var chkid=document.getElementById('chk_'+i).value;
				test = 1;
				break;
			}
		}
		if(test == 1)
		{	  
		   location.href=pageurl+"&imgid="+chkid;
		  //document.getElementById(formid).submit();	
		}
		else
		{
		  alert('Please select the record');
		}
		
	}	
}
function editProd(action,pageurl,formid)
{
   if(action=='edit')
	{
		test = 0;
		var count=document.getElementById('chk_count').value;
		for(var i=1;i<=count;i++)
		{
			if(document.getElementById('chk_'+i).checked==true)
			{
				var chkid=document.getElementById('chk_'+i).value;
				test = 1;
				break;
			}
		}
		if(test == 1)
		{	  
		   location.href=pageurl+"?pid="+chkid;
		  //document.getElementById(formid).submit();	
		}
		else
		{
		  alert('Please select the record');
		}
		
	}	
}
function statustoggle(id,controller)
{
   //$(id+'status').innerHTML = 'Wait...';
   waitfun(id+'status');
   new Ajax.Updater(id+'status', '/admin/'+controller+'/statustoggle/'+id, {asynchronous:true});
}
 /// use in set
function optionDetailUpdate()
{
	tchk=parseInt(document.getElementById('chk_count').value);
	list = document.getElementById('txt_list');
	//list.length=0;
	for(i=1;i<=tchk;i++)
	{
		chk = 0
		if(document.getElementById('chk_'+i).checked)
		{
			schk=document.getElementById('chk_'+i).value
			schk=schk.split('_');
			
			
			if(list.length >0)
			{
			  
			   for(k=0;k<list.length;k++)
			   {
				  
				  if(list[k].value == schk[0])
				  chk = 1									 
			   }
			}
			if(chk == 0)
			{
		       list[list.length]=new Option(schk[1],schk[0],false,false);
			}
		}
	}
}

//------------------------------------------End Tanveer Portion ----------------------------------------------

//------------------------------------------Portion start Mueen ----------------------------------------------

function postBid(controller,bidderid,productid,auctionid,forbid,auctiondetail_id)
{
   //if(document.getElementById('divbid'))
   var bidamount=parseFloat(document.getElementById('txtbid').value);
   var startbid=parseFloat(document.getElementById('hdstartbid').value);
   var endbid=parseFloat(document.getElementById('hdendbid').value);
   if ( bidamount == '' || bidamount <= 0 )
   {	
   	alert('Please enter valid bid amount');
	document.getElementById('txtbid').focus();
	return false;
   }
   if ( bidamount < startbid || bidamount > endbid )
   {	
   	var str='Please enter valid bid amount b/w '+startbid+'and '+endbid;
  	alert(str);
	document.getElementById('txtbid').focus();
	return false;
   }
	 
   var url='/webshop/specialitem/'+controller+'/';
   url=url+'?bid='+bidderid+'&bidamount='+bidamount;
   url=url+'&productid='+productid+'&auctionid='+auctionid;
   url=url+'&forbid='+forbid;
   url=url+'&server='+document.getElementById('server_list').value+'&character='+document.getElementById('character_list').value
   if(auctiondetail_id !='')
   	url=url+'&auctiondetail_id='+auctiondetail_id;
   //alert(url);
   //$('p_cart').innerHTML = 'Wait ...'
   waitfun('p_cart');
   new Ajax.Updater('p_cart',url, {asynchronous:true,onComplete:function()
																{
																  if($('bidresult')){	 	 
																	$('span_current_bid').innerHTML = bidamount+" AP's"
																	$('btnbid').innerHTML = 'Change Bid'}
																  	
																  if($('bid_expired'))	 	 
																	$('p_cart').innerHTML = $('bid_expired').innerHTML
																	
																 refreshAuction('specialitemdetailrefreshbid',bidderid,productid,auctionid);
																}});
}
function changeBid(controller,bidderid,productid,auctionid,forbid,auctiondetail_id,serverid,character)
{
   
   var bidamount=parseFloat(document.getElementById('txtbid').value);
   if ( bidamount == '' || bidamount <= 0 )
   {	
   	alert('Please enter valid bid amount');
	document.getElementById('txtbid').focus();
	return false;
   }
   var startbid=parseFloat(document.getElementById('hdstartbid').value);
   var endbid=parseFloat(document.getElementById('hdendbid').value);
   if ( bidamount < startbid || bidamount > endbid )
   {	
   	var str='Please enter valid bid amount between '+startbid+' and '+endbid;
  	alert(str);
	document.getElementById('txtbid').focus();
	return false;
   }
   var url='/webshop/specialitem/'+controller+'/';
   url=url+'?bid='+bidderid+'&bidamount='+bidamount;
   url=url+'&productid='+productid+'&auctionid='+auctionid;
   url=url+'&forbid='+forbid;
   url=url+'&server='+document.getElementById('server_list').value+'&character='+document.getElementById('character_list').value
   if(auctiondetail_id !='')
   url=url+'&auctiondetail_id='+auctiondetail_id;
   waitfun('p_cart');	
   //$('p_cart').innerHTML = 'Wait ...'
   new Ajax.Updater('p_cart',url, {asynchronous:true,onComplete:function()
																{
																  if($('bidresult'))	 
																	$('span_current_bid').innerHTML = bidamount+" AP's"
																	
																  refreshAuction('specialitemdetailrefreshbid',bidderid,productid,auctionid);	
																}});
				   
}

function refreshAuction(controller,bidderid,productid,auctionid)
{
   //$(bidDiv).innerHTML = 'Wait...';	 
   document.getElementById('table_bidders').innerHTML = '<tr><td align=center><img boder="0" src="/images/uraan/sliderddBar.gif" alt = "Wait..."></td></tr>';	 
   //var bidamount=document.getElementById('txtbid').value;
   var url='/webshop/specialitem/'+controller+'/';
   url=url+'?bid='+bidderid;
   url=url+'&productid='+productid+'&auctionid='+auctionid;
   //alert(url);
   new Ajax.Updater('table_bidders',url, {asynchronous:true,onComplete:function()
																{
																  if($('bidresult'))	 
																	$('tbiders').innerHTML = $('bidresult').innerHTML
																}});
}

function onOksaveSubscription(controller)
{
	

	/*var timeout;
	function openInfoDialog() {
	  Dialog.info("Please wait sunscribing item  <br>in 3s ...",
				   {width:250, height:100, showProgress: true});
	  timeout=3;
	  setTimeout(infoTimeout, 1000)
	}
	
	function infoTimeout() {
	  timeout--;
	  if (timeout >0) {
		Dialog.setInfoMessage("Please wait sunscribing item  <br>in " + timeout + "s ...")
		setTimeout(infoTimeout, 1000)
	 }
	 else
	  Dialog.closeInfo()
	}
	openInfoDialog();
*/
	document.getElementById('subdiv').innerHTML = 'Saving...';	
	var url='/webshop/item/'+controller+'/';
	var discountqty=document.getElementById('hddqty').value;
	var pid=document.getElementById('hdpid').value;
	var pprice=document.getElementById('hdpprice').value;
	var discountfigure=document.getElementById('hddiscount_figure').value;
	var discounttype=document.getElementById('hddiscount_type').value;
	var hdsmode=document.getElementById('hdsmode').value;
	document.getElementById('hdfor').value=1;
	var txtdur=document.getElementById('txtdur').value;
	var txtsubtime=document.getElementById('txtsubtime').value;
	var txtquantity=document.getElementById('txtquantity').value;
	
   url=url+'?dur='+txtdur+'&stime='+txtsubtime+'&pid='+pid
   url=url+'&server='+document.getElementById('server_list').value+'&character='+document.getElementById('character_list').value
   //alert(url);
   new Ajax.Updater('subdiv',url, {asynchronous:true});
   
   
   
	
}
function onCancelSubscriptiobPopup(controller,pid,uid)
{
	
    document.getElementById('subdiv').innerHTML = 'Cancelling...';	
	var url='/webshop/item/'+controller+'/';
	document.getElementById('hdfor').value=0;
	url=url+'?pid='+pid;
	url=url+'&uid='+uid;
	new Ajax.Updater('subdiv',url, {asynchronous:true});
   
	
}
function SubscriptiobPopup(prodid) 
{
		
	    var url='/webshop/cart/checkitemforsub/';
   	    url=url+prodid+'?server='+$('server_list').value+'&character='+$('character_list').value;
	    //$('p_cart').innerHTML = 'Wait';
		waitfun('p_cart');
	    new Ajax.Updater('p_cart',url,{asynchronous:true,onComplete:function(){
																			 if ($('p_cart').innerHTML == '')
																			     showSubscriptionPopup()
																			 }});
		
		
}
function showSubscriptionPopup()
{
		Dialog.confirm($('login').innerHTML, {className:"alphacube", width:700,height:300, okLabel: "Save", cancelLabel: "Close", onOk:function(win)
		{ $('serror_msg').innerHTML='Saving Subscription'; $('serror_msg').show(); 
		  return false;}});
}
function cancelSubscriptiobPopup(pid,uid,controller) 
{
		
		 document.getElementById('hdpid').value=pid;
		 document.getElementById('hduid').value=uid;
		 var url='/webshop/item/'+controller+'/';
		 url=url+'?pid='+pid;
		 url=url+'&uid='+uid;
		// alert(url);
		 new Ajax.Updater('cancelmsg',url, {asynchronous:true});
		 
		 Dialog.confirm($('cancelsubdiv').innerHTML, {className:"alphacube", width:700,height:300, okLabel: "Yes", cancelLabel: "No", onOk:function(win)
		{ $('cserror_msg').innerHTML='Cancelling Subscription'; $('cserror_msg').show(); 
		  return false;}});
		 
		
}

function rebateChange()
{
	
	var txtdur=document.getElementById('txtdur').value;
	var txtsubtime=document.getElementById('txtsubtime').value;
	var hddiscount_type=document.getElementById('hddiscount_type').value;
	var hddiscount_figure=document.getElementById('hddiscount_figure').value;
	var txtquantity=document.getElementById('txtquantity').value;	
	var discountqty=document.getElementById('hddqty').value;
	var rebate=document.getElementById('hdrebate').value;
	var totalrebate=parseFloat(txtsubtime)*parseInt(txtquantity);
	if (txtsubtime == 0)
	  txtsubtime = document.getElementById('txtsubtime').value=1;
	if( txtdur == 0 )
	 txtdur = document.getElementById('txtdur').value=1;
	var totalsubscription;
	if ( String(hddiscount_type)=="Amount")
	{
		if (txtsubtime == "" || isNaN(txtsubtime))
		   txtsubtime = 0
		if (txtquantity == "" || isNaN(txtquantity))
		   txtquantity = 0
		if (txtdur == "" || isNaN(txtdur))
		   txtdur = 0
		
		 totalsubscription = parseFloat(txtsubtime)*parseInt(txtquantity)*parseFloat(txtdur);
		
		if (parseInt(totalsubscription) >= parseInt(discountqty)) 
		{    
		    mod = totalsubscription / discountqty
			document.getElementById('rebateDiv').innerHTML=rebate*mod;
			
		}
		else
		{
			document.getElementById('rebateDiv').innerHTML=0;
		}
	}
	else	
	{
	   if (txtsubtime == "" || isNaN(txtsubtime))
		   txtsubtime = 0
		if (txtquantity == "" || isNaN(txtquantity))
		   txtquantity = 0
		if (txtdur == "" || isNaN(txtdur))
		   txtdur = 0
		
		 totalsubscription = parseFloat(txtsubtime)*parseInt(txtquantity)*parseFloat(txtdur);
		 
		 
		if (parseInt(totalsubscription) >= parseInt(discountqty)) 
			document.getElementById('rebateDiv').innerHTML=(parseFloat(totalsubscription)*parseFloat(hddiscount_figure)) / 100;
		else
		{
			document.getElementById('rebateDiv').innerHTML=0;
		}

	}
	document.getElementById('totalDiv').innerHTML=totalsubscription;

		
}
//------------------------------------------End mueen Portion ----------------------------------------------

//------------------------------------------Portion start Tanveer(Client End)---------------------------------
function unfold(select_id,record_id)
{
  //location.href='/category/testpage';
  total_cat = document.getElementById('menu_total_cat').value  
  for(i=1;i<=total_cat;i++)
  {
    if(document.getElementById(i).style.display == 'block' && i!=select_id)
     document.getElementById(i).style.display = 'none'
   
  }
  
  if(document.getElementById(select_id).style.display == 'block')
   document.getElementById(select_id).style.display = 'none'
  else
   document.getElementById(select_id).style.display = 'block'
  
 
  loadsubcategory(record_id)
}

function showhistory()
{
 
  //$('mydiv').innerHTML = 'Wait...';
  waitfun('mydiv');
  //new Ajax.Updater('mydiv', '/history/index', {asynchronous:true});
  new Ajax.Updater('mydiv','/webshop/history/index',{method:'post',parameters:'',asyncronouse:true,onComplete:function()
		{	
			 //$('searchresult').innerHTML = 'Wait...';
			 waitfun('searchresult');
			 new Ajax.Updater('searchresult', '/webshop/history/purchaselist', {asynchronous:true});
             new Ajax.Updater('search_subscription', '/webshop/history/subscriptionlist', {asynchronous:true});
			 
		}
});
  
}


function changehistorystatus(subscription_id,status)
{
  
  $('status'+subscription_id).innerHTML = 'Wait...';
  //waitfun('status'+subscription_id);
  new Ajax.Updater('status'+subscription_id, '/webshop/history/changesubscriptionstatus/'+subscription_id+'?status='+status, {asynchronous:true});	
  //$('status'+subscription_id).innerHTML=status;
}
function changehistorysuspend(subscription_id)
{
  
  $('status'+subscription_id).innerHTML = 'Wait...';
  //waitfun('status'+subscription_id);
  new Ajax.Updater('status'+subscription_id, '/webshop/history/changesubscriptionstatus/'+subscription_id+'?status=sus_toggle', {asynchronous:true,onComplete:function(){
   if ($('hidden_status_sus') && $('hidden_status_sus').innerHTML != '')																																									
	   $('span_sus').innerHTML = $('hidden_status_sus').innerHTML;
																																									}});	
  //$('status'+subscription_id).innerHTML=status;
}
function showcart()
{
	//$('mydiv').innerHTML = 'Wait...';
	waitfun('mydiv');
	new Ajax.Updater('mydiv','/webshop/cart/index', {asynchronous:true});
	
}

function deletecartitem(cartid,index,costtype)
{
  if(confirm('Are you sure you want to delete this item form the cart'))
  {
	//alert('cost'+index)
	price = $('cost'+index).innerHTML
	 if(costtype == 'AP')
	 totalamount = $('totalcost_ap').innerHTML
	 else if(costtype == 'BP')
	 totalamount = $('totalcost_bp').innerHTML
	 remaining = parseFloat(totalamount)-parseFloat(price)
	 remainingitem = $('totalitem').innerHTML
	 remainingitem = parseInt(remainingitem)-1
	 if(remainingitem>1)
	 remainingitem += ' Items'
	 else
	 remainingitem += ' Item'
	 //$('div'+cartid).innerHTML = 'Wait...';
	 waitfun('div'+cartid);
	  //new Ajax.Updater('mydiv', '/webshop/cart/deleteitem/'+cartid, {asynchronous:true});
	 new Ajax.Updater('msg_show','/webshop/cart/deleteitem/'+cartid,{method:'post',parameters:'',asyncronouse:true,onComplete:function()
			{
				
				
				$('totalitem').innerHTML = remainingitem
				if(costtype == 'AP')
				$('totalcost_ap').innerHTML = remaining
				else if(costtype == 'BP')
				$('totalcost_bp').innerHTML = remaining
				$('div'+cartid).parentNode.removeChild($('div'+cartid))			
				 
			}
	});  
  }
 

}

function changeqty(cartid,cost,index)
{
  newqty = $('qty'+cartid).value
  //final_cost = parseFloat(cost)*parseFloat(newqty)
  if(newqty<=0 || isNaN(newqty))
  {
   $('single_msg'+cartid).innerHTML = 'Invalid Quantity' 
  }
  else
  {
	 //new Ajax.Updater('hiddenqty', '/webshop/cart/cartorignalqty/'+cartid, {asynchronous:true}); // get orginal qty
	 $('single_msg'+cartid).innerHTML='Wait...'
	 //waitfun('single_msg'+cartid);
	 new Ajax.Updater('single_msg'+cartid,'/webshop/cart/changeqty/'+cartid+'/?qty='+newqty,{method:'post',parameters:'',asyncronouse:true,onComplete:function()
			{
				
				newqty = $('qty'+cartid).value
                final_cost = parseFloat(cost)*parseFloat(newqty)
				if(trim($('single_msg'+cartid).innerHTML) != '') 
				{
				  //$('qty'+cartid).value = $('oldqty'+cartid).innerHTML
				  $('qty'+cartid).value = trim($('oldqty'+index).innerHTML)
				  //$('qty'+cartid).value = $('hiddenqty').innerHTML
				}
				else
				{
				  $('oldqty'+index).innerHTML = newqty;
				  $('cost'+index).innerHTML = round(final_cost);
				  total_items = $('totalitems').value;

				  var final_total_cost_ap = 0;
				  var final_total_cost_bp = 0;
				  for(i=0;i<total_items;i++)
                  {
					  if(document.getElementById('oldqty'+i)) {
					    var type = document.getElementById('costtype'+i).innerHTML.toString();
						var type = trim(type);
						if(type=='AP'){
						final_total_cost_ap = parseFloat(final_total_cost_ap)+parseFloat($('cost'+i).innerHTML);}
						if(type=='BP'){
						final_total_cost_bp = parseFloat(final_total_cost_bp)+parseFloat($('cost'+i).innerHTML);}
					  }
                  }
				  $('totalcost_ap').innerHTML = round(final_total_cost_ap);
				  $('totalcost_bp').innerHTML = round(final_total_cost_bp);
				}
				
			}
	});  
	
  }
}
function round(number)
{
	return Math.round(number*100)/100
}
function trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}
function checkoutprocess()
{
 
  //new Ajax.Updater('msg_show', '/webshop/cart/checkout', {asynchronous:true});	  
   $('btnprocess').style.display = 'inline';
   $('btnchk').style.display = 'none';
   new Ajax.Updater('msg_show','/webshop/cart/checkout',{method:'post',parameters:'',asyncronouse:true,onComplete:function()
			{
				
				if($('msg_show').innerHTML == ''){
				showhistory();
				}
				else{
				  $('btnprocess').style.display = 'none';
   				  $('btnchk').style.display = 'inline';
				}
				
			}
	});  
  
}

function getusercharacter(server_id)
{
	
	
	//$('character').innerHTML = ' <div align=center style="padding-left:20px;width:50px"><img boder="0" src="/images/uraan/sliderddBar.gif" alt = "Wait..." /></div>';
	//waitfun('character');
	browser = navigator.appName
	if (browser == 'Microsoft Internet Explorer')
	  $('character').innerHTML = '<img boder="0"  style="padding-left:20px;" src="/images/uraan/sliderddBar.gif" alt = "Wait..." />'
	else
	  $('character').innerHTML = '<div align=center style="padding-left:20px;width:50px"><img boder="0" src="/images/uraan/sliderddBar.gif" alt = "Wait..." /></div>'
	new Ajax.Updater('character','/webshop/item/getcharacter/'+server_id, {asynchronous:true});
	
}

//---------------------------------------Portion End Tanveer(Client End)--------------------------------------
//---------------------------------------Portion Start Babar--------------------------------------------------

function loadsubcategory(id)
{
   //$('mydiv').innerHTML = 'Wait...';
   //new Ajax.Updater('mydiv', '/category/detail/'+id, {asynchronous:true});
    waitfun('mydiv');
    //new Ajax.Updater('mydiv', '/webshop/category/index', {asynchronous:true});
    new Ajax.Updater('mydiv','/webshop/category/index',{method:'post',parameters:'',asyncronouse:true,onComplete:function()
		{	
			 new Ajax.Updater('tab', '/webshop/category/subcattabs/'+id, {asynchronous:true});
             new Ajax.Updater('plist', '/webshop/category/productlist/'+id, {asynchronous:true});
		}
});
//new Ajax.Updater('mydiv', '/category/detail/'+id, {asynchronous:true});
}

function showproducts(catid,suncatid)
{
	//$(suncatid).className='selected'
	var url='/webshop/category/productlist/';
   	url=url+catid;
	url=url+'?subcatid='+suncatid;
   //	alert(url);
    waitfun('mydiv');
	new Ajax.Updater('mydiv',url,{asynchronous:true});
 	
}

function _renderTabs(index) {
	var active = $("subcat_" + index).up().up().up();
	var tabs = active.up().childElements();
	var alreadyactive = active.hasClassName('active');
	if (!active.hasClassName('active')) {
		for (i = 0; i < tabs.length; i++) {
			var tab = tabs[i];
			if (tab == active) {
				tab.toggleClassName('active')
			} else if (tab.hasClassName('active')) {
				tab.toggleClassName('active');
			}
		}
	} else {
		for (i = 0; i < tabs.length; i++) {
			var tab = tabs[i];
			tab.removeClassName('active');
		}
	}
	return alreadyactive;
}

function showproductslist(catid,suncatid,index) {
	var active = _renderTabs(index);
	var url = '/webshop/category/productlist/';
	url = url + catid;
	url = url + '?subcatid=' + suncatid;
	waitspan('plist');
	new Ajax.Updater('plist',url,{asynchronous:true,onComplete:function(){
		if (Prototype.Browser.IE) _renderTabs(index);
	}});
	if (!active && Prototype.Browser.IE) _renderTabs(index);
}

function showset(setid)
{
	var url='/webshop/set/setdetail/';
   	url=url+setid;
   //	alert(url);
	waitfun('mydiv');
	new Ajax.Updater('mydiv',url,{asynchronous:true});
 	
}
function cancel_shop_cart(div)
{
	$(div).innerHTML = ''
}
function shop_cart(prodid,type,force)
{
   if (!force || force=='')
           force = 0
   if (type == 'Set')
   {
		var url='/webshop/cart/shopcartset/';
		url=url+prodid+'?type='+type+'&server='+$('server_list').value+'&character='+$('character_list').value+'&force='+force;
		//$('p_cart').innerHTML = 'Wait';
		waitfun('p_cart');
		new Ajax.Updater('p_cart',url,{asynchronous:true,onComplete:function(){if($('shop_redirect'))showcart();}});
   }
   else
   {
		var url='/webshop/cart/shopcart/';
		url=url+prodid+'?type='+type+'&server='+$('server_list').value+'&character='+$('character_list').value+'&force='+force;
		//$('p_cart').innerHTML = 'Wait';
		waitfun('p_cart');
		new Ajax.Updater('p_cart',url,{asynchronous:true,onComplete:function(){if($('shop_redirect'))showcart();}});
   }
}
/*function enterSearch(val)
{
	for(var j=0; j < val.length; j++)
	{
  		
		var alphaa = val.charAt(j);
  		alert(alphaa.charCode)
		var hh = alphaa.charCodeAt(0);
		/*if((hh == 13)
  		{
			alert(hh);
    	}
		else 
		{
      		alert('ssssssss');
			return false;
  		}	}
	return true;
}*/
function enterSearch(e)
{
	 
	 if(window.event){e = window.event;}
     keycode = e.keyCode;
	 if(keycode == 13)
	 {
		if($('search').value != '')
		{
			new Ajax.Updater('searchresult','/webshop/search/result/?type='+$('searchby').value+'&search='+$('search').value, {asynchronous:true,method:'get'}); 
			$('searchresult').innerHTML = 'Wait...'
		}
		else
		{
			alert('Please enter some value');
			return false;
		}	
	 }
	 return true;
}
/*function enterSearch(val)
{
	if(event.keyCode=='13')
	{
		alert('enter');
	}
	
/*	if($('search').value != '')
	{
		new Ajax.Updater('searchresult','/webshop/search/result/?type='+$('searchby').value+'&search='+$('search').value, {asynchronous:true,method:'get'}); 
		$('searchresult').innerHTML = 'Wait...'
	}
	else
	{
		alert('Please enter some value')
	}	
}*/

function unfoldsets() {
  if (document.getElementById("webshop_sets").style.display == 'block') {
    document.getElementById("webshop_sets").style.display = 'none';
  } else { 
    document.getElementById("webshop_sets").style.display = 'block';
  }
  loadsets();
}

function loadsets() {
  waitfun('mydiv');
  new Ajax.Updater('mydiv', '/webshop/set/index', { method: 'post', parameters: '', asyncronouse: true, onComplete: function()
    {
      //new Ajax.Updater('tab', '/webshop/set/subsettabs', { asynchronous: true });
      new Ajax.Updater('plist', '/webshop/set/setlist', { asynchronous: true });
    }
  });
}

