// Admin section //

/*function ieversion() {
ereg('MSIE ([0-9]\.[0-9])',$_SERVER['HTTP_USER_AGENT'],$reg);
if(!isset($reg[1])) {
return -1;
} else {
//return floatval($reg[1]);
if(floatval($reg[1]) == '9'){ //checks for evil eye of ie6
return floatval($reg[1]); //here you can add other custom code as well

}else{
return 'Not ie6, maybe 7 or 8';
}
}
}*/

/*function alert(message) {

	var id = blind.add({ptype:"div", pclass:"alert", lock: true});

	var o = $('#col1'+id);

	o.html(message);

	blind.repos();

	setTimeout("blind.rem()", 1500);

}*/




function OnButton1()
{
    document.checkout.action = "includes/order_place.php"    // First target

    document.checkout.target = "iframe1";    // Open in a iframe

    document.checkout.submit();        // Submit the page

    document.checkout.action = "https://www.paypal.com/cgi-bin/webscr"    // Second target

    document.checkout.target = "iframe2";    // Open in a iframe

    document.checkout.submit();        // Submit the page

    return true;
}
 


function submitForm(o) {

	

	

	

	

		var arrIds = $(o).attr('name').split('_');

		var shipping_cost = arrIds[1];

		//alert(shipping_cost);

	

	

	var first_name = $('#firstname').val();

	//alert(first_name);

	var last_name = $('#lastname').val();

	var email = $('#email').val();

	var night_phone_a = $('#night_phone_a').val();

	var night_phone_b = $('#night_phone_b').val();

	//alert(night_phone_b);

	var night_phone_c = $('#night_phone_c').val();

	var address1 = $('#address1').val();

	var address2 = $('#address2').val();

	var city = $('#city').val();

	var state = $('#state').val();

	//alert(state);

	var providence = $('#providence').val();

   	var region = $('#region').val();

	var postalcode = $('#postalcode').val();

	var country = $('#country').val();

	var bill_first_name = $('#bill_first_name').val();

	var bill_last_name = $('#bill_last_name').val();

	var bill_email = $('#bill_email').val();

	//alert(email);

	var bill_night_phone_a = $('#bill_night_phone_a').val();

	var bill_night_phone_b = $('#bill_night_phone_b').val();

	var bill_night_phone_c = $('#bill_night_phone_c').val();

	var bill_address1 = $('#bill_address1').val();

	var bill_address2 = $('#bill_address2').val();

	var bill_city = $('#bill_city').val();

	//alert(bill_city);

	var bill_state = $('#bill_state').val();

	var bill_providence = $('#bill_providence').val();

   	var bill_region = $('#bill_region').val();

	var bill_postalcode = $('#bill_postalcode').val();

	var bill_country = $('#bill_country').val();

		

	$.post('includes/order_place.php', {shipping_cost:shipping_cost, first_name:first_name, last_name:last_name, email:email, night_phone_a:night_phone_a, night_phone_b:night_phone_b, night_phone_c:night_phone_c, address1:address1, address2:address2, city:city, state:state, providence:providence, region:region, postalcode:postalcode, country:country, bill_first_name:bill_first_name, bill_last_name:bill_last_name, bill_email:bill_email, bill_night_phone_a:bill_night_phone_a, bill_night_phone_b:bill_night_phone_b, bill_night_phone_c:bill_night_phone_c, bill_address1:bill_address1, bill_address2:bill_address2, bill_city:bill_city, bill_state:bill_state, bill_providence:bill_providence, bill_region:bill_region, bill_postalcode:bill_postalcode, bill_country:bill_country})



//alert('before submit');

	//$('#checkout').submit();

//alert('after submit');







}





function updateShipping(){

	

	var first_name = $('#firstname').val();

		//alert(first_name);

	var last_name = $('#lastname').val();

		//alert(last_name);

	var email = $('#email').val();

		//alert(email);

	var night_phone_a = $('#night_phone_a').val();

		//alert(night_phone_a);

	var night_phone_b = $('#night_phone_b').val();

		//alert(night_phone_b);

	var night_phone_c = $('#night_phone_c').val();

		//alert(night_phone_c);	

	var address1 = $('#address1').val();

		//alert(address1);

	var address2 = $('#address2').val();

		//alert(address2);

	var city = $('#city').val();

		//alert(city)

	var state = $('#state').val();

		//alert(state)

	var providence = $('#providence').val();

		//alert(providence)

   	var region = $('#region').val();

		//alert(region)

	var postalcode = $('#postalcode').val();

		//alert(postalcode)

	var country = $('#country').val();

		//alert(country)

	

	var bill_first_name = $('#bill_first_name').val();

		//alert(bill_first_name);

	var bill_last_name = $('#bill_last_name').val();

		//alert(bill_last_name);

	var bill_email = $('#bill_email').val();

		//alert(bill_email);

	var bill_night_phone_a = $('#bill_night_phone_a').val();

		//alert(bill_night_phone_a);

	var bill_night_phone_b = $('#bill_night_phone_b').val();

		//alert(bill_night_phone_b);

	var bill_night_phone_c = $('#bill_night_phone_c').val();

		//alert(bill_night_phone_c);	

	var bill_address1 = $('#bill_address1').val();

		//alert(bill_address1);

	var bill_address2 = $('#bill_address2').val();

		//alert(bill_address2);

	var bill_city = $('#bill_city').val();

		//alert(bill_city)

	var bill_state = $('#bill_state').val();

		//alert(bill_state)

	var bill_providence = $('#bill_providence').val();

		//alert(bill_providence)

   	var bill_region = $('#bill_region').val();

		//alert(bill_region)

	var bill_postalcode = $('#bill_zip').val();

		//alert(bill_zip)

	var bill_country = $('#bill_country').val();

		//alert(bill_country)	

	

	

	

	

	if(country == "US") {

		var shipping_cost = 3;

		//alert(shipping_cost);

	}

	else {

		var shipping_cost = 8;

		//alert(shipping_cost);

	}



$('#col1').load('includes/inc_checkout.php?shipping_cost='+encodeURIComponent(shipping_cost)+'&first_name='+encodeURIComponent(first_name)+'&last_name='+encodeURIComponent(last_name)+'&email='+encodeURIComponent(email)+'&night_phone_a='+encodeURIComponent(night_phone_a)+'&night_phone_b='+encodeURIComponent(night_phone_b)+'&night_phone_c='+encodeURIComponent(night_phone_c)+'&address1='+encodeURIComponent(address1)+'&address2='+encodeURIComponent(address2)+'&city='+encodeURIComponent(city)+'&state='+encodeURIComponent(state)+'&providence='+encodeURIComponent(providence)+'&region='+encodeURIComponent(region)+'&postalcode='+encodeURIComponent(postalcode)+'&country='+encodeURIComponent(country)+'&bill_first_name='+encodeURIComponent(bill_first_name)+'&bill_last_name='+encodeURIComponent(bill_last_name)+'&bill_email='+encodeURIComponent(bill_email)+'&bill_night_phone_a='+encodeURIComponent(bill_night_phone_a)+'&bill_night_phone_b='+encodeURIComponent(bill_night_phone_b)+'&bill_night_phone=_c'+encodeURIComponent(bill_night_phone_c)+'&bill_address1='+encodeURIComponent(bill_address1)+'&bill_address2='+encodeURIComponent(bill_address2)+'&bill_city='+encodeURIComponent(bill_city)+'&bill_providence='+encodeURIComponent(bill_providence)+'&bill_region='+encodeURIComponent(bill_region)+'&bill_state='+encodeURIComponent(bill_state)+'&bill_postalcode='+encodeURIComponent(bill_postalcode)+'&bill_country='+encodeURIComponent(bill_country))

}







function data_change(field)

     {

          var check = true;

          var value = field.value; //get characters

          //check that all characters are digits, ., -, or ""

          for(var i=0;i < field.value.length; ++i)

          {

               var new_key = value.charAt(i); //cycle through characters

               if(((new_key < "0") || (new_key > "9")) && 

                    !(new_key == ""))

               {

                    check = false;

                    break;

               }

          }

          //apply appropriate colour based on value

          if(!check)

          {

               field.style.backgroundColor = "red";

          }

          else

          {

               field.style.backgroundColor = "white";

          }

     }

	 

	 

	 

	 



function adminCatView(o) {

	var arrIds = $(o).attr('id').split('_');

	var p = arrIds[1];

	$('#col1').load('includes/inc_adminProductView.php?categoryID='+(p))

}



function deleteCatItem(o) {

		var arrIds = $(o).attr('id').split('_');

		var src = arrIds[0];

		var product_code = arrIds[1];

		//alert(product_code);

		var arrIds = $(o).attr('name').split('_');

		var src = arrIds[0];

		var categoryID = arrIds[1];

		//alert(categoryID);

		

		

		$('#col1').load('includes/inc_adminDeleteProduct.php?product_code='+(product_code)+'&categoryID='+(categoryID), function(){

																										

		returnAfterCartItemDelete(categoryID);

		});

}



function returnAfterCartItemDelete(categoryID){

$('#col1').load('includes/inc_adminProductView.php?categoryID='+(categoryID))

$('#col2').load('includes/inc_adminLeft.php')



}



function addCatItem(o) {

		var arrIds = $(o).attr('id').split('_');

		var src = arrIds[0];

		var categoryID = arrIds[1];

		//alert(categoryID);

		$('#col1').load('includes/inc_adminInsertProduct.php?categoryID='+(categoryID));

}



function returnAfterCartItemDelete(categoryID){

$('#col1').load('includes/inc_adminProductView.php?categoryID='+(categoryID))

$('#col2').load('includes/inc_adminLeft.php')



}





function returntocatview(categoryID){

	$('#col1').load('includes/inc_adminProductView.php?categoryID='+(categoryID))

	$('#col2').load('includes/inc_adminLeft.php')

}

	

function addProduct() {

	

		var categoryID = $('#categoryID').val();

		//alert(categoryID);

		var product_code = $('#product_code').val();

		//alert(product_code);

		var Price = $('#Price').val();

		//alert(Price);

		var name = $('#name').val();

		//alert(name);

		$.post('includes/inc_adminAddProduct_sql.php', {act: 'addProduct', categoryID:categoryID, product_code:product_code, Price:Price, name:name})

		$('#col1').load('includes/inc_adminProductView.php?categoryID='+(categoryID))

		$('#col2').load('includes/inc_adminLeft.php')

		

		}

		

// End Admin secion //



// Main secion //



function get_current_time() //get current date and time as a string

{

	return strftime("%Y-%m-%d %H:%M:%S", time());

}





function getContent(o) { // Call this from links for main content pages ... not viewing single shirt

	if(o) {

		var arrIds = $(o).attr('id').split('_');

		var p = arrIds[1];

		var params = {};

		if (arrIds.length == 3) {

			params = {cat : arrIds[2]};

		}

		$('#col1').load('includes/inc_'+((p)?p:'index')+'.php', params)

		if(p == 'cart') {

			getCartMini(false);

		}

	}

}





/*function getItemView(){

$('#col1').load('includes/inc_item_view.php',function() {

     $('.nyroModal').nyroModal();

});

}

*/





function getContentpages(o) { // Call this from links for main content pages ... not viewing single shirt

	if(o) {

		var arrIds = $(o).attr('id').split('_');

		var p = arrIds[1];

		var params = {};

		if (arrIds.length == 3) {

			params = {cat : arrIds[2]};

		}

		$('#col1').load('includes/inc_display.php?name='+((p)?p:'index')+'', params)

		if(p == 'cart') {

			getCartMini(false);

		}

	}

}





function getContentSingle(o) { // Call this from links for main content pages ... not viewing single shirt

	if(o) {

		var arrIds = $(o).attr('id').split('_');

		var p = arrIds[1];

		//alert(p);

		var arrIds = $(o).attr('name').split('_');

		var q = arrIds[1];

		//alert(q);

		

		var params = {};

		if (arrIds.length == 3) {

			params = {cat : arrIds[2]};

		}

		$('#col1').load('includes/inc_item_view.php?name='+((q)?q:'index')+'&productID='+((p)?p:'index')+'', params, function(){

																															  $('.nyroModal').nyroModal();

																															  })

		if(p == 'cart') {

			getCartMini(false);

		}

	}

}







function addItem(o) {

	if(o) {

		

		var $btn = $(o);

		var id = $btn.attr('id').split('_')[1];

		//alert(id);

		var catname = $btn.attr('name').split('_')[1];

		//alert(catname);

		var size = $('#size').val();

		//alert(size);

		var qty = $('#qty').val();

		//alert(qty);

		var product_code = $('#product_code').val();

		//alert(product_code);

		var Price = $('#Price').val();

		//alert(list_price);

		var productID = $('#productID').val();

		//alert(productID);

		//var orderID = $('#orderID').val();

		var name = $('#name').val();

		//alert(name);

		var thumbnail = $('#thumbnail').val();

		//alert(thumbnail);

		if(qty && size) {

			//$btn.css({opacity: .6}).text('Processing...');

			$.post('includes/inc_cart_sql.php', {act: 'add', itemid:id, size:size, qty:qty, product_code:product_code, Price:Price, productID:productID, name:name, thumbnail:thumbnail}, function(){

				getCartMini();

				//$btn.text('Success!');

				//setTimeout(function() {

					//var $btn = $('.itemBtnAdd');

					//$btn.text('Add To Cart').animate({opacity:1});

									//}/*, 1500*/);

});

		}

		else {

			var errmsg = 'Please select a ' + ((!size) ? 'size' : '') + ((!qty) ? ((!size) ? ' and ' : '') + 'quantity' : '') + '...';

			alert(errmsg);

			return false;

		}

		returnAfterAdd(catname);

		}

}



function returnAfterAdd(catname){

	

//alert('Your item has been placed into the shopping cart');

	bid = blind.add({ptype:'div'});

	var o = $$('content' + bid);

	aj.set('<div class="infoMsg"><h5>Your item has been placed into the shopping cart.</h5></div>',o);

	blind.rem({fade:'slow',delay:2000});



	$('#col1').load('includes/inc_browse.php?name='+(catname))

}



					

					

					

					

					

					

					

					

					

					

					



function deleteItem(o) {

		var arrIds = $(o).attr('id').split('_');

		var src = arrIds[0];

		var product_code = arrIds[1];

		//alert(product_code);

		$('#col1').load('includes/inc_delete.php', {product_code:product_code}, function(){

		getCartMini();

		returnAfterDelete();

		});

		

}



function returnAfterDelete(){

$('#col1').load('includes/inc_view_cart.php')

}



function continueShopping(){

$('#col1').load('includes/inc_browse.php')

}



			

		



function orderPlace(o) {

	if(o) {

		var $btn = $(o);

		var id = $btn.attr('id').split('_')[1];

		var first_name = $('#first_name').val();

		var last_name = $('#last_name').val();

		var email = $('#email').val();

		var country = $('#country').val();

		var state = $('#state').val();

		var zip = $('#zip').val();

		var city = $('#city').val();

		var address = $('#address').val();

		var phone = $('#phone').val();

		if(first_name && last_name && email && country && state && zip && city && address && phone) {

			$btn.css({opacity: .6}).text('Processing...');

			

			$.post('includes/order_place.php', {act: 'add', first_name:first_name, last_name:last_name , email:email, country:country, state:state, zip:zip, city:city, address:address, phone:phone}, function(){

				getCartMini();

				$btn.text('Success!');

				setTimeout(function() {

					var $btn = $('.itemBtnAdd');

					$btn.text('Place Order').animate({opacity:1});

									}, 1500);

});

		}

		else {

			var errmsg = 'Please fill in the following fields' + '\n' + '\n' 

											 

											 + ((!first_name) ? 'First Name' : '') + '\n' 

											 + ((!last_name) ? 'Last Name' : '') + '\n'  

											 + ((!email) ? 'Email Address' : '') + '\n'  

											 + ((!country) ? 'Country' : '') + '\n'  

											 + ((!state) ? 'State' : '') + '\n'  

											 + ((!zip) ? 'Zip code' : '') + '\n'  

											 + ((!city) ? 'City' : '') + '\n'  

											 + ((!address) ? 'Address' : '') + '\n'  

											 + ((!phone) ? 'Phone Number' : '');

			alert(errmsg);

			return false;

		}

		orderComplete();

		}

}











function orderComplete(){

	

$('#col1').load('includes/inc_order_complete.php')

}





function getCartMini(show) {

//alert('test alert for getCartMini');	

	var p = (show)?'cart_mini':'cart_info';

	$('#col-left').load('includes/inc_'+p+'.php',function(){

//			Nifty("ul#split h3","top");

//			Nifty("ul#split div","bottom same-height");

		}

	);

}





function getItemRead(o) {

	if(o) {

		var arrIds = $(o).attr('id').split('_');

		var src = arrIds[0];

		var id = arrIds[1];

		$('#col1').load('includes/inc_item_view.php', {id:id});

		if(src == 'cart') {

			getCartMini(true);

		}

	}

	else {

		alert('error');

	}

}



function getViewCart(o) {

	if(o) {

		var arrIds = $(o).attr('id').split('_');

		var src = arrIds[0];

		var id = arrIds[1];

		//toggleCol();

		$('#col1').load('includes/inc_view_cart.php', {id:id});

		

	}

}







/*function toggleCol() {

	var c1 = document.getElementById("col1");

	var c3 = document.getElementById("col3");

	if (c1 && c3) {

		c3.style.display = (c3.style.display == "none") ? "block" : "none";

		c1.style.width = (c3.style.display == "none") ? "650px" : "400px";

	}

}

*/



function getCheckout(o) {

	if(o) {

		var arrIds = $(o).attr('id').split('_');

		var src = arrIds[0];

		var id = arrIds[1];

		$('#col1').load('includes/inc_checkout.php', {id:id});

		

	}

}





/*function button(o){



		var arrIds = $(o).attr('id').split('_');

		var p = arrIds[1];

		var params = {};

		//alert(p);

		

		$('#popupContact').load('includes/inc_displayLarge.php?name='+((p)?p:'index')+'', params)



		//centering with css

		centerPopup();

		//load popup

		loadPopup();



}





	

	

//centering popup

function centerPopup(){

	//request data for centering

	var windowWidth = document.documentElement.clientWidth;

	var windowHeight = document.documentElement.clientHeight;

	var popupHeight = $("#popupContact").height();

	var popupWidth = $("#popupContact").width();

	//centering

	$("#popupContact").css({

		"position": "absolute",

		"top": windowHeight/2-popupHeight/2,

		"left": windowWidth/2-popupWidth/2

	});

	//only need force for IE6

	

	$("#backgroundPopup").css({

		"height": windowHeight

	});

	

}



function loadPopup(){

	//loads popup only if it is disabled

	if(popupStatus==0){

		$("#backgroundPopup").css({

			"opacity": "0.7"

		});

		$("#backgroundPopup").fadeIn("slow");

		$("#popupContact").fadeIn("slow");

		

		popupStatus = 1;

	}

}

*/



function updateQty(o){

    var arrId = $(o).attr('id').split('_');

    var act = arrId[0];

    var id = arrId[1];

    var qty = (act == 'update' ? $('#qty_'+id).val() : 0);

    act = (act == 'update' && qty == 0 ? 'delete' : act);

    var cartTotal = 0;

    

    if(act == 'update' && (qty == '' || /[^0-9]/.test(qty))) {

        alert('Invalid Quantity! Must be numeric.');

    } else {

    

        $.post('includes/inc_cart_sql.php', {act: act, id: id, Quantity:qty}, function(){ getCartMini();}, function(){ getViewCart();});

		

		$('#col1').load('includes/inc_view_cart.php');



        if (act == 'delete') {

            $('tr[id^="item_"+id+"_"]').slideUp('slow', function() { $(this).remove(); });

        } else {

            $('#sum_'+id).text( $('#price_'+id) * qty );

        }

		$('#col1').load('includes/inc_view_cart.php');



   

        //Update Cart Total

//        $('span[id^="sum_]').each( function(i) {

 //           cartTotal += parseInt($(this).text());

 //       }

 //       $('#id_for_cart_total').text(cartTotal);

    }



}






