/*
#############################################################################
# Function Name: isBlank()
# Created By: Arpan R
# Created On: April 19 ,2007
# Purpose: Function to check wether given value is blank or not.
# Parameters: string strValue : string.
# ON SUCCESS: Returns TRUE if value is blank.
# ON FAILURE: Returns FLASE  if value is not blank.
#############################################################################
*/

function isBlank(strValue)
{
	for(var i = 0; i < strValue.length; i++)
	{
		var c = strValue.charAt(i);
		if ((c != ' ') && (c != '\n') && (c != '\t')) return false;
	}
	return true;
}

/*
#############################################################################
# Function Name: isValidEmail()
# Created By: Arpan R
# Created On: April 19 ,2007
# Purpose: Validate an email address.
# Parameters: string strEmail : Email address
# ON SUCCESS: Returns TRUE if string is in valid email format.
# ON FAILURE: Returns FLASE if string is not in valid email format.
#############################################################################
*/
function isValidEmail(strEmail)
{
	// assume an email address cannot start with an @ or white space, but it
	// must contain the @ character followed by groups of alphanumerics and '-'
	// followed by the dot character '.'
	// It must end with 2 or 3 alphanumerics.
	//
	var alnum="a-zA-Z0-9";
	exp="^[^@\\s]+@(["+alnum+"+\\-]+\\.)+["+alnum+"]["+alnum+"]["+alnum+"]?$";
	emailregexp = new RegExp(exp);
	result = strEmail.match(emailregexp);
	if (result != null)
	{
		return true;
	}
	else
	{
		return false;
	}
}

function inArray(needle, haystack) {
	for (var i in haystack) {
		if (needle == haystack[i]) {
			return true;
		}
	}
	return false;
}

/*
#############################################################################
# Function Name: isValidNumber()
# Created By: Arpan R
# Created On: April 19 ,2007
# Purpose: Checks if the passed string contain valid number or not.
# Parameters: string numval : Number to check
# ON SUCCESS: Returns TRUE if value is numeric.
# ON FAILURE: Returns FLASE  if value is not numeric.
#############################################################################
*/

function isValidNumber(numval)
{
	if (isBlank(numval))
	{
		return false;
	}
	var myRegExp = new RegExp("^[0-9]*$");
	return myRegExp.test(numval);
}


function trimArray(arr2){
	var arr1=new Array();
	for(j=0;j<arr2.length;j++)
		if(arr2[j]!="")
			arr1[arr1.length]=arr2[j];

	arr2.length=arr1.length;
	for(j=0;j<arr1.length;j++)
		arr2[j]=arr1[j];

	return arr2;
}


function hasClass(ele,cls) {
	return ele.className.match(new RegExp('(\\s|^)'+cls+'(\\s|$)'));
}

function addClass(ele,cls) {
	if (!this.hasClass(ele,cls)) ele.className += " "+cls;
}

function removeClass(ele,cls) {
	if (hasClass(ele,cls)) {
		var reg = new RegExp('(\\s|^)'+cls+'(\\s|$)');
		ele.className=ele.className.replace(reg,' ');
	}
}



function commentsshowhide()
{
	var divshowhide = document.getElementById('commentshowhide');
	var divcommentlist = document.getElementById('commentlist');
	if (divshowhide.className=="show open-show")
	{
		divshowhide.className="show";
		divshowhide.innerHTML = '<a href="JavaScript:void(0);">Show all comments</a>';
		divcommentlist.style.display='none';
		divcommentlist.style.visibility='hidden';
	}
	else
	{
		divshowhide.className="show open-show";
		divshowhide.innerHTML = '<a href="JavaScript:void(0);">Hide all comments</a>';
		divcommentlist.style.display='block';
		divcommentlist.style.visibility='visible';
	}
}

function confirmDelete()
{
	return window.confirm("Attention!!! You are about to delete this record.");
}

function quoteComment(comment_num) {
	str_comment = document.getElementById("comment_body_"+comment_num).innerHTML;
	str_username = document.getElementById("comment_user_"+comment_num).innerHTML;

	str_new_comment = document.add_view_comments.comments.value;
	document.add_view_comments.comments.value = "<blockquote><cite>"+str_username+" said: </cite>"+str_comment+"</blockquote>" + str_new_comment;
}

function divStyle(s, w, h, d, v, o, p, t, l) {
	document.getElementById("TFstafPingMessage").style.display = "none";
	document.getElementById("TFstafPingMessage").style.visibility = "hidden";

	if (w != -1) { var containerWidth = w + "px"; document.getElementById(s).style.width = containerWidth; }
	if (h != -1) { var containerHeight = h + "px"; document.getElementById(s).style.height = containerHeight; }
	if (d != 0) { document.getElementById(s).style.display = d; }
	if (v != 0) { document.getElementById(s).style.visibility = v; }
	if (o != 0) { document.getElementById(s).style.overflow = o; }
	if (p != 0) { document.getElementById(s).style.position = p; }
	if (t) { var containerTop = t + "px"; document.getElementById(s).style.top = containerTop; }
	if (l) { var containerLeft = l + "px"; document.getElementById(s).style.left = containerLeft; }
}

function stafPing(s) {
	var mySTAFImage = new Image(1,1);
	mySTAFImage.src = "/tellafriend.php?toAddress=" + s.toAddress.value + "&product_id=" + s.product_id.value;
	document.getElementById("TFstafPingImage").src = mySTAFImage.src;
	alert("An Email with the thumbnail of this shirt has been sent to your friend at: "+s.toAddress.value);
	document.getElementById("toAddress_id").value = 'Email address(es)';
	document.getElementById("it4_id").className = 'it4';
	return false;
}

function checkadd_view_comments(add_view_comments)
{
	if(add_view_comments.comments.value=="")
	{
		alert("Please write your comments");
		add_view_comments.comments.focus();
		return false;
	}
}

function getNewHTTPObject()
{
	var xmlHttp;
	try
	{
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	}
	catch (e)
	{
	// Internet Explorer
		try
		{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			try
			{
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e)
			{
				alert("Your browser does not support AJAX!");
				return false;
			}
		}
	}
	return xmlHttp;
}

var xmlObjForConstantContact;

function addConstantContact() {
	var cc_new_contact = document.getElementById('constantContact_form_email').value;
	if (isBlank(cc_new_contact)) {
		alert("Email field can not be left Blank");
		return false;
	}

	if (!isValidEmail(cc_new_contact)) {
		alert("Email field does not contain a valid e-mail id, Please correct and Try Again!");
		return false;
	}

	xmlObjForConstantContact = getNewHTTPObject();
	if(xmlObjForConstantContact) {

		xmlObjForConstantContact.open('GET', 'constant_contact.php?method=addContact&email_id='+cc_new_contact, true);
		xmlObjForConstantContact.onreadystatechange = function() {

			if(xmlObjForConstantContact.readyState == 4){ //Finished loading the response

				var response = xmlObjForConstantContact.responseText;
				if(response == "success") {
					alert("Congratulations! You have successfully registered for TeeFury Newsletter!");
				}
				else{
					switch (response) {
						case '409'  :  alert("This E-Mail already registered for TeeFury Newsletter!");
						break;
						default     :  alert("This E-Mail already registered for TeeFury Newsletter!");
						break;
					}
				}
			}
		}
		xmlObjForConstantContact.send(null);
	}
	else {
		alert('System Error!!! Please try again later!!!');
	}
}

function addConstantContact2() {
	var cc_new_contact = document.getElementById('constantContact_overley_form_email').value;
	if (isBlank(cc_new_contact)) {
		alert("Email field can not be left Blank");
		return false;
	}

	if (!isValidEmail(cc_new_contact)) {
		alert("Email field does not contain a valid e-mail id, Please correct and Try Again!");
		return false;
	}

	xmlObjForConstantContact = getNewHTTPObject();
	if(xmlObjForConstantContact) {

		xmlObjForConstantContact.open('GET', 'constant_contact.php?method=addContact&email_id='+cc_new_contact, true);
		xmlObjForConstantContact.onreadystatechange = function() {

			if(xmlObjForConstantContact.readyState == 4){ //Finished loading the response

				var response = xmlObjForConstantContact.responseText;
				if(response == "success") {
					alert("Congratulations! You have successfully registered for TeeFury Newsletter!");
				}
				else{
					switch (response) {
						case '409'  :  alert("This E-Mail already registered for TeeFury Newsletter!");
						break;
						default     :  alert("This E-Mail already registered for TeeFury Newsletter!");
						break;
					}
				}
			}
		}
		xmlObjForConstantContact.send(null);
	}
	else {
		alert('System Error!!! Please try again later!!!');
	}
}

function addConstantContactPopUp() {
	var cc_new_contact = document.getElementById('constantContact_popup_form_email').value;
	if (isBlank(cc_new_contact)) {
		alert("Email field can not be left Blank");
		return false;
	}

	if (!isValidEmail(cc_new_contact)) {
		alert("Email field does not contain a valid e-mail id, Please correct and Try Again!");
		return false;
	}

	xmlObjForConstantContact = getNewHTTPObject();
	if(xmlObjForConstantContact) {

		xmlObjForConstantContact.open('GET', 'constant_contact.php?method=addContact&email_id='+cc_new_contact, true);
		xmlObjForConstantContact.onreadystatechange = function() {

			if(xmlObjForConstantContact.readyState == 4){ //Finished loading the response

				var response = xmlObjForConstantContact.responseText;
				if(response == "success") {
					divStyle('TFutil-newsletter', -1, -1, 'none', 'hidden', 0, 'absolute', 50, 100);
					alert("Congratulations! You have successfully registered for TeeFury Newsletter!");
				}
				else{
					document.getElementById('constantContact_popup_form_email').value = '';
					switch (response) {
						case '409'  :  alert("This E-Mail already registered for TeeFury Newsletter!");
						break;
						default     :  alert("This E-Mail already registered for TeeFury Newsletter!");
						break;
					}
				}
			}
		}
		xmlObjForConstantContact.send(null);
	}
	else {
		alert('System Error!!! Please try again later!!!');
	}
}

function apply_discount(ele_id){

	var ele = document.getElementById(ele_id);

	if (isBlank(ele.value)) {
		ele.value = "";
		alert("Discount Code can not be blank! Please correct and try again!");
		return false;
	}

	window.location = 'apply_discount.php?discount_code='+ele.value;
}

function updateCart(ele_id, sizeID, price, product_id, color, is_grabbag)
{
	var ele = document.getElementById(ele_id);
	var maxQtyAllowed = 3;
	if(is_grabbag == 1) {
		maxQtyAllowed = 12;
	}
	if (isBlank(ele.value)) {
		ele.value = "";
		alert("Quantity can not be blank! Please correct and try again!");
		return false;
	}
	if (!isValidNumber(ele.value)) {
		ele.value = "";
		alert("Quantity can not be non-numeric! Please update and try again!");
		return false;
	}
	if (parseInt(ele.value)>maxQtyAllowed) {
		ele.value = "";
		alert("Quantity can not be greater than "+maxQtyAllowed+" Please update and try again!");
		return false;
	}
	cartList = document.getElementById("hidden_cartList").value;

	ch = "";
	str = "";
	check = 1;
	sizeIds = new Array();
	sizeQty = new Array();
	for (var i=1; i<(cartList.length + 1); i++) {
		if (check == 1) {
			ch = cartList.substr(i,1);
			if (ch != "=") {
				str = str + ch;
			}
			else {
				check = 2;
				sizeIds.push(str);
				str = "";
			}
		}
		else {
			ch = cartList.substr(i,1);
			if (ch != "&") {
				str = str + ch;
			}
			else {
				check = 1;
				sizeQty.push(str);
				str = "";
			}
		}
	}
	sizeQty.push(str);
	newCartList = "";
	for (var j=0; j < sizeIds.length; j++) {
		if (sizeIds[j] == sizeID) {
			sizeQty[j] = ele.value;
		}
		newCartList = newCartList + "&" + sizeIds[j] + "=" + sizeQty[j];
	}
	window.location = 'cart.php?method=update&size=' + sizeID + '&product_id=' + product_id + newCartList;
}

function updateStickerCart(ele_id, sticker_id)
{
	var ele = document.getElementById(ele_id);
	if (isBlank(ele.value)) {
		ele.value = "";
		alert("Quantity can not be blank! Please correct and try again!");
		return false;
	}
	if (!isValidNumber(ele.value)) {
		ele.value = "";
		alert("Quantity can not be non-numeric! Please update and try again!");
		return false;
	}
	if (ele.value > 6) {
		ele.value = "";
		alert("Quantity can not be more than 6! Please update and try again!");
		return false;
	}
	
	if (ele.value == 0) {
		window.location = 'cartRemoveSticker.php?stickerId=' + sticker_id;
	}
	else {
		window.location = 'cartAddSticker.php?stickerId=' + sticker_id + '&qty=' + ele.value;
	}
}

function updatePosterCart(ele_id, poster_id, poster_size_id)
{
	var ele = document.getElementById(ele_id);
	if (isBlank(ele.value)) {
		ele.value = "";
		alert("Quantity can not be blank! Please correct and try again!");
		return false;
	}
	if (!isValidNumber(ele.value)) {
		ele.value = "";
		alert("Quantity can not be non-numeric! Please update and try again!");
		return false;
	}
	if (ele.value > 6) {
		ele.value = "";
		alert("Quantity can not be more than 6! Please update and try again!");
		return false;
	}
	
	if (ele.value == 0) {
		window.location = 'cartRemovePoster.php?posterId=' + poster_id + '&posterSizeId=' + poster_size_id;
	}
	else {
		window.location = 'cartAddPoster.php?posterId=' + poster_id + '&posterSizeId=' + poster_size_id + '&qty=' + ele.value;
	}
}

function updateExProCart(ele_id, product_id, current_val)
{
	var ele = document.getElementById(ele_id);
	var TotalCount = parseInt(document.getElementById('TotalCount').value);
	var total_count_ex_pro = parseInt(document.getElementById('total_count_ex_pro').value);

	if (isBlank(ele.value)) {
		ele.value = "";
		alert("Quantity can not be blank! Please correct and try again!");
		return false;
	}
	if (!isValidNumber(ele.value)) {
		ele.value = "";
		alert("Quantity can not be non-numeric! Please update and try again!");
		return false;
	}

	if ( (TotalCount*6)<((total_count_ex_pro-current_val)+parseInt(ele.value)) || ((total_count_ex_pro-current_val)+parseInt(ele.value)) > 50 )
	{
		var showmaxcount;
		if (((total_count_ex_pro-current_val)+parseInt(ele.value)) > 50)
		{
			showmaxcount = 50;
		}
		else {
			showmaxcount = (TotalCount*6);
		}
		ele.value = "";
		alert("Oops. You can only buy "+(showmaxcount)+" bonus products for each daily tee in your cart.");
		return false;
	}

	cartList = document.getElementById("hidden_cartList").value;

	ch = "";
	str = "";
	check = 1;
	sizeIds = new Array();
	sizeQty = new Array();
	for (var i=1; i<(cartList.length + 1); i++) {
		if (check == 1) {
			ch = cartList.substr(i,1);
			if (ch != "=") {
				str = str + ch;
			}
			else {
				check = 2;
				sizeIds.push(str);
				str = "";
			}
		}
		else {
			ch = cartList.substr(i,1);
			if (ch != "&") {
				str = str + ch;
			}
			else {
				check = 1;
				sizeQty.push(str);
				str = "";
			}
		}
	}
	sizeQty.push(str);
	newCartList = "";
	for (var j=0; j < sizeIds.length; j++) {
		if (sizeIds[j] == ele_id) {
			sizeQty[j] = ele.value;
		}
		newCartList = newCartList + "&" + sizeIds[j] + "=" + sizeQty[j];
	}
	window.location = 'cart.php?method=update&product_id=' + product_id+ newCartList;
}

function popup_zoom() {
	var div_ele = document.getElementById('popup_zoom');
	div_ele.style.display = 'block';
}

function popup_zoom_close() {
	var div_ele = document.getElementById('popup_zoom');
	div_ele.style.display = 'none';
}

function popup_login() {
	var div_ele = document.getElementById('popup_login');
	div_ele.style.display = 'block';
}

function popup_login_close() {
	var div_ele = document.getElementById('popup_login');
	div_ele.style.display = 'none';
}

var xmlObjForAjaxLogin;

function ajaxLogin() {
	var poststr = "ajax_login_username=" + escape(encodeURI(document.getElementById('ajax_login_username').value)) +
                    "&ajax_login_password=" + escape(encodeURI(document.getElementById('ajax_login_password').value)) +
						"&ajax_login_fb_user_id=" + escape(encodeURI(document.getElementById('ajax_login_fb_user_id').value));
	var link_back = '';

	xmlObjForAjaxLogin = getNewHTTPObject();
	if(xmlObjForAjaxLogin) {

		xmlObjForAjaxLogin.open('POST', 'ajax_login.php', true);
		xmlObjForAjaxLogin.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		/*
		xmlObjForAjaxLogin.setRequestHeader("Content-length", poststr.length);
		xmlObjForAjaxLogin.setRequestHeader("Connection", "close");
		*/
		xmlObjForAjaxLogin.send(poststr);

		xmlObjForAjaxLogin.onreadystatechange = function() {

			if(xmlObjForAjaxLogin.readyState == 4){ //Finished loading the response

				var response = xmlObjForAjaxLogin.responseText;
				if(response == "success") {
					link_back = document.getElementById('linkback_page').value;
					target_page = document.getElementById('target_page').value;
					window.location=target_page+"?linkback_page="+link_back;
				}
				else if(response == "failed") {
					alert("Invalid Username/Password. Please try again with the correct details!");
				}
			}
		}
		xmlObjForAjaxLogin.send(null);
	}
	else {
		alert('System Error!!! Please try again later!!!');
	}
	return false;
}


function changePaymentMethod(pValue,pForm)
{
	if(pValue=='pp')
	{
		document.forms[pForm].elements['method_change'].value = "pp";
		document.getElementById('ccDetails').style.display = 'none';

		document.getElementById('ppDetails').style.display = 'block';
	}
	else if(pValue=='cc')
	{
		document.forms[pForm].elements['method_change'].value = "cc";
		document.getElementById('ccDetails').style.display = 'block';

		document.getElementById('ppDetails').style.display = 'none';
	}
}

function funct_samebilling()
{
	frm=document.frmcheckoutinfo;
	if(frm.copyshippingvalues.checked==true)
	{
		frm.b_name.value=frm.s_name.value
		frm.b_address.value=frm.s_address.value
		frm.b_address2.value=frm.s_address2.value
		frm.b_city.value=frm.s_city.value
		frm.b_state.value=frm.s_state.value
		frm.b_postal_code.value=frm.s_postal_code.value
		frm.b_country.value=frm.s_country.value
	}
	else
	{
		frm.b_name.value=""
		frm.b_address.value=""
		frm.b_address2.value=""
		frm.b_city.value=""
		frm.b_state.value=""
		frm.b_postal_code.value=""
		frm.b_country.value=""
	}
}


function checkfrmcheckoutinfo(frmcheckoutinfo)
{
	if(frmcheckoutinfo.s_name.value=="")
	{
		alert("Your Shipping Name is required.");
		frmcheckoutinfo.s_name.focus();
		return false;
	}
	if(frmcheckoutinfo.s_address.value=="")
	{
		alert("Line 1 of your shipping address is required.");
		frmcheckoutinfo.s_address.focus();
		return false;
	}
	
	if(frmcheckoutinfo.s_city.value=="")
	{
		alert("Your Shipping city is required.");
		frmcheckoutinfo.s_city.focus();
		return false;
	}
	if(frmcheckoutinfo.s_state.value=="" || frmcheckoutinfo.s_state.value==0)
	{
		alert("Your Shipping State is required");
		frmcheckoutinfo.s_state.focus();
		return false;
	}
	if(frmcheckoutinfo.s_postal_code.value=="")
	{
		alert("Your Shipping Postal Code is required");
		frmcheckoutinfo.s_postal_code.focus();
		return false;
	}

	if(frmcheckoutinfo.s_country.value=="" || frmcheckoutinfo.s_country.value==0)
	{
		alert("Your Shipping Country is required");
		frmcheckoutinfo.s_country.focus();
		return false;
	}
	if(frmcheckoutinfo.b_name.value=="")
	{
		alert("Your Billing Name is required.");
		frmcheckoutinfo.b_name.focus();
		return false;
	}
	if(frmcheckoutinfo.b_address.value=="")
	{
		alert("Line 1 of your billing address is required.");
		frmcheckoutinfo.b_address.focus();
		return false;
	}
	
	if(frmcheckoutinfo.b_city.value=="")
	{
		alert("Your Billing city is required.");
		frmcheckoutinfo.b_city.focus();
		return false;
	}
	if(frmcheckoutinfo.b_state.value=="" || frmcheckoutinfo.b_state.value==0)
	{
		alert("Your Billing State is required");
		frmcheckoutinfo.b_state.focus();
		return false;
	}
	if(frmcheckoutinfo.b_postal_code.value=="")
	{
		alert("Your Billing Postal Code is required");
		frmcheckoutinfo.b_postal_code.focus();
		return false;
	}
	if(frmcheckoutinfo.b_country.value=="" || frmcheckoutinfo.b_country.value==0)
	{
		alert("Your Billing Country is required.");
		frmcheckoutinfo.b_country.focus();
		return false;
	}
	if(frmcheckoutinfo.b_country.value!=frmcheckoutinfo.s_country.value)
	{
		alert("Billing Address Country and Shipping Address Country must be the same.");
		frmcheckoutinfo.b_country.focus();
		return false;
	}

	if (frmcheckoutinfo.shipping_method.value == null || frmcheckoutinfo.shipping_method.value == "")
	{
		alert("Please Select Your Shipping Method");
		frmcheckoutinfo.b_country.focus();
		return false;
	}

	if (frmcheckoutinfo.method_change.value == "cc" && document.frmcheckoutinfo.grandTotal.value > 0)
	{
		if(frmcheckoutinfo.card_number.value=="")
		{
			alert("Your Credit Card number is required.");
			frmcheckoutinfo.card_number.focus();
			return false;
		}
		if(frmcheckoutinfo.card.value=="")
		{
			alert("Your CCV Code is required.  Check the back of your credit card.");
			frmcheckoutinfo.card.focus();
			return false;
		}
	}

	if(frmcheckoutinfo.b_email.value=="")
	{
		alert("Please enter your email address.  We will send a copy of your receipt to this email address.");
		frmcheckoutinfo.b_email.focus();
		return false;
	}

	return true;
}

function checkfrmcheckoutinfo_cim(frmcheckoutinfo)
{

	if (frmcheckoutinfo.shipping_method.value == null || frmcheckoutinfo.shipping_method.value == "")
	{
		alert("Please Select Your Shipping Method");
		frmcheckoutinfo.b_country.focus();
		return false;
	}
	if (frmcheckoutinfo.field_edit.value == true)
	{
		if (frmcheckoutinfo.shipping_method.value == null || frmcheckoutinfo.shipping_method.value == "")
		{
			alert("Please Select Your Shipping Method");
			frmcheckoutinfo.b_country.focus();
			return false;
		}

		if (frmcheckoutinfo.method_change.value == "cc" && document.frmcheckoutinfo.grandTotal.value > 0)
		{
			if(frmcheckoutinfo.card_number.value=="")
			{
				alert("Your Credit Card number is required.");
				frmcheckoutinfo.card_number.focus();
				return false;
			}
			if(frmcheckoutinfo.card.value=="")
			{
				alert("Your CCV Code is required.  Check the back of your credit card.");
				frmcheckoutinfo.card.focus();
				return false;
			}
		}
	}
	
	if(frmcheckoutinfo.b_email.value=="")
	{
		alert("Please enter your email address.  We will send a copy of your receipt to this email address.");
		frmcheckoutinfo.b_email.focus();
		return false;
	}

	return true;
}

function addExProToCart(product_id, ex_pro_id, is_shirt, size_id, shirt_for, qty_already_present) {

	if ( typeof qty_already_present == "undefined")
	{
		qty_already_present = 0;
	}

	var new_qty = parseInt(qty_already_present) + 1;

	cartList = document.getElementById("hidden_cartList").value;

	if (is_shirt) {
		if (shirt_for == "men") {
			addedExPro = "&ex_pro_id[]=" + ex_pro_id + "&" + ex_pro_id + "_ex_pro_men_qty_" + size_id + "="+new_qty;
		}
		if (shirt_for == "women") {
			addedExPro = "&ex_pro_id[]=" + ex_pro_id + "&" + ex_pro_id + "_ex_pro_women_qty_" + size_id + "="+new_qty;
		}
	}
	else {
		addedExPro = "&ex_pro_id[]=" + ex_pro_id + "&" + ex_pro_id + "_ex_pro_qty="+new_qty;
	}

	window.location = 'cart.php?method=update&product_id=' + product_id + cartList + addedExPro;
}

function validateEmailAddress(email_address)
{
	// This function is used to validate a given e-mail
	// address for the proper syntax
	if (email_address == ""){
		return false;
	}
	badStuff = ";:/,' \"\\";
	for (i=0; i<badStuff.length; i++){
		badCheck = badStuff.charAt(i)
		if (email_address.indexOf(badCheck,0) != -1){
			return false;
		}
	}
	posOfAtSign = email_address.indexOf("@",1)
	if (posOfAtSign == -1){
		return false;
	}
	if (email_address.indexOf("@",posOfAtSign+1) != -1){
		return false;
	}
	posOfPeriod = email_address.indexOf(".", posOfAtSign)
	if (posOfPeriod == -1){
		return false;
	}
	if (posOfPeriod+2 > email_address.length){
		return false;
	}
	return true
}

function viewWin(filename)
{
	var mybars='width=1025,height=550,directories=no,location=no,menubar=no,status=no,screenX=0,screenY=0';
	mybars+=',titlebar=no,toolbar=no';
	myoptions='scrollbars=yes,resizeable=yes';
	myfeatures=mybars+ ','+myoptions
	var newin=open(filename,'mydoc',myfeatures);
}

function viewWin2(filename)
{
	var mybars='width=500,height=450,directories=no,location=no,menubar=no,status=no,screenX=0,screenY=0';
	mybars+=',titlebar=no,toolbar=no';
	myoptions='scrollbars=yes,resizeable=yes';
	myfeatures=mybars+ ','+myoptions
	var newin=open(filename,'mydoc',myfeatures);
}

function checkSubmitFrm(frm) {

	if (frm.title.value=="") {
		alert("Title cannot be empty!");
		return false;
	}

	if(frm.title.value.length<4 || frm.title.value.length>26)
	{
		alert("Title should be atleast 4 but not more than 25 characters!");
		return false;
	}

	if (frm.submitimage.value=="") {
		alert("Please select a file to upload!");
		return false;
	}

	if (frm.terms.checked!=true) {
		alert("Please accept the legal terms and conditions before uploading.");
		return false;
	}

	return true;
}

var xmlObjForShippingOptions;

function getShippingOptions(onlyUSPS) {

	var frm = document.getElementById('frmcheckoutinfo');
	
	var s_pobox = document.frmcheckoutinfo.s_pobox.value;
	
	if (s_pobox == 1) {
		onlyUSPS = 1;
	}

	if (onlyUSPS === undefined)
	{
		onlyUSPS = 0;
	}

	var onlyUSPSstates = new Array('AK', 'HI', 'GU', 'PR', 'FM', 'MP', 'AE', 'AA', 'AP');

	if (inArray(frm.s_state.value, onlyUSPSstates))
	{
		onlyUSPS = 1;
	}

	if (frm.s_country.value !=0 && frm.s_postal_code.value !='')
	{
		xmlObjForShippingOptions = getNewHTTPObject();
		if(xmlObjForShippingOptions) {
			xmlObjForShippingOptions.open('GET', 'getShippingOptions.php?zip='+frm.s_postal_code.value+'&country='+frm.s_country.value+'&onlyUSPS='+onlyUSPS, true);
			xmlObjForShippingOptions.onreadystatechange = function() {

				if(xmlObjForShippingOptions.readyState == 4){ //Finished loading the response

					var response = xmlObjForShippingOptions.responseText;

					var ShippingOptions_ul = document.getElementById("ShippingOptions_ul");

					if(response == "failed") {
						ShippingOptions_ul.innerHTML = '';
						document.frmcheckoutinfo.shipping_choice = null;
						document.frmcheckoutinfo.shipping_amount.value = null;
						document.frmcheckoutinfo.shipping_method.value = null;
						document.frmcheckoutinfo.package_weight.value = null;
						alert('System Error!!! Please refresh the page or try again later.');
					}
					else if(response == "wrong data") {
						ShippingOptions_ul.innerHTML = '';
						document.frmcheckoutinfo.shipping_choice = null;
						document.frmcheckoutinfo.shipping_amount.value = null;
						document.frmcheckoutinfo.shipping_method.value = null;
						document.frmcheckoutinfo.package_weight.value = null;
						alert('Right now we are not serving to the zip/country you have selected. Please contact service@teefury.com');
					}
					else{

						var shipping_p = document.getElementById('shipping_p');
						shipping_p.innerHTML = '**Please add an additional 3-7 business days to the shipping times listed below to allow for printing, packing and processing of orders**';

						var responseData = eval('(' + response + ')');

						srt_html = '';
						var s_state_value = frm.s_state.value;
						var tax_value=0;
						document.frmcheckoutinfo.package_weight.value = responseData.nonRoundedWeight;
						document.frmcheckoutinfo.totalPosterStickerWeight.value = responseData.totalPosterStickerWeight;
						for (x in responseData.data) {
							var shipping_image;
							if (responseData.data[x].Service == '1') {
								shipping_image = 'images/usps22.jpg';
							}
							else if (responseData.data[x].Service == '2') {
								shipping_image = 'images/fedex22.gif';
							}
							if(s_state_value=="CA") {
								tax_value = (frm.subTotal.value*.0775);
  								tax_value = tax_value.toFixed(2);
							}

							srt_html = srt_html + '<li id="ShippingOption_li_'+x+'"> <div id="shipping_option_'+x+'"><div class="price"><input type="radio" id="radio'+x+'" name="shipping_choice" value="'+responseData.data[x].ShippingCost+'" onClick="getset_shipping_value(event);" /><label for="radio'+x+'">$ '+responseData.data[x].ShippingCost+'</label></div><div class="method" id="div_id_method'+x+'"><a href="#"><img src="'+shipping_image+'" alt="image" /></a><div class="content-holder"><p><B id="id_shipping_name'+x+'">'+responseData.data[x].ServiceName+'</B></p><p>Shipping Time: '+responseData.data[x].ShippingTime+'</p><p>Tracking: '+responseData.data[x].Tracking+'</p>';

							if ((responseData.data[x].ServiceName).match("Signature Confirmation")=="Signature Confirmation")
							{
								srt_html = srt_html + '<div id="TooltipXY" class="TooltipXY" style="">TooltipXY</div>';
							}

							srt_html = srt_html + '</div></div></div></li>';

						}

						ShippingOptions_ul.innerHTML = srt_html;

						/*'<li>
							<div id="shipping_option_a">
								<div class="price">\
								<input type="radio" id="radio2" name="shipping_choice" value="9" checked tabindex="18" onClick="getset_shipping_value();" \/>\
								<label for="radio2">$ 9.00<\/label>\
							<\/div>\
							<div class="method">\
								<a href="#"><img src="images/usps.jpeg" alt="image" \/><\/a>\
								<div class="content-holder">\
									<p>Total cost with shipping: <span id="ship_total_2">'."$".sprintf("%.2f",$subTotal+9).'<\/span><\/p>\
									<p>(3-5 weeks)  No Tracking<\/p>\
								<\/div>\
							<\/div>
							</div>
						</li>';*/
					}
				}
			}
			xmlObjForShippingOptions.send(null);
		}
		else {
			alert('System Error!!! Please refresh the page or try again later.');
		}
	}
}

function ShowDiv(e)
{
	var div = document.getElementById('TooltipXY');
	if (div)
	{
		div.style.position = 'relative';
		div.style.display = e;
		div.innerHTML = "You've selected a shipping method that requires you to be at home to sign for your package when it's delivered. <BR>If you cannot be present to sign for your package, please select a different shipping method. Thanks";
	}
}

function getset_shipping_value(event)
{
	var frm = document.getElementById('frmcheckoutinfo');
    var total_without_shipping = frm.subTotal.value;
	var GrandTotal;
    if (document.frmcheckoutinfo.shipping_choice != null)
    {
        if (document.frmcheckoutinfo.shipping_choice.length)
        {
            for (var i=0; i < document.frmcheckoutinfo.shipping_choice.length; i++)
            {
                if (document.frmcheckoutinfo.shipping_choice[i].checked)
                {
                    var rad_val = document.frmcheckoutinfo.shipping_choice[i].value;
                    var dis_val = document.frmcheckoutinfo.discount.value;
                    var shippingamountspan = document.getElementById('shippingamountspan');
					var id_shipping_name = document.getElementById('id_shipping_name'+i);
					var shipping_method = id_shipping_name.innerHTML;
                    var taxamountspan = document.getElementById('taxamountspan');
                    var totalamountspan = document.getElementById('totalamountspan');
                    shippingamountspan.innerHTML = parseFloat(rad_val).toFixed(2);
                    var taxamount = taxamountspan.innerHTML;
					GrandTotal = (parseFloat(total_without_shipping)+parseFloat(rad_val)+parseFloat(taxamount)-parseFloat(dis_val)).toFixed(2);
					if (GrandTotal <=0) {
						GrandTotal = "0.00";
					}
					totalamountspan.innerHTML = GrandTotal;

                    document.frmcheckoutinfo.tax_amount.value = parseFloat(taxamount);
                    document.frmcheckoutinfo.shipping_amount.value = parseFloat(rad_val);
					document.frmcheckoutinfo.shipping_method.value = shipping_method;
                    document.frmcheckoutinfo.grandTotal.value = GrandTotal;

					if (shipping_method.match("Signature Confirmation")=="Signature Confirmation") {
						ShowDiv('block');
					}
					else {
						ShowDiv('none');
					}

                }
            }
        }
        else {
            var rad_val = document.frmcheckoutinfo.shipping_choice.value;
            var dis_val = document.frmcheckoutinfo.discount.value;
            var shippingamountspan = document.getElementById('shippingamountspan');
			var id_shipping_name = document.getElementById('id_shipping_name0');
			var shipping_method = id_shipping_name.innerHTML;
            var taxamountspan = document.getElementById('taxamountspan');
            var totalamountspan = document.getElementById('totalamountspan');
            shippingamountspan.innerHTML = parseFloat(rad_val).toFixed(2);
            var taxamount = taxamountspan.innerHTML;
            GrandTotal = (parseFloat(total_without_shipping)+parseFloat(rad_val)+parseFloat(taxamount)-parseFloat(dis_val)).toFixed(2);
			if (GrandTotal <=0) {
				GrandTotal = "0.00";
			}
			totalamountspan.innerHTML = GrandTotal;

            document.frmcheckoutinfo.tax_amount.value = parseFloat(taxamount);
            document.frmcheckoutinfo.shipping_amount.value = parseFloat(rad_val);
			document.frmcheckoutinfo.shipping_method.value = shipping_method;
            document.frmcheckoutinfo.grandTotal.value = GrandTotal;
        }

		var paymentdiv = document.getElementById('payment-information');
		paymentdiv.style.position = 'relative';
		if (GrandTotal == "0.00")
		{
			paymentdiv.style.display = 'none';
		}
		else {
			if (document.frmcheckoutinfo.field_edit.value == 1){
				paymentdiv.style.display = 'block';
			}
			else {
				paymentdiv.style.display = 'none';
			}
			
		}
    }
}

var xmlObjForAllComments;

function loadAllComments(paginated_comment_count, type, id, co_no) {
	xmlObjForAllComments = getNewHTTPObject();
	if(xmlObjForAllComments) {

		var http_host = document.getElementById('hidden_http_host').value;
		var hidden_http_images = document.getElementById('hidden_http_images').value;

		var d=new Date();
		xmlObjForAllComments.open('GET', http_host+'getAllComments.php?paginated_comment_count='+paginated_comment_count+'&type='+type+'&id='+id+'&s='+d.getTime(), true);

		var more_li = document.getElementById("li_for_more_button");
		var more_button = document.getElementById("button_for_more_comments");

		if (more_button)
		{
			addClass(more_button, "loading");
			more_button.innerHTML = "<CENTER><div style='text-align:center;' class='loading'>&nbsp;</div></CENTER>";

			xmlObjForAllComments.onreadystatechange = function() {
				if(xmlObjForAllComments.readyState == 4){ //Finished loading the response

					var response = xmlObjForAllComments.responseText;

					if(response == "failed") {
						alert('System Error!!! Please refresh the page or try again later.');
					}
					else{
						var comments_ul = document.getElementById('comments_ul');
						comments_ul.removeChild(more_li);

						var responseData = eval('(' + response + ')');

						var head_li, com_a, imageholder_div, contentholder_div, commentabout_p, commentbody_div, actionbar_div, actionbar_div_text;

						for (x in responseData.data)
						{
							head_li = document.createElement('li');

								com_a = document.createElement('a');
								com_a.setAttribute('name',"comment_no_"+responseData.data[x].comment_id);
								head_li.appendChild(com_a);

								imageholder_div = document.createElement('div');
								imageholder_div.setAttribute('class',"image-holder");
								imageholder_div.innerHTML = '<A HREF="'+http_host+responseData.data[x].user_link+'"><img src="'+hidden_http_images+responseData.data[x].avatar+'" alt="image" /></A>';
								if (responseData.data[x].is_admin==true)
								{
									imageholder_div.innerHTML += '<span class="zipper">zipper</span>';
								}
								head_li.appendChild(imageholder_div);

								contentholder_div = document.createElement('div');
								contentholder_div.setAttribute('class',"content-holder");
									commentabout_p = document.createElement('p');
									commentabout_p.setAttribute('class',"comment-about");
									commentabout_p.innerHTML = '<strong class="author"><a href="'+http_host+responseData.data[x].user_link+'" id="comment_user_'+responseData.data[x].comment_count+'">'+responseData.data[x].username+'</a></strong><em class="date">said '+responseData.data[x].comment_date+'</em>';
									contentholder_div.appendChild(commentabout_p);

									commentbody_div = document.createElement('div');
									commentbody_div.setAttribute('id',"comment_body_"+responseData.data[x].comment_count);
									commentbody_div.innerHTML = responseData.data[x].comment;
									contentholder_div.appendChild(commentbody_div);
								head_li.appendChild(contentholder_div);

								actionbar_div = document.createElement('div');
								actionbar_div.setAttribute('class',"action-bar");
								actionbar_div_text = '<ul>';
								if (document.getElementById("hidden_session_is_admin").value==true)
								{
									actionbar_div_text += '<li><a href="'+http_host+'delete_comment.php?comment_id='+responseData.data[x].comment_id+'&refer=index.php" class="delete" onClick=\'return confirmDelete();\'>Delete</a></li><li><a href="'+http_host+'edit_comment.php?comment_id='+responseData.data[x].comment_id+'&refer=index.php" class="edit">Edit</a></li>';
								}
								if (document.getElementById("hidden_session_logged_in").value=="true")
								{
									actionbar_div_text += '<li><a href="#comment_tag" class="reply" onClick=\'javascript: quoteComment('+responseData.data[x].comment_count+');\'>Reply</a></li>';
								}
								else
								{
									actionbar_div_text += '<li><a href="#comment_tag" class="reply" >Reply</a></li>';
								}
								actionbar_div_text += '</ul>';
								actionbar_div.innerHTML = actionbar_div_text;
								head_li.appendChild(actionbar_div);

							comments_ul.appendChild(head_li);
						}
						if (co_no!=null)
						{
							window.location=window.location+"#comment_no_"+co_no;
						}
					}
				}
			}
			xmlObjForAllComments.send(null);
		}
		else {
			if (co_no!=null)
			{
				window.location=window.location+"#comment_no_"+co_no;
			}
		}
	}
}


function isCreditCard(textObj) {
 /*
  *  This function validates a credit card entry.
  *  If the checksum is ok, the function returns true.
  */
   var ccNum;
   var odd = 1;
   var even = 2;
   var calcCard = 0;
   var calcs = 0;
   var ccNum2 = "";
   var aChar = '';
   var cc;
   var r;

   ccNum = textObj.value;
   for(var i = 0; i != ccNum.length; i++) {
      aChar = ccNum.substring(i,i+1);
      if(aChar == '-') {
         continue;
      }

      ccNum2 = ccNum2 + aChar;
   }

   cc = parseInt(ccNum2);
   if(cc == 0) {
      return false;
   }
   r = ccNum.length / 2;
   if(ccNum.length - (parseInt(r)*2) == 0) {
      odd = 2;
      even = 1;
   }

   for(var x = ccNum.length - 1; x > 0; x--) {
      r = x / 2;
      if(r < 1) {
         r++;
      }
      if(x - (parseInt(r) * 2) != 0) {
         calcs = (parseInt(ccNum.charAt(x - 1))) * odd;
      }
      else {
         calcs = (parseInt(ccNum.charAt(x - 1))) * even;
      }
      if(calcs >= 10) {
         calcs = calcs - 10 + 1;
      }
      calcCard = calcCard + calcs;
   }

   calcs = 10 - (calcCard % 10);
   if(calcs == 10) {
      calcs = 0;
   }

   if(calcs == (parseInt(ccNum.charAt(ccNum.length - 1)))) {
      return true;
   }
   else {
      return false;
   }
}

