﻿if (typeof vcc != "object")	vcc = {};

$(window).ready(function() {
	vcc.fixIePng("#content");
});

function getScrollXY() { 
	var scrOfX = 0, scrOfY = 0; 
	if( typeof( window.pageYOffset ) == 'number' ) { 
		//Netscape compliant 
		scrOfY = window.pageYOffset; 
		scrOfX = window.pageXOffset; 
	} else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) { 
		//DOM compliant 
		scrOfY = document.body.scrollTop; 
		scrOfX = document.body.scrollLeft; 
	} else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) { 
		//IE6 standards compliant mode 
		scrOfY = document.documentElement.scrollTop; 
		scrOfX = document.documentElement.scrollLeft; 
	} 
	return {X:scrOfX, Y:scrOfY}; 
} 

function getWindowSize() { 
	var myWidth = 0, myHeight = 0; 
	if( typeof( window.innerWidth ) == 'number' ) { 
		//Non-IE 
		myWidth = window.innerWidth; 
		myHeight = window.innerHeight; 
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) { 
		//IE 6+ in 'standards compliant mode' 
		myWidth = document.documentElement.clientWidth; 
		myHeight = document.documentElement.clientHeight; 
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) { 
		//IE 4 compatible 
		myWidth = document.body.clientWidth; 
		myHeight = document.body.clientHeight; 
	} 
	return{X:myWidth, Y:myHeight} 
}

/*
 * Returns the value of a query string parameter, or null if it does not exist
 */
vcc.getParameter = function(parameterName) {
    var queryString = window.location.search;
    if (queryString.length > 0 && parameterName.length > 0) {
        if (parameterName.substring(parameterName.length - 1) != "=")
            parameterName += "=";
        var start = queryString.indexOf(parameterName);
        if (start != -1) {
            start += parameterName.length;
            var end = queryString.indexOf("&", start);
            if (end == -1)
                end = queryString.length;
            return decodeURIComponent(queryString.substring(start, end));
        }
    }
    return null;
}

vcc.center = function(elm, bHorizontally, bVertically) {
	if (elm == null)
		return;
	var windowDim = getWindowSize(); 
	var popupHeight = $(elm).height(); 
	var popupWidth = $(elm).outerWidth(); 
	//alert(popupWidth);
	var scroll = getScrollXY(); 
	//centering 
	if (bHorizontally) {
		$(elm).css({ 
			"position": "absolute",
			"left": windowDim.X/2-popupWidth/2 + scroll.X 
		});
	}
	if (bVertically) {
		$(elm).css({ 
			"position": "absolute", 
			"top": windowDim.Y/2-popupHeight/2 + scroll.Y-15
		});
	}
	
}

vcc.flashLightBoxWidth = null;
vcc.flashLightBoxHeight = null;
vcc.flashVarsLightBox = null;
vcc.centerLightBoxVertically = false;

vcc.clone = function(obj) {
	if(obj == null || typeof(obj) != 'object')
        return obj;
	var newObj = new obj.constructor()
	for (var key in obj) {
		newObj[key] = vcc.clone(obj[key]);
	}
	return newObj;
}

vcc.flashLightbox = function(sUrl, iWidth, iHeight) {
	vcc.flashVarsLightBox = vcc.clone(vcc.flashVars);
	vcc.flashVarsLightBox.flashobjectid = "flashLightBoxContainer";
	if (sUrl.indexOf(".swf") > -1) {
		//Regular static flash, load it with swf object
		vcc.showOverlay(vcc.hideOverlay, "<div id=\"flashLightBoxContainer\" style=\"width: " + iWidth + "px;height: \"" + iHeight + "px;\"></div>", iWidth, iHeight);
		swfobject.embedSWF(sUrl, "flashLightBoxContainer", iWidth, iHeight, "9.0.0", "/_layouts/VolvoCars.SharePoint.Features.Site3/swf/expressInstall.swf", vcc.flashVarsLightBox, { wmode: "window", allowscriptaccess: "always", allowfullscreen: "true", bgcolor: "#000000"  }, { id: "flashLightBoxContainer", "class": "flash" } );
	} else {
		//Flashcontent page. Get the swf with content url and settings from the page using AJAX
		//If width and height has been passed to the function, use it instead of the dimensions in the aspx page
		vcc.flashLightBoxWidth = iWidth;
		vcc.flashLightBoxHeight = iHeight;
		if (sUrl.indexOf("?") > -1) {			
			var params = sUrl.substring(sUrl.indexOf("?"));
			params.replace(
				new RegExp("([^?=&]+)(=([^&]*))?", "g"),
				function($0, $1, $2, $3) {
					vcc.flashVarsLightBox[$1] = $3;
				}
			);			
			sUrl = sUrl.substring(0, sUrl.indexOf("?"));			
		}		
		$.getJSON(sUrl + "?json=true", function(data){
			if (vcc.flashLightBoxWidth != null && vcc.flashLightBoxWidth != 0 && vcc.flashLightBoxWidth != "") {
				vcc.showOverlay(vcc.hideOverlay, "<div id=\"flashLightBoxContainer\" style=\"width: " + vcc.flashLightBoxWidth + "px;height: \"" + vcc.flashLightBoxHeight + "px;\"></div>", vcc.flashLightBoxWidth, vcc.flashLightBoxHeight);
				swfobject.embedSWF(data.url, "flashLightBoxContainer", vcc.flashLightBoxWidth, vcc.flashLightBoxHeight, data.version, "/_layouts/VolvoCars.SharePoint.Features.Site3/swf/expressInstall.swf", vcc.flashVarsLightBox, { wmode: data.wmode, allowscriptaccess: "always", allowfullscreen: "true", bgcolor: data.bgcolor  }, { id: "flashLightBoxContainer", "class": "flash" } );
			} else {
				vcc.showOverlay(vcc.hideOverlay, "<div id=\"flashLightBoxContainer\" style=\"width: " + data.width + "px;height: \"" + data.height + "px;\"></div>", data.width, data.height);
				swfobject.embedSWF(data.url, "flashLightBoxContainer", data.width, data.height, data.version, "/_layouts/VolvoCars.SharePoint.Features.Site3/swf/expressInstall.swf", vcc.flashVarsLightBox, { wmode: data.wmode, allowscriptaccess: "always", allowfullscreen: "true", bgcolor: data.bgcolor  }, { id: "flashLightBoxContainer", "class": "flash" } );
			}
		});
	}
	
}

vcc.showOverlay = function(oOnClickFunction, sOverlayHtml, iOverlayWidth, iOverlayHeight) {
	var oOverlay = document.getElementById("overlay");
	if (oOverlay == null) {
		oOverlay = document.createElement("div")
		oOverlay.style.display.opacity = 0;
		oOverlay.id = "overlay";
		document.body.appendChild(oOverlay);
		oOverlay.onclick = oOnClickFunction;
		//$("#overlay").hide();	
	}
		
	vcc.resizeOverlay();
	
	$("#overlay").fadeTo(0, 0.7);
	$("#overlay").show();
	
	if (sOverlayHtml == null)
		return;
		
	var oOverlayContainer = document.getElementById("overlay-container");
	if (oOverlayContainer == null) {
		oOverlayContainer = document.createElement("div");
		oOverlayContainer.id = "overlay-container";
		document.body.appendChild(oOverlayContainer);
	}
	
	oOverlayContainer.style.width = (iOverlayWidth) ? iOverlayWidth + "px" : "auto";
	oOverlayContainer.style.height = (iOverlayHeight) ? iOverlayHeight + "px" : "auto";
	
	oOverlayContainer.innerHTML = sOverlayHtml + "<a href=\"#\" id=\"overlay-closebutton\" onclick=\"vcc.hideOverlay();return false;\"></a>";
	$("#overlay-container").corner("3px cc:#4c4c4c sc:#fff");
	$("#overlay-container").show();
	vcc.center(oOverlayContainer, true, vcc.centerLightBoxVertically);
	
	$(window).bind("resize", vcc.handleOverlayWhenResized);
}

vcc.handleOverlayWhenResized = function() {
	vcc.resizeOverlay();
	vcc.center(document.getElementById("overlay-container"), true, vcc.centerLightBoxVertically);
}

//Updates the light box dimensions

vcc.updateOverlaySize = function(iOverlayWidth, iOverlayHeight) {
	var oFlashLightBoxContainer = document.getElementById("flashLightBoxContainer");
	if (oFlashLightBoxContainer) {
		oFlashLightBoxContainer.style.width = (iOverlayWidth) + "px";
		oFlashLightBoxContainer.style.height = (iOverlayHeight) + "px";
	}
	
	var oOverlayContainer = document.getElementById("overlay-container");
	if (oOverlayContainer) {
		oOverlayContainer.style.width = (iOverlayWidth) + "px";
		oOverlayContainer.style.height = (iOverlayHeight) + "px";
		vcc.center(oOverlayContainer, true, vcc.centerLightBoxVertically);
	}	
}

vcc.resizeOverlay = function() {
	var oOverlay = document.getElementById("overlay");
	if (oOverlay == null)
		return;
	var arrayPageSize = vcc.getPageSize();
	oOverlay.style.width = arrayPageSize[0] + "px";
	oOverlay.style.height = arrayPageSize[1] + "px";
}

vcc.hideOverlay = function() {
	$(window).unbind("resize", vcc.handleOverlayWhenResized);
	$("#overlay").fadeOut(500);
	if ($("#overlay-container #flashLightBoxContainer").length > 0) {
		swfobject.removeSWF("flashLightBoxContainer");
	} else if ($("#overlay-container #large").length > 0) {
		swfobject.removeSWF("large");
	}
	$("#overlay-container").replaceWith("<div id=\"overlay-container\"></div>");
	$("#overlay-container").hide();
	vcc.centerLightBoxVertically = false;
}

vcc.getPageSize = function() {	
	var xScroll, yScroll;	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = window.innerWidth + window.scrollMaxX;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else {
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}	
	var windowWidth, windowHeight;

	if (self.innerHeight) {	// all except Explorer
		if(document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth; 
		} else {
			windowWidth = self.innerWidth;
		}
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}
	
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	if(xScroll < windowWidth){	
		pageWidth = xScroll;		
	} else {
		pageWidth = windowWidth;
	}

	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}

vcc.centerFlash = function(sFlashId, iWidth, iHeight) {	
	var oFlashObject = $("#" + sFlashId);	
	var oWindow = $(window);
	
	var x = (oWindow.width() / 2) - (iWidth / 2);
    var y = (oWindow.height() / 2) - (iHeight / 2);
    
    x = parseInt(x + oWindow.scrollLeft());
    y = parseInt(y + oWindow.scrollTop());
	
    var sContainerId = sFlashId + "_centerContainer";
    
    if (document.getElementById(sContainerId) == null) {
		$("form").append("<div id=\"" + sContainerId + "\"></div>");
		oFlashObject.remove().appendTo("#" + sContainerId);
		oWindow.bind('resize', function() {
			vcc.centerFlash(sFlashId, iWidth, iHeight);
		});	
    }    
	
	$("#" + sContainerId).css( {
		"position": "absolute",
		"top": y,
		"left": x,
		"z-index": 30000
		});		
}

vcc.fullscreenFlash = function(sFlashId) {
	var oFlashObject = $("#" + sFlashId);	
	var sContainerId = sFlashId + "_fullscreenContainer";
	var oContainer = document.getElementById(sContainerId);
	var oWindow = $(window);
	
	if (oContainer == null) {
		$("form").append("<div id=\"" + sContainerId + "\"></div>");
		oContainer = document.getElementById(sContainerId);
		$(oContainer).css( {
			"position": "absolute",
			"top": 0,
			"left": 0
		});
		oFlashObject.remove().appendTo("#" + sContainerId);
		oWindow.bind('resize', function() {
			vcc.fullscreenFlash(sFlashId);
		});	
    }    
    
    $(oContainer).css( {
		"width": oWindow.width(),
		"height": oWindow.height()
    });
}

vcc.openWindow = function(sURL, sName, sOptions, bDoNotReturnWindow) {
	if (!sOptions) sOptions = "location=yes,resizable=yes,scrollbars=yes,status=yes,toolbar=yes,";
	else {
		//parse the sOptions variable to get width and height
		var aWidth = sOptions.match(/width=[0-9]+/i);
		var aHeight = sOptions.match(/height=[0-9]+/i);
		if (aWidth != null) {
			//Center window horizontally
			var iWidth = aWidth[0].substring(aWidth[0].lastIndexOf("=") + 1);
			var x = (screen.width - iWidth) / 2;
			x = (x<0) ? 0 : x
			sOptions += ",left=" + x;
		}
		if (aHeight != null) {
			//Center window vertically
			var iHeight = aHeight[0].substring(aHeight[0].lastIndexOf("=") + 1);
			var y = (screen.height - iHeight) / 2;
			y = (y<0) ? 0 : y
			sOptions += ",top=" + y;
		}
	}
	var popup = window.open(sURL,sName,sOptions);
	if (!bDoNotReturnWindow)
		return popup;
}

vcc.trackEvent = function(sUrl, sTitle, sGroup, sSubGroup) {
	if (typeof(pageTracker) == "object") {
		//Google analytics
		var sGoogleUrl = sUrl;
		if (sGoogleUrl.indexOf("/") != 0)
			sGoogleUrl = "/" + sGoogleUrl;		
		sGoogleUrl = document.location.pathname + sGoogleUrl;		
		pageTracker._trackPageview(sGoogleUrl);
	}	
}

vcc.trackCampaignEvent = function(category, action, optional_label, optional_value) {
	if (typeof(pageTracker) == "object") {
		pageTracker._trackEvent(category, action, optional_label, optional_value);
	}
}

//Loops through all links on the page, and attaches an onclick statistics call for external ones
vcc.initExternalTracking = function() {
	if (typeof(pageTracker) != "object")
		return;
	pageTracker._setAllowLinker(true);
	var sDomain = document.location.hostname.toLowerCase();
	$.each($("#content a"), function() {
		var sLinkUrl = this.href.toLowerCase()
		if (sLinkUrl.indexOf("http") > -1 && sLinkUrl.indexOf(sDomain) == -1) {
			$(this).click(function() {
				pageTracker._link(this.href);
				return false;
			});
		}
	});
}



vcc.flashObj = function(sUrl, iWidth, iHeight, sRequiredVersion, oParams, oAttributes) {
	this.url = sUrl;
	this.width = iWidth;
	this.height = iHeight;
	this.requiredVersion = sRequiredVersion;
	this.params = oParams;
	this.attributes = oAttributes;
}

//Searches the vcc.aModels array and returns the first model that matches the key.
vcc.getModel = function(key) {
	key = key.toLowerCase();
	for (var i = 0; i < vcc.aModels.length; i++) {
		var oModel = vcc.aModels[i];
		if (oModel.ModelWebTitle.toLowerCase() == key || oModel.ModelWebName.toLowerCase() == key
			|| oModel.Name.toLowerCase() == key || oModel.ShortName.toLowerCase() == key
			|| oModel.ModelCode.toLowerCase() == key) {
			return oModel;
		}
	}
	return null;
}

vcc.fixIePng = function(sElementSelector) {
	var ie55 = (navigator.appName == "Microsoft Internet Explorer" && parseInt(navigator.appVersion) == 4 && navigator.appVersion.indexOf("MSIE 5.5") != -1);
	var ie6 = (navigator.appName == "Microsoft Internet Explorer" && parseInt(navigator.appVersion) == 4 && navigator.appVersion.indexOf("MSIE 6.0") != -1);

	if (jQuery.browser.msie && (ie55 || ie6)) {
		//Images
		if (sElementSelector == null)
			sElementSelector = "#content";
		$("img[src$=.png]", $(sElementSelector)).each(function() {
			jQuery(this).attr('width',jQuery(this).width());
			jQuery(this).attr('height',jQuery(this).height());

			var prevStyle = '';
			var strNewHTML = '';
			var imgId = (jQuery(this).attr('id')) ? 'id="' + jQuery(this).attr('id') + '" ' : '';
			var imgClass = (jQuery(this).attr('class')) ? 'class="' + jQuery(this).attr('class') + '" ' : '';
			var imgTitle = (jQuery(this).attr('title')) ? 'title="' + jQuery(this).attr('title') + '" ' : '';
			var imgAlt = (jQuery(this).attr('alt')) ? 'alt="' + jQuery(this).attr('alt') + '" ' : '';
			var imgAlign = (jQuery(this).attr('align')) ? 'float:' + jQuery(this).attr('align') + ';' : '';
			var imgHand = (jQuery(this).parent().attr('href')) ? 'cursor:hand;' : '';
			if (this.style.border) {
				prevStyle += 'border:'+this.style.border+';';
				this.style.border = '';
			}
			if (this.style.padding) {
				prevStyle += 'padding:'+this.style.padding+';';
				this.style.padding = '';
			}
			if (this.style.margin) {
				prevStyle += 'margin:'+this.style.margin+';';
				this.style.margin = '';
			}
			var imgStyle = (this.style.cssText);

			strNewHTML += '<span '+imgId+imgClass+imgTitle+imgAlt;
			strNewHTML += 'style="position:relative;white-space:pre-line;display:inline-block;background:transparent;'+imgAlign+imgHand;
			strNewHTML += 'width:' + jQuery(this).width() + 'px;' + 'height:' + jQuery(this).height() + 'px;';
			strNewHTML += 'filter:progid:DXImageTransform.Microsoft.AlphaImageLoader' + '(src=\'' + jQuery(this).attr('src') + '\', sizingMethod=\'scale\');';
			strNewHTML += imgStyle+'"></span>';
			if (prevStyle != ''){
				strNewHTML = '<span style="position:relative;display:inline-block;'+prevStyle+imgHand+'width:' + jQuery(this).width() + 'px;' + 'height:' + jQuery(this).height() + 'px;'+'">' + strNewHTML + '</span>';
			}
			//alert(strNewHTML);
			jQuery(this).hide();
			jQuery(this).after(strNewHTML);
		});		
		// Background-images
		/*if (vcc.pngBgsToFix) {
			var arAll = document.getElementsByTagName("*");
			for (var i=0; i<arAll.length; i++) {
				if (arAll[i] && arAll[i].currentStyle && arAll[i].currentStyle.backgroundImage && arAll[i].currentStyle.backgroundImage.indexOf("url(") > -1) {
					var sUrl = arAll[i].currentStyle.backgroundImage.substring(5, arAll[i].currentStyle.backgroundImage.length - 2);
					if (sUrl.substring(sUrl.length-3, sUrl.length) == "png") {
						for (var j=0; j<vcc.pngBgsToFix.length; j++) {
							if (sUrl.indexOf(vcc.pngBgsToFix[j]) > -1) {
								arAll[i].style.backgroundImage = "none";
								arAll[i].style.filter += "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + sUrl + "', sizingMethod='scale')";
							}
						}
					}
				}
			}
		}*/
	}
}

/* Send to friend */
if (vcc.sendtofriend == null) 
    vcc.sendtofriend = {};

vcc.sendtofriend.showLoadingFrame = function() {
    // Disable validation of form data
    vcc.sendtofriend.validateForm = false;
    // Hide close icon
    $("#email-form").find("img:first").hide();
    // Hide e-mail form
    $("#email-content-inner").hide();
    // Show loading frame
    $("#email-loading-frame").show();
}

vcc.sendtofriend.showInfoFrame = function() {
    // Get status message
    var message = $('#email-content-inner').find('input[type="hidden"]:first').val();
    // Set status message
    $("span", "#email-info-frame").eq(0).text(message);
    // Hide loading frame
    $("#email-loading-frame").hide();
    // Show close icon
    $("#email-form").find("img:first").show();
    // Show error frame
    $("#email-info-frame").show();
}

vcc.sendtofriend.showEmailFrame = function() {
    // Clear error message
    $("span", "#email-info-frame").eq(0).text("");
    // Hide error frame
    $("#email-info-frame").hide();
    // Show e-mail form
    $("#email-content-inner").show();
    // enable validation of form data
    vcc.sendtofriend.validateForm = true;
}

vcc.sendtofriend.validateForm = false;
vcc.sendtofriend.openForm = function() {
    // Show e-mail form
    $("#email-form").show();

    // Get element positions
    var spos = $("#sendtofriend").offset();
    var swidth = $("#sendtofriend").width();
    var fpos = $("#footer").offset();
    var fleft = $get("footer").offsetLeft;
    var t1 = $("#sendtofriend").offset().top;
    var h1 = $("#email-form").height();

    // Calculate e-mail form position
    var left = spos.left + swidth - fleft - fpos.left - $("#email-form").width() + 19;
    var top = t1 - h1;

    // Position e-mail form
    $("#email-form").css({ "left": left + "px", "top": top + "px" });

    // enable validation of form data
    vcc.sendtofriend.validateForm = true;
}

vcc.sendtofriend.closeForm = function() {
    // Disable validation of form data
    vcc.sendtofriend.validateForm = false;
    
    // Reset input fields
    $("#email-content-inner .textarea").val("");
    $("#email-content-inner .textbox").each(function() {
        $(this).val("");
    });
    // Reset frames & icon
    $("#email-form").find("img:first").show();
    $("#email-content-inner").show();
    $("#email-loading-frame").hide();
    $("#email-info-frame").hide();
    $("#email-form").hide();
}

vcc.sendtofriend.sFlashID = null;
vcc.sendtofriend.fnCallback = null;
vcc.sendtofriend.sendEmail = function(sXml, sFlashID, fnCallback) {
    // Set callback values
    vcc.sendtofriend.fnCallback = fnCallback;
    vcc.sendtofriend.sFlashID = sFlashID;
    // Get hidden XML element
    var element = $('#email-function').find('input[type="hidden"]:first');
    if (typeof element === "object") {
        // Set element value
        element.val(encodeURIComponent(sXml));
        // Get unique ID for postback
        var eventTarget = element.attr("name");
        // Perform postback to send e-mail
        WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions(
            eventTarget, // Event target
            "",          // Event argument
            false,       // Perform validation
            "",          // Validation group
            "",          // Action URL
            false,       // Track focus
            true         // Client submit
        ));
    }
}

vcc.sendtofriend.sendEmailFinished = function() {
    // Get status message
    var status = $('input[type="hidden"]', '#email-function').eq(1).val();
    // Check registered parameters
    if (typeof vcc.sendtofriend.fnCallback == "string") { // Assume vcc.sendtofriend.fnCallback represents a flash movie function
        // Verify the flash ID variable
        if (typeof vcc.sendtofriend.sFlashID == "string") {
            // Try to call the flash function
            try {
                // Get flash movie on which to call the function on
                var flash = $get(vcc.sendtofriend.sFlashID);
                // Create javascript to call flash function
                var objectFunctionCall = "flash." + vcc.sendtofriend.fnCallback + "(\"" + status + "\")";
                // Execute javascript
                eval(objectFunctionCall);
            }
            catch (e) { }
        }
    }
    else if (typeof vcc.sendtofriend.fnCallback == "function") { // Assume vcc.sendtofriend.fnCallback represents a javascript function
        try {
            // Try to call the javascript function
            vcc.sendtofriend.fnCallback(status);
        }
        catch (e) { }
    }
}

vcc.sendtofriend.validateEmailForm = function() {
    if (vcc.sendtofriend.validateForm == true) {
        if ($("#email-content-inner").find(".invalid").length > 0) {
            $("#email-content-inner span.error").addClass("visible");
        }
        else {
            $("#email-content-inner span.error").removeClass("visible");
        }
    }
}

vcc.sendtofriend.validateText = function(source, args) {
    args.IsValid = true;

    if (vcc.sendtofriend.validateForm == true) {
        if (args.Value == "") {
            args.IsValid = false;
            $("#" + source.controltovalidate).parent().addClass("invalid");
        }
        else {
            $("#" + source.controltovalidate).parent().removeClass("invalid");
        }

        vcc.sendtofriend.validateEmailForm();
    }

    return args.IsValid;
}

vcc.sendtofriend.validateEmailAddress = function(source, args) {
    args.IsValid = true;

    if (vcc.sendtofriend.validateForm == true) {
        var filter = /^([a-zA-Z0-9_\.\-+*#])+@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,6})$/;
        if (args.Value == "") {
            args.IsValid = false;
            $("#" + source.controltovalidate).parent().addClass("invalid");
        }
        else if (!filter.test(args.Value)) {
            args.IsValid = false;
            $("#" + source.controltovalidate).parent().addClass("invalid");
        }
        else {
            $("#" + source.controltovalidate).parent().removeClass("invalid");
        }

        vcc.sendtofriend.validateEmailForm();
    }

    return args.IsValid;
}
