/* Simple AJAX Code-Kit (SACK) v1.6.1 */
/* ©2005 Gregory Wild-Smith */
/* www.twilightuniverse.com */
/* Software licenced under a modified X11 licence,
   see documentation or authors website for more details */
var SITE_PATH = window.location.protocol+"//www.pcgamesupply.com";

var ajax = new sack();   
var ajax1 = new sack();
var ajax2 = new sack();
var ajax3 = new sack();
   
function sack(file) {
	this.xmlhttp = null;

	this.resetData = function() {
		this.method = "POST";
  		this.queryStringSeparator = "?";
		this.argumentSeparator = "&";
		this.URLString = "";
		this.encodeURIString = true;
  		this.execute = false;
  		this.element = null;
		this.elementObj = null;
		this.requestFile = file;
		this.vars = new Object();
		this.responseStatus = new Array(2);
  	};

	this.resetFunctions = function() {
  		this.onLoading = function() { };
  		this.onLoaded = function() { };
  		this.onInteractive = function() { };
  		this.onCompletion = function() { };
  		this.onError = function() { };
		this.onFail = function() { };
	};

	this.reset = function() {
		this.resetFunctions();
		this.resetData();
	};

	this.createAJAX = function() {
		try {
			this.xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e1) {
			try {
				this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e2) {
				this.xmlhttp = null;
			}
		}

		if (! this.xmlhttp) {
			if (typeof XMLHttpRequest != "undefined") {
				this.xmlhttp = new XMLHttpRequest();
			} else {
				this.failed = true;
			}
		}
	};

	this.setVar = function(name, value){
		this.vars[name] = Array(value, false);
	};

	this.encVar = function(name, value, returnvars) {
		if (true == returnvars) {
			return Array(encodeURIComponent(name), encodeURIComponent(value));
		} else {
			this.vars[encodeURIComponent(name)] = Array(encodeURIComponent(value), true);
		}
	}

	this.processURLString = function(string, encode) {
		encoded = encodeURIComponent(this.argumentSeparator);
		regexp = new RegExp(this.argumentSeparator + "|" + encoded);
		varArray = string.split(regexp);
		for (i = 0; i < varArray.length; i++){
			urlVars = varArray[i].split("=");
			if (true == encode){
				this.encVar(urlVars[0], urlVars[1]);
			} else {
				this.setVar(urlVars[0], urlVars[1]);
			}
		}
	}

	this.createURLString = function(urlstring) {
		if (this.encodeURIString && this.URLString.length) {
			this.processURLString(this.URLString, true);
		}

		if (urlstring) {
			if (this.URLString.length) {
				this.URLString += this.argumentSeparator + urlstring;
			} else {
				this.URLString = urlstring;
			}
		}

		// prevents caching of URLString
		this.setVar("rndval", new Date().getTime());

		urlstringtemp = new Array();
		for (key in this.vars) {
			if (false == this.vars[key][1] && true == this.encodeURIString) {
				encoded = this.encVar(key, this.vars[key][0], true);
				delete this.vars[key];
				this.vars[encoded[0]] = Array(encoded[1], true);
				key = encoded[0];
			}

			urlstringtemp[urlstringtemp.length] = key + "=" + this.vars[key][0];
		}
		if (urlstring){
			this.URLString += this.argumentSeparator + urlstringtemp.join(this.argumentSeparator);
		} else {
			this.URLString += urlstringtemp.join(this.argumentSeparator);
		}
	}

	this.runResponse = function() {
		eval(this.response);
	}

	this.runAJAX = function(urlstring) {
		if (this.failed) {
			this.onFail();
		} else {
			this.createURLString(urlstring);
			if (this.element) {
				this.elementObj = document.getElementById(this.element);
			}
			if (this.xmlhttp) {
				var self = this;
				if (this.method == "GET") {
					totalurlstring = this.requestFile + this.queryStringSeparator + this.URLString;
					this.xmlhttp.open(this.method, totalurlstring, true);
				} else {
					this.xmlhttp.open(this.method, this.requestFile, true);
					try {
						this.xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded")
					} catch (e) { }
				}

				this.xmlhttp.onreadystatechange = function() {
					switch (self.xmlhttp.readyState) {
						case 1:
							self.onLoading();
							break;
						case 2:
							self.onLoaded();
							break;
						case 3:
							self.onInteractive();
							break;
						case 4:
							self.response = self.xmlhttp.responseText;
							self.responseXML = self.xmlhttp.responseXML;
							self.responseStatus[0] = self.xmlhttp.status;
							self.responseStatus[1] = self.xmlhttp.statusText;
							if (self.execute) {
								
								self.runResponse();
							}

							if (self.elementObj) {
								elemNodeName = self.elementObj.nodeName;
								elemNodeName.toLowerCase();
								if (elemNodeName == "input"
								|| elemNodeName == "select"
								|| elemNodeName == "option"
								|| elemNodeName == "textarea") {
									self.elementObj.value = self.response;
								} else {
									self.elementObj.innerHTML = self.response;
								}
							}
							if (self.responseStatus[0] == "200") {
								self.onCompletion();
							} else {
								self.onError();
							}

							self.URLString = "";
							break;
					}
				};

				this.xmlhttp.send(this.URLString);
			}
		}
	};

	this.reset();
	this.createAJAX();
}
/*
function cart_add( pk ){

 alert('This product has added to your cart.\n\nYou can review your cart at the top of our site\non the right hand side.');
 
 ajax.reset(); 
 ajax.requestFile = "/cart/smallcart.ajax.php";
 ajax.setVar("action", "add");
 ajax.setVar("pk", pk);
 ajax.method = 'POST';
 ajax.encodeURIString = 0;
 ajax.element = 'smallcart';
 ajax.runAJAX();
cart_header_items(pk);
}
*/


function cart_add( pk, SITE_URL ,typeOfShip){
  if(document.getElementById('typeOfOrder').value=='')
  {
    document.getElementById('typeOfOrder').value = typeOfShip;
  }
  else
  {
    if(document.getElementById('typeOfOrder').value!=typeOfShip)
    {
        m_displayMsg(typeOfShip);
        return false;
    }
  }
 //alert('This product has added to your cart.\n\nYou can review your cart at the top of our site\non the right hand side.');
 
    
if(jQuery('#order_details').length) // for cart details page
{

	 cart_box_add(pk);
	 
  
 }else
 {jQuery("#xx").html(window.location.protocol);
	 if(window.location.protocol=='https:'){   //Condition added for the #325
	 jQuery.ajax({
	   type: "POST",
	   url: SITE_PATH+"/core/cart/smallcart.ajax.php",
	   data: "action=add&pk="+pk,
	   success: function(msg){
			
			cart_header_items(pk);
			m_PopUp(SITE_PATH +'/core/cart/checkout/popup.php?id='+pk);
	   }
	 });
       }else{
          jQuery.ajax({
	   type: "POST",
	   url: "/cart/smallcart.ajax.php",
	   data: "action=add&pk="+pk,
	   success: function(msg){
			//jQuery("#smallcart").html(msg);
			cart_header_items(pk);
			m_PopUp(SITE_URL +'/cart/checkout/popup.php?id='+pk);
	   }
	 });
         }
 }

  //Added for tool tip For ticket #350
  jQuery(function() {
    jQuery('.tooltipahref').tooltip({
            track: true,
            delay: 0,
            showURL: false,
            showBody: " - ",
            bodyHandler: function() {
                    return "The item is <b>out of stock</b> and cannot be added to shopping cart.";
            },
            fade: 250
    });
   });
 //End of Added for tool tip For ticket #350

}

/*
Added by Priyabrata Bera on 24th Jan 2011
*/
// will display floating message
function m_floating_message(msg, container)
{			   
	  jQuery('#'+container).show();
	  jQuery('#'+container).css('color', '#25b900');
	  jQuery('#'+container).html(msg);
	  setTimeout("jQuery('#"+container+"').hide();", 2000); //display message for 3 seconds
 
}
// This function will update the quentity in shopping cart
function cart_update( pk ){
	var qty=jQuery('#qty_'+pk).val();
	 jQuery.ajax({
	   type: "POST",
	   url: SITE_PATH+"/core/cart/smallcart.ajax.php",
	   data: "action=update&pk="+pk+'&qty='+qty,
	   success: function(msg){
		   
			//jQuery("#smallcart").html(msg);
			if(qty > 0){
			update_cart_box_details();
			var container='message_'+pk;
			m_floating_message('The quantity has been updated sucessfully.', container);
		  }else{
			  var container='message_'+pk;
		  	  m_floating_message('<font color="red">Please update with a valid number.</font>', container);	
		  }
	   }
	 });
}

function cart_box_remove( pk ){
var are_u_confirm = confirm("Do you really want to remove this product from your shopping cart?");
if(are_u_confirm==true){
 jQuery.ajax({
   type: "POST",
   url: SITE_PATH+"/core/cart/smallcart.ajax.php",
   data: "action=remove&pk="+pk,
   success: function(msg){
		jQuery("#contain_box_"+pk).remove();
		if(jQuery('#contain_box_activation_'+pk).length){ // activation box
			jQuery("#contain_box_activation_"+pk).remove();
		}
		cart_header_items(pk);
		update_cart_box_details();
   }
 });
}
}

function cart_box_add( pk ){
  jQuery.ajax({
	   type: "POST",
	   url: SITE_PATH+"/core/cart/smallcart.ajax.php",
	   data: "action=add&pk="+pk+"&cart_page=1",
	   success: function(html){
			//jQuery("#smallcart").html(msg);
			//cart_header_items(pk);
			jQuery("#contain_box_"+pk).remove();
			jQuery('#order_details').append(html);
			cart_header_items(pk);
			update_cart_box_details();
			m_PopUp('popup.php?id='+pk); //popup invoking
	   }
	 });
	
}

function cart_popup_add( pk ){
  jQuery.ajax({
	   type: "POST",
	   url: SITE_PATH+"/core/cart/smallcart.ajax.php",
	   data: "action=add&pk="+pk+"&popup_page=1",
	   success: function(msg){
			//jQuery("#smallcart").html(msg);
			//cart_header_items(pk);
	
			jQuery('#cart_details').html(msg);
			cart_header_items(pk);
			
	   }
	 });
}



function cart_product_count(pk, container){
jQuery.ajax({
   type: "POST",
   url: SITE_PATH+"/core/cart/smallcart.ajax.php",
   data: "action=add&pk="+pk+"&count=1",
   success: function(msg){
		jQuery("#"+container).val(msg);
	
   }
 });
 
}

function update_cart_box_details(){
 jQuery("#productBoxContent").html('<img src="/assets/images/loadingAnimation.gif" width="220">');
	jQuery.ajax({
   type: "POST",
   url: SITE_PATH+"/core/cart/cart_box.php",
   data: "update_cart_box=count",
   success: function(msg){
		//jQuery("#cart_box_price").html(msg);
        jQuery("#productBoxContent").html(msg);
         //Added for ticket #299 to refresh the payment method.....
             loadPaymentMethod();      
	
   }
 });
}
	



function cart_header_items(pk){
jQuery.ajax({
   type: "POST",
   url: SITE_PATH+"/core/cart/smallcart_header.ajax.php",
   data: "action=add&pk="+pk,
   success: function(msg){
		jQuery("#smallcart_header").html(msg);
	
   }
 });
 
}


function cart_removeitem( pk ){
 jQuery.ajax({
   type: "POST",
   url: SITE_PATH+"/core/cart/smallcart.ajax.php",
   data: "action=remove&pk="+pk,
   success: function(msg){
		jQuery("#smallcart").html(msg);
		cart_header_remove_items(pk);
   }
 });
}

function cart_header_remove_items(pk){
jQuery.ajax({
   type: "POST",
   url: SITE_PATH+"/core/cart/smallcart_header.ajax.php",
   data: "action=remove&pk="+pk,
   success: function(msg){
		jQuery("#smallcart_header").html(msg);
	
   }
 });
 
}


function category_add(SITE_URL){

 category = jQuery('#add_category').value;
 alert(category); 
if(category!='') // for cart details page
{

	 jQuery.ajax({
	   type: "POST",
	   url: "/admin/category_add.php",
	   data: "action=add&pk=1",
	   success: function(msg){
			//jQuery("#smallcart").html(msg);
			//cart_header_items(pk);
			//m_PopUp(SITE_URL +'/cart/checkout/popup.php?id='+pk);
	   }
	 });
	 
  
 }else
 {
	alert('Please enter a category name.');	 
	
 }		 
}


/*
function cart_removeitem( pk ){
 ajax.reset(); 
 ajax.requestFile = "/cart/smallcart.ajax.php";
 ajax.setVar("action", "remove");
 ajax.setVar("pk", pk);       
 ajax.method = 'POST';
 ajax.encodeURIString = 0;
 ajax.element = 'smallcart';
 ajax.runAJAX();
}
*/         
function m_PopUp(URL)
{
	window.scroll(0,0);
  var element = document.getElementById('sitepopup');
  element.scrollIntoView(true);

                jQuery.ajax({
						url: URL,                               
						beforeSend : function(){
										m_ShowLoading();
										}              
						,
						success: function(responseText){						
						// document.getElementById('sitepopup').innerHTML=responseText;
                                                 //  document.getElementById('sitepopup').style.display='inline';
                                                   jQuery('#sitepopup').html(responseText);
                                                //Function called  Add to cart of Out of stock case #350
                                                tooltipCalled();
						}
						,
						complete : function (){
							jQuery('#TB_img').hide();
						}
						}
						);
}
function m_ShowLoading()
{
                jQuery('#sitepopup').show();
                jQuery('#transparentdiv').show();
				jQuery('#sitepopup').html("<img src='/assets/images/loadingAnimation.gif' id='TB_img' align='middle' class='waitImg' />");
}
function m_Close()
{
    jQuery('#sitepopup').hide();
    jQuery('#transparentdiv').hide();
				
}

function m_HideLoading(){
	jQuery('#TB_img').hide();
  
	
}

	/* ---  Added By ashish for the select region spacific products on 2011-03-10 ----*/

	function upd_mult_prod( pk, flgid ){
	 jQuery('#mult-ajax').html("<p class='mult-ajax'><img src='/assets/images/loadingAnimation.gif' id='TB_img'/></p>");
	 jQuery.ajax({
	   type: "POST",
	   url: "/core/buygames/multiple-ajax.php",
	   data: "pk="+pk+"&flg="+flgid,
	   success: function(msg){
			jQuery("#mult-ajax").html(msg);
                        //Function called  Add to cart of Out of stock case #350
                        tooltipCalled();
	   }
	 });
	}
 
//Functionn added for the confirmation box on click of link and button
// By Deepak
// At 08042011
function confirmation(url,msg){
    var answer = confirm(msg)
    if (answer) {
        window.location = url;
    }
}
//End........................

/*Following Code add by Deepak For the Shipping Change On 22/4/2011*/


//Common ajax function //////////////

function m_commonajax(gotourl,divId,status){
    //alert(gotourl+divId+status);
    document.getElementById(divId).innerHTML = "<div class='indexup'><img src='/assets/images/ajax-loader2.gif' />"+status+"...</div>";
    jQuery.ajax({
         url: gotourl,
         cache:false,
         async:true,
         success: function(data) {
               //alert(data);
               //document.getElementById(divId).style.display='none';
               //document.getElementById("sp").innerHTML = "<div></div>";
               jQuery('#'.divId).html(data);
               //alert('Load was performed.');
         }
  });
 }

//Function  to validate the Shipping service providers form ::::: Deepak - 4/16/2011///
function m_validate_Shipping_form(){
    str = trim(document.frmshipping.providername.value);
   if(str==''){
       //jQuery("#providername").addClass('redclass');
       alert('Enter Shipping Provider Name.');
       document.frmshipping.providername.focus();
       //document.getElementById('providernamemsg').style.display = "block";
       return false;
   }
   document.frmshipping.providername.value=str;
   if(document.frmshipping.providerlogo.value=='' && document.frmshipping.id.value==''){
       alert('Enter Shipping Providers Logo.\nIt must be an image file.');
       //jQuery("#providerlogo").addClass('redclass');
       //document.frmshipping.providerlogo.focus();
       //document.getElementById('providerlogomsg').style.display = "block";
       return false;
   }
   if(document.frmshipping.trackinglink.value!=''){
      return check_it(document.frmshipping.trackinglink.value);
   }
   return true;
}

 function check_it(theurl) {
     var theurl=theurl;
     var tomatch= /http:\/\/[A-Za-z0-9\.-]{3,}\.[A-Za-z]{3}/
     if (tomatch.test(theurl))
     {
         //window.alert("URL OK.");
         return true;
     }
     else
     {
         alert("Invalid Service Provider's Tracking Link.Please enter valid one.");
         return false;
     }

 }


function trim(inputString) {
   // Removes leading and trailing spaces from the passed string. Also removes
   // consecutive spaces and replaces it with one space. If something besides
   // a string is passed in (null, custom object, etc.) then return the input.
   if (typeof inputString != "string") { return inputString; }
   var retValue = inputString;
   var ch = retValue.substring(0, 1);
   while (ch == " ") { // Check for spaces at the beginning of the string
      retValue = retValue.substring(1, retValue.length);
      ch = retValue.substring(0, 1);
   }
   ch = retValue.substring(retValue.length-1, retValue.length);
   while (ch == " ") { // Check for spaces at the end of the string
      retValue = retValue.substring(0, retValue.length-1);
      ch = retValue.substring(retValue.length-1, retValue.length);
   }
   while (retValue.indexOf("  ") != -1) { // Note that there are two spaces in the string - look for multiple spaces within the string
      retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length); // Again, there are two spaces in each of the strings
   }
   //alert(retValue);
   return retValue; // Return the trimmed string back to the user
} // Ends the "trim" function


function showred(obj)
{   obj.value = trim(obj.value);
    if(obj.value==''){
       //jQuery("#"+obj.id).addClass('redclass');
       //document.getElementById(obj.id).focus();
       //return false;
    }else{
        //jQuery("#"+obj.id).removeClass('redclass');
    }
}


function checkPhoto(picField) {
 var picFile = picField;
 var imagePath = document.frmshipping.providerlogo.value;
 var pathLength = imagePath.length;
 var lastDot = imagePath.lastIndexOf(".");
 var fileType = imagePath.substring(lastDot,pathLength);
 alert(fileType);
 if((fileType == ".gif") || (fileType == ".jpg") || (fileType == ".png") || (fileType == ".GIF") || (fileType == ".JPG") || (fileType == ".PNG")) {
  return true;
 } else {

  document.frmshipping.providerlogo.value = '';
  document.getElementById('providerlogomsg').innerHTML ="Must be .JPG, .PNG, and .GIF image formats. Your file-type is " + fileType + ".";
 }
}


var message_box = function() {
	var button = "<div class='btnsbox fontmyriad'><p class='cls'></p><ul><li class='addcartlinkB'  style='width:45px'><a href='javascript:void(0)' style='width:45px' onclick='message_box.close_message();'><span class='fontB fontFTMS'>Close</span></a></li></ul></div>"

	return {
		show_message: function(title, body) {
                       window.scrollTo(0, 0);
			if(jQuery('#message_box').html() === null) {
				var message = '<div id="message_box"><br/><br/>' + body + '<br/><br/>' + button + '</div>';
				jQuery(document.body).append( message );
				jQuery(document.body).append( '<div id="darkbg"></div>' );
				jQuery('#darkbg').show();
                                jQuery('#darkbg').css('height', jQuery(document).height());
				jQuery('#message_box').css('top', jQuery('html, body').scrollTop() + 150);
				jQuery('#message_box').show('slow');
			} else {
				var message = '<br/><br/>' + body + '<br/><br/>' + button;
				jQuery('#darkbg').show();
                                jQuery('#darkbg').css('height', jQuery(document).height());
				jQuery('#message_box').css('top', jQuery('html, body').scrollTop() + 150);
				jQuery('#message_box').show('slow');
				jQuery('#message_box').html( message );
			}
		},
		close_message: function() {
			jQuery('#message_box').hide('fast');
			jQuery('#darkbg').hide();
		}
	}
}();


function m_displayMsg(t){
   if(t==0)
     message_box.show_message('', '<b>You can add to cart only shipping products. If you want to add digital delivery product, You should first complete current order or remove any shipping products from the cart.</b>');
    else
     message_box.show_message('', '<b>You can add to cart only Digital Delivery Products. If you want to add shipping product, You should first complete current order or remove Digital Delivery Products from the cart.</b>');
}





var shipping_box = function() {
	var button = '<!--<input type="button" onclick="shipping_box.close_shipping();" value="Close" />-->';
	return {
		show_shipping: function(title) {
                    jQuery('#shippingload1').hide();
                      innerW= jQuery(document).width();
                      innerH=jQuery(document).height();
                        innerW = (innerW-400)/2
                         innerH = (innerH-400)/2
                       window.scrollTo(0, 0);
                       jQuery('#lightBox').css('width', jQuery(document).width());
                        jQuery('#lightBox').css('height', jQuery(document).height());
                        jQuery('#lightBox').show();


                       jQuery("#one").css('left',innerW);
                         jQuery("#one").css('top',200);
                        jQuery('#one').show();

                        //alert(innerW);


                     //  $JQuery("#lightBox").offset({ top: offset.top, left:  offset.left+20 });


		},
		close_shipping: function() {
			 jQuery('#closeme').hide('fast');
			jQuery('#closeme').hide();
                        jQuery('#lightBox').hide();
		}
	}
}();


function showHideshippingField(thischecked){
    //alert(document.getElementById('billingshipping14').style.display);
    //if(document.getElementById('billingshipping14').style.display=='none')
    //document.getElementById('billingshipping14').style.display = "block";
    //else
    //document.getElementById('billingshipping14').style.display = "none";
    //alert(thischecked);
    if(thischecked==true){
                                     document.getElementById('old').style.display='block';
                                     document.getElementById('new').style.display='none';
                                     }else{
                                     document.getElementById('old').style.display='none';
                                     document.getElementById('new').style.display='block';
                                     }

}


function saveShipping(){

       //var tvar = jQuery('#shipping2').serialize();
       //alert(tvar);
       //alert(document.getElementById('ship').checked);
       //if(document.getElementById('ship').checked!=true){

       var t = 'true';
       if(document.shipping2.fname.value=='')
         {
           jQuery('#fname').addClass('highlight');
           t= 'false';
         }else{
              jQuery('#fname').removeClass('highlight');
         }
         if(document.shipping2.lname.value=='')
         {
             jQuery('#lname').addClass('highlight');
           t= 'false';
         }else{
              jQuery('#lname').removeClass('highlight');
         }
         if(document.shipping2.address1.value=='')
         {
              jQuery('#address1').addClass('highlight');
           t= 'false';
         }else{
              jQuery('#address1').removeClass('highlight');
         }

         if(document.shipping2.city.value=='')
         {
             jQuery('#city').addClass('highlight');
             t= 'false';
         }else{
              jQuery('#city').removeClass('highlight');
         }

         if(document.shipping2.postalcode.value=='')
         {
              jQuery('#postalcode').addClass('highlight');
              t= 'false';
         }else{
              jQuery('#postalcode').removeClass('highlight');
         }

         if(document.shipping2.shippingstate.value=='')
         {
             jQuery('#shippingstate').addClass('highlight');
           t= 'false';
         }else{
              jQuery('#shippingstate').removeClass('highlight');
         }

         if(document.shipping2.shippingstate.value=='oth' && document.shipping2.otherregion.value=='' ){
               jQuery('#otherregion').addClass('highlight');
               t= 'false';
         }else{
              jQuery('#otherregion').removeClass('highlight');
         }


         if(document.shipping2.country.value=='')
         {
           jQuery('#country').addClass('highlight');
           t= 'false';
         }else{
              jQuery('#country').removeClass('highlight');
         }

        if(t=='false'){

            document.getElementById('shippingload1').innerHTML="<div class='errMessage errors'>Highlight fields are required field(s).Fill the highlight field (s).</div> ";
            document.getElementById('shippingload1').style.display = 'block';
           return false;
        }
      // }
       document.getElementById('shippingload1').style.display = 'block';
     document.getElementById('shippingload1').innerHTML = "<div class='indexup'><img src='/assets/images/ajax-loader2.gif' />Loding...</div>";

     var tvar = jQuery('#shipping2').serialize();
     //alert(tvar);
     jQuery.ajax({
        type: "POST",
        url:  SITE_PATH+"/core/cart/checkout/shipping.php",
        cache: false,
        data: tvar,
        success: function (response) {
             //alert(response);
             update_cart_box_details();
              innerW= jQuery(document).width();
                      innerH=jQuery(document).height();
                        innerW = (innerW-400)/2
                         innerH = (innerH-400)/2

                       document.getElementById('shippingload1').style.display = 'none';

                       jQuery("#one").css('left',innerW);
                         jQuery("#one").css('top',200);
                        jQuery('#one').hide();
                          jQuery("#closeme").css('left',innerW);
                         jQuery("#closeme").css('top',200);
                jQuery('#closeme').show();
             //var button = '<input type="button" onclick="shipping_box.close_shipping();" value="Close" />';
            // var button ="<br/><div class='btnsbox fontmyriad' style='margin-left:127px'><p class='cls'></p><ul><li class='addcartlinkB'><a href='javascript:void(0)' style='width:45px' onclick='shipping_box.close_shipping()'><span class='fontB fontFTMS'>Close</span></a></li></ul>  </div>";
            //document.getElementById('shippingloadmsg').innerHTML ="<div id='shippingload'>Your Shipping details has been saved.<A href='javascript:void(0)' onclick=\"shipping_box.show_shipping('Shipping Details',test)\">Edit</a></div>"+button;

        }
    });
}

//**End Of Addition**/



//Added for coupon Module Ticket#254 by Deepak on 15/6/2011
  function redeemBox(couponCode,couponError,couponBox,total){ checkcart();
     jQuery.ajax({
         url: SITE_PATH+'/core/cart/checkout/redeem_coupon.php?couponCode='+couponCode+'&total='+total,
         cache:false,
         async:true,
         success: function(responce) {
             if(responce==0){
               document.getElementById(couponError).innerHTML = 'Invalid Coupon code.';
             }else if(responce==2){
               document.getElementById(couponError).innerHTML = 'Coupon Code already redeemed.';
             }else if(responce==1){
               document.getElementById(couponError).innerHTML = '';
               document.getElementById(couponBox).style.display = 'none';
               update_cart_box_details();
               loadPaymentMethod();     //Updated for ticket #299
             }
         }
     });
  }

 function ajaxFormSubmit(formid,urltoaction,divtoresponce,proccessmsg){
    document.getElementById(divtoresponce).innerHTML ="<img src='/assets/images/ajax-loader2.gif' />"+proccessmsg+"..."
    var dataString = jQuery("#"+formid).serialize();
    //alert (dataString);return false;
    jQuery.ajax({
      type: "POST",
      url: urltoaction,
      data: dataString,
      success: function(responce) {
          document.getElementById(divtoresponce).innerHTML=responce;
      }
   });
   return false;
 }

function ajaxFormAddEditSubmit(formid,urltoaction,divtoresponce,proccessmsg,limit,page,spage){
   document.getElementById(divtoresponce).innerHTML ="<img src='/assets/images/ajax-loader2.gif' />"+proccessmsg+"..."
    var dataString = jQuery("#"+formid).serialize();
    //alert (dataString);return false;
    jQuery.ajax({
      type: "POST",
      url: urltoaction,
      data: dataString,
      success: function(responce) {
          document.getElementById(divtoresponce).innerHTML=responce;
          ajaxCallGeneric('CouponList','/admin/couponlist.php','Please wait','CouponList','');
      }
   });
   return false;
}

 function ajaxCallGeneric(divId,urlset,msg,responceto){
    document.getElementById(divId).style.display  = 'block';
    document.getElementById(divId).innerHTML      = "<img src='/assets/images/ajax-loader2.gif' />"+msg+"...";
    jQuery.ajax({
         url: urlset,
         cache:false,
         async:true,
         success: function(responce) {
           document.getElementById(responceto).innerHTML = responce;
           if(divId=='ADDEDIT'){
               chooseProducts();
           }
         }
     });
 }

function addclasstoobj(id,className){
    jQuery("#"+id).addClass( className )
}

function removeclasstoobj(id,className){
    jQuery("#"+id).removeClass( className )
}

function autoSetValue(setUrl,objId){
   jQuery.ajax({
         url: setUrl,
         cache:false,
         async:true,
         success: function(responce) {
           document.getElementById(objId).value = responce;
         }
     });
}


function checkValueofField(setUrl,responceto,makeDisable){
     jQuery.ajax({
         url: setUrl,
         cache:false,
         async:true,
         success: function(responce){
           if(responce>0){
             document.getElementById(responceto).style.display = '';
             document.getElementById(makeDisable).disabled = true;
           }else{
             document.getElementById(makeDisable).disabled = false;
             document.getElementById(responceto).style.display = 'none';
           }
         }
     });
}

function selectMultipleSelect(urlt,sid,here){
     document.getElementById(here).innerHTML      = "<img src='/assets/images/ajax-loader2.gif' />Please Wait...";
     var t='';
     jQuery.ajax({
                 url:urlt,
                 type:'POST',
                 cache:false,
                 async:true,
                 data:{
                       Games:jQuery('#'+sid).val().join(",")
                 },
                 success:function(data){
                      document.getElementById(here).innerHTML = data;
                 }
         });
}

function hideMsg(){
          if(document.getElementById('responce'))
           document.getElementById('responce').innerHTML = '';
          if(document.getElementById('msglist'))
           document.getElementById('msglist').innerHTML  = '';
       }
//End of Ticket#254




/*Function for ticket #299 Streamline checkout Start*/
/**************************************************************************
	Purpose			: Open login popup
	Added By                : Deepak Kumar
	Added On                : 2011-07-11
***************************************************************************/
    function m_loginPopUP(){
       log = 0;

       if(readCookie('pcgame_email') && readCookie('pcgame_password')){
        window.location = '/myaccount/';
       }else{
        innerW  = jQuery(document).width();
        innerH  = jQuery(document).height();
        innerW  = (innerW-400)/2
        innerH  = (innerH-400)/2
        window.scrollTo(0, 0);
        jQuery('#Loginbg').css('width', jQuery(document).width());
        jQuery('#Loginbg').css('height', jQuery(document).height());
        jQuery('#Loginbg').show();
        jQuery("#LoginBox").css('top',200);
        jQuery('#LoginBox').show();
        t = cookiestest();
       }
    }
 /**************************************************************************
	Purpose			: Submit Login form
	Added By                : Deepak Kumar
	Added On                : 2011-07-11
 ***************************************************************************/
    function m_submitLogin(){
       var tvar = jQuery('#loginForm').serialize();
       jQuery.ajax({
         url: SITE_PATH+'/core/myaccount/ajaxlogin.php',
         data:tvar,
         type: "POST",
         cache:false,
         async:true,
         success: function(responce){
             if(responce==1){
              /* if(document.getElementById('rememberme1') && document.getElementById('rememberme1').checked==true){
                createCookie('pcgame_email',document.getElementById('idEmail').value,365);
                createCookie('pcgame_password',document.getElementById('idPassword').value,365)
               }else{
                eraseCookie('pcgame_email');
                eraseCookie('pcgame_password')
               }*/
                 window.location = '/myaccount/';
               
                return 1;
             }else{
                document.getElementById('loginErroeBox').style.display = '';
                document.getElementById('loginErroeBox').innerHTML     = responce;
             }
         }
     });
     return false;
    }

    function loadUserAccount(){
        window.location = '/myaccount/';
        /*jQuery.ajax({
         url: '/myaccount/useraccount.php',
         cache:false,
         async:true,
         success: function(responce){
             jQuery('#Loginbg').hide();
             jQuery('#LoginBox').hide();
             //document.getElementById('middelArea').innerHTML = responce;
             window.location = '/';
           }
       });*/
    }


    function closeLogin(){
       jQuery('#Loginbg').hide();
       jQuery('#LoginBox').hide();
    }


   function m_validateConnectform(){
       if(!fnc_ValidateEmail(email)){

       }
   }


   function m_submitConnect(){   
      if(document.getElementById('phone').value=='' || !fnc_IsValidMobile(document.getElementById('phone').value)){
          document.getElementById('loginErroeBox1').style.display = '';
          document.getElementById('loginErroeBox1').innerHTML     = 'Enter your Phone Number.';          
          return false;
      }

      if(document.getElementById('concountry').value==''){
          document.getElementById('loginErroeBox1').style.display = '';
          document.getElementById('loginErroeBox1').innerHTML     = 'Choose your country.';
          return false;
      }
      
       var tvar = jQuery('#connectForm').serialize();
       jQuery.ajax({
         url: SITE_PATH+'/core/myaccount/facebook_connect.php',
         data:tvar,
         cache:false,
         async:true,
         success: function(responce){
             if(responce==1){
                loadUserAccount();
             }else if(responce==2){
                window.location="/cart/checkout/index.php";
             }else{
                document.getElementById('loginErroeBox1').style.display = '';
                document.getElementById('loginErroeBox1').innerHTML     = responce;
             }
         }
     });
     return false;
   }





function showlogin(){
     t=  cookiestest();
     document.getElementById('registerErroeBox1').style.display = 'none';
     jQuery('#loginsecform').show();
     jQuery('#loginsec').hide();
}

function hidelogin(){
     jQuery('#loginsecform').hide();
     jQuery('#loginsec').show();
}


function checkoutLogin(){

}
    /*
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    Name        :    popUpWindow
    Purpose     :    This function pops up a new window.
    Usage       :    popUpWindow( "somepath/somefile.php", 500, 250, "_myWindow" );
    Arguments   :
        url       	-    String. The url that will open in the poped up window.
        width     	-    integer. width of the window.
        height    	-    integer. height of the window.
        [windName]	-    String. Pass this argument only if a fresh window is to be
                    poped up. This argument    should not contain any spaces.
    Return      :    void.
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*/

function fnc_PopUpWindow(url,width,height,windName)
{

    wind = window.open(url, (windName?windName:"_sameWindow"), "width="+width+",height="+height+",scrollbars=yes");
	//alert(url);
    x = (screen.availWidth/2)  - (width/2);
    y = (screen.availHeight/2) - (height/2);
    wind.moveTo(x, y);
    wind.resizeTo( width, (height+23) );
    wind.focus();
}

function fullViewBG(){
        innerW  = jQuery(document).width();
        innerH  = jQuery(document).height();
        innerW  = (innerW-400)/2
        innerH  = (innerH-400)/2
        window.scrollTo(0, 0);
        jQuery('#Loginbg').css('width', jQuery(document).width());
        jQuery('#Loginbg').css('height', jQuery(document).height());

}


function fnc_ValidateEmail(email)
{
    invalidChars = " /:,;'\"!#&*()"
    if(email == "")
    {                 //email cannot be empty
        return false;
    }

    for(i=0; i<invalidChars.length; i++)
    { //check for invalid characters
        badChar = invalidChars.charAt(i);
        if(email.indexOf(badChar,0) != -1)
        {
            return false;
        }
    }

    atPos = email.indexOf("@",1);         //there must be one "@" symbol
    if(atPos == -1)
    {
        return false;
    }
    if(email.indexOf("@",atPos+1) != -1)
    { //check to make sure only one "@" symbol
        return false;
    }

    periodPos = email.indexOf(".",atPos);
    if (periodPos == -1)
    { // make sure there is one "." after the "@"
        return false;
    }

    if(periodPos+3 > email.length)
    { // must be at least 2 chars after the "."
        return false;
    }
    return true;
}

function submitStreamLineRegister(){
    if(document.getElementById('streamfname').value==''){
        document.getElementById('registerErroeBox1').style.display='block';
        document.getElementById('registerErroeBox1').innerHTML = 'Enter your First Name.';
        return false;
    }else if(document.getElementById('streamlname').value==''){             //Condition added on 17-8-2011 for last name related update
        document.getElementById('registerErroeBox1').style.display='block';
        document.getElementById('registerErroeBox1').innerHTML = 'Enter your Last Name.';
        return false;
    }else if(document.getElementById('streamemail').value=='' || !fnc_ValidateEmail(document.getElementById('streamemail').value)){
        document.getElementById('registerErroeBox1').style.display='block';
        document.getElementById('registerErroeBox1').innerHTML = 'Enter your valid Email Address.';
        return false;
    }else if(document.getElementById('streamcountry').value=='' ){
        document.getElementById('registerErroeBox1').style.display='block';
        document.getElementById('registerErroeBox1').innerHTML = 'Please choose a Country.';
        return false;
    }else if(document.getElementById('streampass').value==''){
        document.getElementById('registerErroeBox1').style.display='block';
        document.getElementById('registerErroeBox1').innerHTML = 'Enter valid Password.';
        return false;
    }else if(document.getElementById('streampass1').value==''){
        document.getElementById('registerErroeBox1').style.display='block';
        document.getElementById('registerErroeBox1').innerHTML = 'Enter valid Password(Confirm).';
        return false;
    }else if(document.getElementById('streampass1').value!=document.getElementById('streampass').value){
        document.getElementById('registerErroeBox1').style.display='block';
        document.getElementById('registerErroeBox1').innerHTML = 'Enter same Password(Confirm) as Password.';
        return false;
    }else if(document.getElementById('phone').value=='' || !fnc_IsValidMobile(document.getElementById('phone').value)){
        document.getElementById('registerErroeBox1').style.display='block';
        document.getElementById('registerErroeBox1').innerHTML = 'Enter valid Phone Number.';
        return false;
    }else{
        document.getElementById('loginErroeBox1').style.display='none';
        var tvar = jQuery('#testId').serialize();
        //alert(tvar);
        jQuery.ajax({
          url: SITE_PATH+'/core/myaccount/register_action.php',
          data:tvar,
          type: "POST",
          cache:false,
          async:true,
          success: function(responce){
             if(responce==1){
               if(document.getElementById('couponBox')){
                document.getElementById('couponBox').style.display='block';
               }               
               update_cart_box_details();
               loadPaymentMethod();
             }else{
                document.getElementById('registerErroeBox1').style.display = '';
                document.getElementById('registerErroeBox1').innerHTML     = responce;
             }
         }
     });
     return false;
    }
    return false;
}


function streamlineLogin(){   checkcart();
    //salert(readCookie('pcgame_email'));
    //alert(document.getElementById('rememberme').checked)
    if(document.getElementById('slemail').value=='' || !fnc_ValidateEmail(document.getElementById('slemail').value)){

        document.getElementById('loginErroeBox1').style.display='block';
        document.getElementById('loginErroeBox1').innerHTML = 'Enter a valid Email Address.';
        return false;
    }else if(document.getElementById('slpassword').value==''){
        document.getElementById('loginErroeBox1').style.display='block';
        document.getElementById('loginErroeBox1').innerHTML = 'Enter a valid Password.';
        return false;
    }else{
        document.getElementById('loginErroeBox1').style.display='none';
        var tvar = jQuery('#frmslLogin').serialize();

       jQuery.ajax({
         url: SITE_PATH+'/core/myaccount/ajaxlogin.php',
         data:tvar,
         type: "POST",
         cache:false,
         async:true,
         success: function(responce){
             //alert(responce)
             if(responce==1){
               // alert(document.getElementById('rememberme').checked)
               /*if(document.getElementById('rememberme').checked==true){
                 createCookie('pcgame_email',document.getElementById('slemail').value,365);
                 createCookie('pcgame_password',document.getElementById('slpassword').value,365)
               }else{
                eraseCookie('pcgame_email');
                eraseCookie('pcgame_password')
               }*/
               if(document.getElementById('couponBox')){
                document.getElementById('couponBox').style.display='block';
               }
               update_cart_box_details();
               loadPaymentMethod();
             }else{
                document.getElementById('loginErroeBox1').style.display = '';
                document.getElementById('loginErroeBox1').innerHTML     = responce;
             }
         }
     });
     return false;
    }
}

function loadPaymentMethod(){ checkcart();
   changeLink();
   jQuery("#pay_detailed").html('<img src="/assets/images/loadingAnimation.gif" width="220">');
   jQuery.ajax({
         url: SITE_PATH+'/core/cart/checkout/streamline_payment.php?w=ajax',
         cache:false,
         async:true,
         success: function(responce){
              if(responce==1){
                 window.location= SITE_PATH+'/cart/checkout/thanks.php';
               }else{
              document.getElementById('pay_detailed').innerHTML=responce;
              }
         }
   });
}



function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";

}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

function cookiestest(){
    createCookie('pcgame_test','test',365);
    if(readCookie('pcgame_test')==null || readCookie('pcgame_test')==''){
      if(document.getElementById('rememberme')){
         document.getElementById('rememberme').checked = false;
      }
      if(document.getElementById('rememberme1')){
         document.getElementById('rememberme1').checked = false;
      }
      return false;
    }else{
      return true;
    }
}

function logout()
{
    eraseCookie('pcgame_email');
    eraseCookie('pcgame_password');
    window.location='/myaccount/logout.php';
}

function submitCreaditCardPayment(){ checkcart();
       var tvar = jQuery('#frmCreaditCard').serialize();
       //document.getElementById('pay_detailed').innerHTML ="";
       jQuery("#pay_detailed").html('<img src="/assets/images/loadingAnimation.gif" width="220">');
       jQuery.ajax({
         url: SITE_PATH+'/core/cart/checkout/streamline_payment.php?submit=1&w=ajax',
         data:tvar,
         type: "POST",
         cache:false,
         async:true,
         success: function(responce){
             
               if(responce==1){
                 window.location=SITE_PATH+'/cart/checkout/thanks.php';
               }else{
                 document.getElementById('pay_detailed').innerHTML = responce;
                 window.location.href = "#pay_detailed";
               }
         }
     });
     return false;
}

function changeLink(){
    if(document.getElementById('noLogin') && document.getElementById('yesLogin')){
        document.getElementById('yesLogin').style.display='block';
        document.getElementById('noLogin').style.display='none';
    }
}

function m_GetCountryPhoneCode(countryCode){
		var arrCountry = {"US":"+1", "CA":"+1","AF":"+93","AL":"+355","DZ":"+213","AS":"+1","AD":"+376","AO":"+244","AI":"+1","AQ":"+672","AG":"+1","AR":"+54","AM":"+374","AW":"+297","AU":"+61","AT":"+43","AZ":"+994","BS":"+1","BH":"+973","BD":"+880","BB":"+1","BY":"+375","BE":"+32","BZ":"+501","BJ":"+229","BM":"+1","BT":"+975","BO":"+591","BA":"+387","BW":"+267","BV":"+00","BR":"+55","IO":"+246","BN":"+673","BG":"+359","BF":"+226","BI":"+257","KH":"+855","CM":"+237","CV":"+238","KY":"+1","CF":"+236","TD":"+235","CL":"+56","CN":"+86","CX":"+61", "CC":"+61","CO":"+57", "KM":"+269", "CG":"+242","CD":"+243","CK":"+682","CR":"+506","CI":"+225","HR":"+385","CU":"+53","CY":"+357", "CZ":"+420","DK":"+45","DJ":"+253","DM":"+1","DO":"+1","TP":"+00","EC":"+593","EG":"+20","SV":"+503","GQ":"+240","ER":"+291","EE":"+372","ET":"+251","FK":"+500","FO":"+298","FJ":"+679","FI":"+358","FR":"+33","GF":"+594","PF":"+689","TF":"+262", "GA":"+241","GM":"+220","GE":"+995","DE":"+49","GH":"+233","GI":"+350","GR":"+30", "GL":"+299","GD":"+1","GP":"+590","GU":"+1","GT":"+502","GN":"+224","GW":"+245","GY":"+592","HT":"+509","HM":"+00","VA":"+39", "HN":"+504","HK":"+852","HU":"+36","IS":"+354","IN":"+91","ID":"+62", "IR":"+98","IQ":"+964","IE":"+353","IL":"+972","IT":"+39","JM":"+1", "JP":"+81","JO":"+962","KZ":"+7","KE":"+254","KI":"+686","KP":"+850","KR":"+82","KW":"+965","KG":"+996","LA":"+856","LV":"+371","LB":"+961","LS":"+266","LR":"+231","LY":"+218","LI":"+423","LT":"+370","LU":"+352","MO":"+853","MK":"+389","MG":"+261","MW":"+265","MY":"+60","MV":"+960","ML":"+223","MT":"+356","MH":"+692","MQ":"+596","MR":"+222","MU":"+230","YT":"+269","MX":"+52", "FM":"+691","MD":"+373","MC":"+377","MN":"+976","MS":"+1","MA":"+212","MZ":"+258","MM":"+95","NA":"+264","NR":"+674","NP":"+977","NL":"+31",  "AN":"+599","NC":"+687","NZ":"+64", "NI":"+505","NE":"+227","NG":"+234","NU":"+683", "NF":"+672","MP":"+1","NO":"+47", "OM":"+968","PK":"+92","PW":"+680","PS":"+970","PA":"+507","PG":"+675","PY":"+595","PE":"+51", "PH":"+63","PN":"+872","PL":"+48","PT":"+351","PR":"+1","QA":"+974","RE":"+262", "RO":"+40", "RU":"+7","RW":"+250","SH":"+290","KN":"+1","LC":"+1","PM":"+508","VC":"+1","WS":"+685","SM":"+378","ST":"+239","SA":"+966","SN":"+221","SC":"+248","SL":"+232","SG":"+65","SK":"+421","SI":"+386","SB":"+677","SO":"+252","ZA":"+27","GS":"+00","ES":"+34","LK":"+94", "SD":"+249","SR":"+597","SJ":"+47", "SZ":"+268", "SE":"+46","CH":"+41","SY":"+963","TW":"+886","TJ":"+992","TZ":"+255","TH":"+66", "TG":"+228","TK":"+690","TO":"+676","TT":"+1", "TN":"+216","TR":"+90","TM":"+993","TC":"+1","TV":"+688", "UG":"+256","UA":"+380", "AE":"+971","GB":"+44", "UM":"+699","UY":"+598","UZ":"+998","VU":"+678","VE":"+58", "VN":"+84","VG":"+1","VI":"+1","WF":"+681","EH":"+212","YE":"+967","YU":"+00","ZM":"+260","ZW":"+263"};
			 // logged for the undefined country -------
			 if(arrCountry[countryCode] == undefined){
			 	arrCountry[countryCode] = "+0";
			 }
			 document.getElementById('country_code').value = arrCountry[countryCode];
}


function fnc_IsValidMobile(aValue)
{
	var i=0;
	var temp="";
	var test="";

	for (i=0; i < aValue.length; i++)
	{
		temp = aValue.substring(i, i+1);
		if (((temp < "0" || temp > "9") && temp != ' ' && temp != '-'))
		    test ="no";
	}
	if (test != "" )
		return false;
	else
		return true;
}
/*End of the ticket#299*/


/*Start for ticket 325*/
function loginCheckOnThanks(urlToSend){
    jQuery.ajax({
         url: SITE_PATH+'/core/checklogin.php?url='+urlToSend,
         cache:false,
         async:true,
         success: function(responce){
               if(responce==1){
                 window.location = SITE_PATH+urlToSend;
               }else{
                   m_loginPopUP()
               }
         }
     });
     return false;
}
/*End for ticket 325*/



function checkcart(){
   jQuery.ajax({
         url: SITE_PATH+'/core/checkcart.php',
         cache:false,
         async:true,
         success: function(responce){
               if(responce==1){
                 document.getElementById('viewItem').style.display = 'none';
                 window.location = '/cart/checkout/';
               }
         }
     });
}


//For #332
function listingByScroll(sortby,pageno,spage,iCategory,str){
        jQuery.ajax({
         url: '/core/newajax-product.php?sortby='+sortby+'&pageno='+pageno+'&spage='+spage+'&iCategory='+iCategory,
         cache:false,
         success: function(response){
             document.getElementById('ProductList').innerHTML  = '';
             if(str=='undefined')
                str = '';
                document.getElementById('ProductList').innerHTML  = str+response;
                if(Number(document.getElementById('iStartFrom').value)!=Number(document.getElementById('npageno').value)+1){
                  document.getElementById('iStartFrom').value = Number(document.getElementById('iStartFrom').value)+1;
                }
                document.getElementById('inprogerss').value = 0;
         }
     });
}


function listingSortBy(sortby,lpageno){
    //document.getElementById('ProductList').innerHTML  = "<div class='scrollLoader'><img alt='Page Loading .. ' title='Page Loading ..' src='/assets/images/loadingAnimation.gif' alt='Please wait..' title='Please wait..'></div>";
    document.getElementById('inproccess').innerHTML  = "<img alt='Page Loading .. ' title='Page Loading ..' src='/assets/images/facebook-loader.gif' alt='Please wait..' title='Please wait..'>";
    document.getElementById('inprogerss').value = 1;
    jQuery.ajax({
         url: '/core/newajax-product.php?sortby='+sortby+'&lpageno='+lpageno+'&iCategory='+document.getElementById('iCategory').value+"&pageno="+document.getElementById('iStartFrom').value,
         cache:false,
         success: function(response){
             str = response;
             document.getElementById('ProductList').innerHTML  = '';
             document.getElementById('ProductList').innerHTML  = str;
             document.getElementById('inprogerss').value = 0;
             document.getElementById('inproccess').innerHTML  = '';
         }
     });
}


function zoomOut(ths){
     jQuery(ths).css({'background-color' : '#eeeeee'})
        if(tempStatus==1)
        {
          jQuery(ths).find('.zoomSec').css({'display':'block'});
          jQuery(ths).find('.zoomSect').css({'display':'block'});
        }

         //Added for tool tip For ticket #350
  jQuery(function() {
    jQuery('.tooltipahref').tooltip({
            track: true,
            delay: 0,
            showURL: false,
            showBody: " - ",
            bodyHandler: function() {
                    return "The item is <b>out of stock</b> and cannot be added to shopping cart.";
            },
            fade: 250
    });
   });
 //End of Added for tool tip For ticket #350

}


function zoomIn(ths){
    jQuery(ths).css({'background-color' : '#FFFFFF'})
    jQuery(ths).find('.zoomSec').css({'display':'none'});
    jQuery(ths).find('.zoomSect').css({'display':'none'});
}

//mouse out
function zoomInImage(ths){
    tempStatus=1;
        jQuery("#"+ths).css({'z-index' : '1'});
        jQuery("#div"+ths).css({'z-index' : '1'});
	jQuery("#"+ths).removeClass("hover").stop()
		.animate({
			marginTop: '0',
			marginLeft: '0',
			top: '0',
			left: '0',
			width: '65px',
			height: '92px',
			padding: '0'
		}, 200);
        jQuery("#div"+ths).find('.zoomSec2').css({'display':'none'});
        jQuery("#div"+ths).find('.zoomSec').css({'display':'block'});
        jQuery("#div"+ths).find('.zoomSect').css({'display':'block'});
         document.getElementById(ths).style.border='1px solid silver';

}

//click on zoom
function zoomOutImage(ths){
        tempStatus=0;
        jQuery("#"+ths).css({'z-index' : '1000'});
        jQuery("#div"+ths).css({'z-index' : '1000'});
        jQuery("#"+ths).addClass("hover").stop(),
		jQuery("#"+ths).animate({
			marginTop: '-157px',
			marginLeft: '-135px',
			top: '50%',
			left: '50%',
                        width: '136px',
			height: (jQuery("#"+ths).height() / jQuery("#"+ths).width() * 136) + 'px',
			padding: '3px'

		}, 200);

       jQuery("#div"+ths).find('.zoomSec2').css({'display':'none'});
       jQuery("#div"+ths).find('.zoomSec').css({'display':'none'});
       jQuery("#div"+ths).find('.zoomSect').css({'display':'none'});
       document.getElementById(ths).style.border='3px solid silver';
}


//start 327
function loadCode(varl){
       document.getElementById('responce').innerHTML = '';
       document.getElementById('busy').style.display = 'block';
       //document.getElementById('busy').innerHTML = '';
       jQuery.ajax({
         url: '/admin/setcode.php?url='+varl,
         cache:false,
         async:true,
         success: function(responce){
             document.getElementById('code').value         = responce;
             document.getElementById('busy').style.display = 'none';
             //document.getElementById('busy').innerHTML     = '';
         }
     });
     return false;
}

function submitCode(){
    if(document.getElementById('urllist').value=='0'){
       //responce
       alert('Please select URL/Game/Category.');
       //document.getElementById('responce').innerHTML = 'Please select URL/Game.';
       return false;
    }

    document.getElementById('busy').style.display = 'block';
    jQuery.post("/admin/addcode.php", jQuery("#frmCode").serialize(),
    function(data) {
        document.getElementById('responce').innerHTML = '<label class="success">Code has been saved.</label>';
        document.getElementById('busy').style.display = 'none';
        document.frmCode.reset();
      }
    );
     return false;
}
//End 327




/*Changwe password for #388*/
function submitChangePassword(){
    document.getElementById('passwordError').style.display = 'block';
    if(!validateChangePassword()){
        return false;
    }else{
        var tvar = jQuery('#changepassword').serialize();
        jQuery("#passwordError").css("background","#ffffff");
        jQuery("#passwordError").css("border","0");
        jQuery("#passwordError").html('<span>Please wait...</span><img src="/assets/images/ajax-loader2.gif">');
        jQuery.ajax({
            url: '/core/myaccount/changepassword_action.php',
            data:tvar,
            type: "POST",
            cache:false,
            async:true,
            success: function(responce){
                if(responce=='SUCCESS'){
                    jQuery("#passwordError").html('<span>Your password has been changed.</span>');
                    document.changepassword.reset();
                }else if(responce!='SUCCESS'){
                    changepasswordAddErrorCSS();
                    jQuery("#passwordError").html(responce);
                }
            }
        });
        return false;
    }
    return false;
}

function validateChangePassword(){
    var old         = document.getElementById('oldpassword').value;
    var password    = document.getElementById('newpassword').value;
    var password1   = document.getElementById('newpassword1').value;
    if(old==''){
        document.getElementById('passwordError').innerHTML = "Enter your old password.";
        document.getElementById('oldpassword').focus();
        changepasswordAddErrorCSS()
        return false;
    }

    if(password==''){
        document.getElementById('passwordError').innerHTML = "Enter new password.";
        document.getElementById('newpassword').focus();
        changepasswordAddErrorCSS()
        return false;
    }

    if(password1==''){
        document.getElementById('passwordError').innerHTML = "Enter new password (again).";
        document.getElementById('newpassword1').focus();
        changepasswordAddErrorCSS()
        return false;
    }

    if(password1 != password){
        document.getElementById('passwordError').innerHTML = "Enter same in new password and new password (again).";
        document.getElementById('newpassword1').focus();
        changepasswordAddErrorCSS()
        return false;
    }
    return true;
}

function changepasswordRemoveErrorCSS(){
    jQuery("#passwordError").css("background","#ffffff");
    jQuery("#passwordError").css("border","0");
}

function changepasswordAddErrorCSS(){
    jQuery("#passwordError").css("background","#ffcccc");
    jQuery("#passwordError").css("border","1px solid #ff0000");
}

function hideErrorBoxOnpasswwordChangePage(){
    jQuery("#passwordError").hide();
    jQuery("#securityError").hide();
}

function submitChangeSecurity(){
    document.getElementById('securityError').style.display = 'block';
    if(!validateChangeSecurity()){
        return false;
    }else{
        var tvar = jQuery('#securitySettings').serialize();
        jQuery("#securityError").css("background","#ffffff");
        jQuery("#securityError").css("border","0");
        jQuery("#securityError").html('<span>Please wait...</span><img src="/assets/images/ajax-loader2.gif">');
        jQuery.ajax({
            url: '/core/myaccount/updatesecurity.php?security_submit=Submit',
            data:tvar,
            type: "POST",
            cache:false,
            async:true,
            success: function(responce){
                if(responce=='SUCCESS'){
                    jQuery("#securityError").html('<span>You have successfully changed your security question and answer.</span>');
                    document.securitySettings.reset();
                }else if(responce!='SUCCESS'){
                    changeSecurityAddErrorCSS();
                    jQuery("#securityError").html(responce);
                }
            }
        });
        return false;
    }
}

function validateChangeSecurity(){
    var question            = document.getElementById('question_id').value;
    var answer              = document.getElementById('answer').value;
    if(question==''){
        document.getElementById('securityError').innerHTML = "Choose security question.";
        document.getElementById('question_id').focus();
        changeSecurityAddErrorCSS();
        return false;
    }

    if(answer==''){
        document.getElementById('securityError').innerHTML = "Enter your answer.";
        document.getElementById('answer').focus();
        changeSecurityAddErrorCSS();
        return false;
    }
    return true;
}

function changeSecurityRemoveErrorCSS(){
    jQuery("#securityError").css("background","#ffffff");
    jQuery("#securityError").css("border","0");
}

function changeSecurityAddErrorCSS(){
    jQuery("#securityError").css("background","#ffcccc");
    jQuery("#securityError").css("border","1px solid #ff0000");
}
