﻿function getRegisterUrl() {
    var url = '<%=ConfigurationManager.AppSettings["regUrl"].ToString() %>'
    alert(url);
    return url;
}

var FlashBuilder = {
    fnPrintFlash: function(sFileURL, nWidth, nHeight, id) {
        try { document.write(this.fnGetFlash(sFileURL, nWidth, nHeight, id)); }
        catch (e) { alert('Error loading script:\n' + e.message); }
    },
    fnGetFlash: function(sFileURL, nWidth, nHeight, id) {
        var RetValue = "";
        if (window.ActiveXObject)
            RetValue += '<object type="application/x-shockwave-flash"' + ((id && id != '') ? ' id="' + id + '"' : '') + ' width="' + nWidth + '" height="' + nHeight + '">';
        else
            RetValue += '<object' + ((id && id != '') ? ' id="' + id + '"' : '') + ' width="' + nWidth + '" height="' + nHeight + '" data="' + sFileURL + '">';
        RetValue += '<param name="movie" value="' + sFileURL + '">';
        document.write('<param name="quality" value="high">');
        if (id && id != '')
            RetValue += '<param name="scale" value="exactfit">';
        RetValue += '<param name="flashvars" value="movie=flash/movie1.flv"/>';
        RetValue += '<param name="wmode" value="transparent">';
        RetValue += '<embed type="application/x-shockwave-flash" wmode="transparent" ';
        RetValue += 'width="' + nWidth + '" height="' + nHeight + '" src="' + sFileURL + '"/>';
        RetValue += '</object>';
        return RetValue;
    }
}

var FormProcessor = {
	acceptTerms: true,
	defaltState: true,
        defaultRegister: "http://www.vort1.net/Campaign",
	defaultHost: "http://vort1.net/system",
	usHost: "http://www.vort1.net",
	ukHost: "http://Media-SB.com/Test",
	ilHost: "http://Media-SB.co.il",
	defaultArray: new Array(),
	defaultCID: 1,
	statHandlerURL: "http://www.vort1.net/xlogger",
	statIsraelHandlerURL: "http://www.media-sb.co.il/xlogger",
	startProcess: function () {

		this.adjustFormContainer();
		this.setValidation();
		this.clearFormField('txtEmail', 'txtFirstName', 'txtLastName', 'txtPassword');
	},
	clearFormField: function () {
		for (var i = 0; i < arguments.length; i++) {
			$('#' + arguments[i]).click(function () {
				if (FormProcessor.isDefaultState(this)) {
					$(this).val('');
					$(this).removeClass("defaultState");
					$(this).addClass("defaultStateFoc");

				}
				else {
					//$(this).removeClass("defaultStateFoc");
					//$(this).addClass("defaultState");
				}
			});
		}
	},
	setValidation: function () {
		$('#aspnetForm').submit(function () {
			if (!$('#chkAccept').attr('checked') || !FormProcessor.acceptTerms) {
				alert('Please check the terms of use check box in order to continue');
				return false;
			}
			if (!FormProcessor.checkFields()) {
				alert('All fields are required. Please fill in the missing data.');
				return false;
			}
			if (!FormProcessor.validEmail()) {
				$('#txtEmail').select().focus();
				alert('The email format is not valid.\nPlease insert an email address (example: email@company.com)');
				return false;
			}
			FormProcessor.defaultHost = FormProcessor[$('#selRegion').val()];
			//FormProcessor.defaultHost = eval("FormProcessor." + $('#selRegion').val());
			$('#hidCID').val(FormProcessor.getCID());
			//this.action = getRegisterUr(); // FormProcessor.defaultHost + "/Campaign/Register.aspx";
			//debugger;
			this.action = FormProcessor.defaultHost + "/Campaign/Register.aspx";
		});
	},
	validEmail: function () {
		var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
		return re.test($('#txtEmail').val());
	},
	checkFields: function () {
		return this.checkValue('txtEmail', '', 'Email') &&
            this.checkValue('txtFirstName', '', 'First Name') &&
            this.checkValue('txtLastName', '', 'Last Name') &&
            this.checkValue('txtPassword', '', 'Password') &&
            this.checkValue('selRegion', '0')
	},
	checkValue: function () {
		var retValue = true;
		for (var i = 1; i < arguments.length; i++) {
			if (arguments[i] == $('#' + arguments[0]).val()) {
				retValue = false;
				break;
			}
		}
		return retValue;
	},
	adjustFormContainer: function () {
		if ($.browser.msie) {
			$('.formContainer').css('padding-top', '70px');
			$('#popup_tryit').toggleClass('popup_tryit_IE');
			$('#popup_40').toggleClass('popup_40_IE');
			$('#popup_bottom_logo').toggleClass('popup_bottom_logo_IE');
			$('#h1_1').css('top', '20px');
			$('#h1_2').css('top', '80px');
			$('#h2_1').css('top', '180px');
			$('#h2_2').css('top', '220px');
			$('#h2_3').css('top', '300px');
			$('#h2_4').css('top', '340px');
			$('#loop').css('top', '60px');
			$('#h3_1').css('top', '30px');
		} else {
			$('#popup_tryit').toggleClass('popup_tryit_FF');
			$('#popup_40').toggleClass('popup_40_FF');
			$('#popup_bottom_logo').toggleClass('popup_bottom_logo_FF');
			$('#h1_1').css('top', '0px');
			$('#h1_2').css('top', '60px');
			$('#h2_1').css('top', '160px');
			$('#h2_2').css('top', '200px');
			$('#h2_3').css('top', '280px');
			$('#h2_4').css('top', '315px');
			$('#loop').css('top', '60px');
			$('#h3_1').css('top', '10px');
		}
	},
	openTermsPopup: function () {
		this.acceptTerms = true;
		$('#chkAccept').attr('disabled', false);
		window.open('http://vort1.net/System/Campaign/terms.htm', '', 'width=700,height=600,scrollbars=1');
	},
	goLogin: function () {
		if (this.defaultHost != "")
			window.location = this.defaultHost;
		else
			alert("You must select a hosting server in order to login");
	},
	goPopup2: function () {
		window.location = "/Home.aspx" + document.location.search;
	},
	goHome: function () {
		window.open('/default.htm');
	},
	restoreDefault: function (field) {
		for (var i = 0; i < this.defaultArray.length; i++) {
			if (field.id == this.defaultArray[i].id) {
				if (field.value == "") {
					field.value = this.defaultArray[i].value;
					$(field).removeClass("defaultStateFoc");
					$(field).addClass("defaultState");
				} else {
					this.className = "changedState";
				}
				break;
			}
		}
	},
	isDefaultState: function (field) {
		var retValue = false, test;
		for (var i = 0; i < this.defaultArray.length; i++) {
			test = this.defaultArray[i];
			if (field.id == test.id && field.value == test.value) {
				retValue = true;
				break;
			}
		}
		return retValue;
	},
	getCID: function () {
		var retValue = this.defaultCID;
		try {
			if (document.location.search != "") {
				var arr1 = document.location.search.split('=');
				retValue = parseInt(arr1[1]);
			}
			else {
				var cid = this.getCookieValue("cid");
				if (cid != "") retValue = cid;
			}
		}
		catch (e) { }
		this.setCookieValue("cid", retValue, 100 * 365);
		return retValue;
	},
	setEventTracking: function (eventID) {
		//debugger;
		var $img, src;
		
		if ($('#selRegion').val() == "ilHost"){
			src = this.statIsraelHandlerURL + '/?action=' + eventID + '&cid=' + this.getCID();
		}
		else{
			src = this.statHandlerURL + '/?action=' + eventID + '&cid=' + this.getCID();
		}
		
		$img = $(document.createElement('img'));
		
		$img.attr('src', src).css('display', 'none');
		$('body').append($img);
	},
	getActionID: function () {
		var loc, retValue = 1;
		loc = document.location.href.toLowerCase();
		if (loc.indexOf('/campaign1/subscribe.html') != -1)
			retValue = 2;
		else if (loc.indexOf('/campaign1') != -1)
			retValue = 1;
		return retValue;
	},
	getCookieValue: function (cookieName) {
		var splitChar = ";";
		var str1, str2, arr1, arr2, retValue = "";
		str1 = new String(document.cookie);
		arr1 = str1.split(splitChar);
		for (i = 0; i <= arr1.length - 1; i++) {
			str2 = new String(arr1[i]);
			if (str2.indexOf(cookieName) != -1) {
				arr2 = str2.split("=");
				if (arr2.length == 2) retValue = arr2[1];
				break;
			}
		}
		return retValue;
	},
	setCookieValue: function (cookieName, newValue, expiredays) {
		var exdate = new Date();
		exdate.setDate(exdate.getDate() + expiredays);

		var splitChar = ";";
		var cookString = new String(document.cookie);
		var oldValue = this.getCookieValue(cookieName, splitChar);
		if (oldValue != "") {
			var findString = cookieName + "=" + oldValue;
			cookString = cookString.replace(findString, (cookieName + "=" + newValue));
			document.cookie = cookString + ";expires=" + exdate.toGMTString();
		} else {
			document.cookie = cookieName + "=" + newValue + ";expires=" + exdate.toGMTString();
		}
	},
	setWindow: function () {
		try {
			//var w = 758, h = 745;
			var w = 1080, h = 860;
			window.resizeTo(w, h);
			window.moveTo((screen.availWidth - w) / 2, (screen.availHeight - h) / 2);
		}
		catch (e) { }
	}
}

var EventType = {
    Defult: 1,
    HomePage: 11,
    Popup1: 1,
    Popup2: 2,
    PlayMovie: 12
}


