/*********** GENERAL FUNCTIONS ************/

function cleanTextBox(element, action) {
    var dv = element.defaultValue;
    if (action == 'getFocus') if (dv == element.value) element.value = "";
    if (action == 'lostFocus') if ("" == element.value) element.value = dv;
}

function submitEnter(e, method){
	var keycode;
	if (window.event) keycode = window.event.keyCode;
	else if (e) keycode = e.which;
	else return true;

	if (keycode == 13) {
	   eval(method);
	   return false;
	} else return true;
}

function replaceClass(id, oldClass, newClass) {
	$("#"+id).removeClass(oldClass);
	$("#"+id).addClass(newClass);
}

function setCancelAccountBtn() {
	var status = eval($("#agree").attr("checked"));
	if (!status) {
		$("#btnSubmit").attr("disabled", "disabled");
		$("#btnSubmit").css("background-color", "#CCCCCC");
	} else {
		$("#btnSubmit").attr("disabled", "");
		$("#btnSubmit").css("background-color", "#FFCCCC");
	}
}

function highLightCell(tableID, focusColor, nofocusColor) {
	$(function(){
		var cells=$(tableID).find('td');
		$.each(cells, function(index, cell){
						cell.onmouseover = function(){this.style.backgroundColor = focusColor;}
						cell.onmouseout = function() {this.style.backgroundColor = nofocusColor;}
		});
	});
}

function goToSignUp() {

	if (($("#fname").val()=="")) {
		alert("Please enter your first name");
		return;
	}

	if (($("#lname").val()=="")) {
		alert("Please enter your last name");
		return;
	}

	if (($("#email").val()=="")) {
		alert("Please enter your email");
		return;
	}

	if (!is_valid_email($("#email").val())) {
		alert("Please enter a valid email");
		return;
	}
	window.location = URL+"signup/"+$("#fname").val()+"/"+$("#lname").val()+"/"+$("#email").val();
}

function goToRedeemFooter()
{
	window.location = URL+"redeem/"+$("#phonenumberGifterFooter").val();
}


function is_valid_email (email) {
	return /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/.test(email);
}

//20100728: mayank to modify the function to not accept whitespaces, search gift text and find a gift... text.
function doSearchGifts()
{
    var searchtext  = $("#phraseSearch").val();
    searchtext      = $.trim(searchtext);
    
    if(searchtext == '' || searchtext == 'search giiv' || searchtext == 'find a gift...')
    {
        //alert('Please enter some text.');
        return false;
    }
    else
        window.location = URL+"search/"+$("#phraseSearch").val();
}

function doRememberMe() {
	if ($("#remember").attr("checked")==true) {
		$("#remember").attr("checked", false);
		$("#rememberImg").attr("src", URL+"images/icons/remember-off.jpg");
	} else {
		$("#remember").attr("checked", true);
		$("#rememberImg").attr("src", URL+"images/icons/remember-on.jpg");
	}
}

function isValidPhone(num){
	num = num.replace(/[^0-9]/g, "");

	if(isNaN(num)) return false;
	if(num.length != 10) return false;

	return num;
}

/*  FUNCTION NEGRADA    */
function retailer_back_sidebar(img)
{
    $(".ColB").css({
        background: 'url('+img+'_back.png) no-repeat'
        
    });
}

function retailer_back_header(img)
{
    $("#retailer_header").css({
        background: 'url('+img+'_back.png) no-repeat',
        marginBottom: '15px'
    });
}
/*
function PartnersCarousel(){
    $(".PartnersCarousel").html;
}
*/

//20100803: mayank to write this function for autoadvance the text box when its maxlength reached.
function autoAdvanceTextBox(field,nextFieldID)
{
    if(field.value.length >= field.maxLength)
        document.getElementById(nextFieldID).focus();
}

//20100803: mayank to write this function for remove the text highlighting with remove backgroundcolor.
function removehighlighling(field,highlightID)
{
    if(typeof(highlightID) == 'undefined' || highlightID == '')
        highlightID = false;
    $(field).css('background-color', '');
    if(highlightID)
          $("#"+highlightID).hide();
    }

/**
 *  @Author: Mayank Gupta.
 *  @Desc: function to remove the all whitespaces with \t tab, \r carriage return and new lines.
 *  @Param: String (data) which we want to trimmed.
 *  @return: Trimmed string.
 */
function alltrim(str)
{
	if(str == undefined) {
		return '';
	} else {
    	return str.replace(/^\s+|\s+$/g, '');
	}
}

/**
 * @author: Mayank Gupta 20100818.
 * @desc: This function is used to revert back the text of look up your gift.
 * @param: string field is the ID of input control, string highlightID ID of input control on which we do operations.
 * @return: remove background with alter the text.
 */
function alterTexthighlight(field, highlightID)
{
    if(typeof(highlightID) == 'undefined' || highlightID == '')
        highlightID = false;
    $(field).css('background-color', '');
    if(highlightID)
    {
        $("#"+highlightID).css({"color":"","font-family":"","font-size":"","font-weight":""});
        $("#"+highlightID).html('Did you receive a gift from someone?<br />You can look it up by entering your mobile number.');
    }
}

