// JavaScript Document
var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		//alert(data[10].string.indexOf(data[10].subString));
		
		for (var i=0;i<data.length;i++)	{
			
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				
				var txt=new RegExp(data[i].subString,"g");
				
				var str = dataString.match(txt);
				//alert(i + " :: " + data[i].subString + " :: " + str);
			
				
				if (str!=null)				
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Chrome",
			identity: "Chrome"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		}	
		
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
BrowserDetect.init();


if(BrowserDetect.browser=="Explorer" && BrowserDetect.version==6)
{
	document.write('<link rel="stylesheet" type="text/css" href="css/style_e.css">');	
}
if(BrowserDetect.browser=="Explorer" && BrowserDetect.version==7)
{
	document.write('<link rel="stylesheet" type="text/css" href="css/style_e7.css">');
}
if(BrowserDetect.browser=="Explorer" && BrowserDetect.version==8)
{
	document.write('<link rel="stylesheet" type="text/css" href="css/style_e8.css">');
}
if(BrowserDetect.browser=="Safari")
{	
	document.write('<link rel="stylesheet" type="text/css" href="css/style_s.css">');	
}
if(BrowserDetect.browser=="Chrome")
{
	document.write('<link rel="stylesheet" type="text/css" href="css/style_gc.css">');
}
if(BrowserDetect.browser=="Chrome" && BrowserDetect.OS=="Windows")
{
	document.write('<link rel="stylesheet" type="text/css" href="css/style_gcWin.css">');
}
if(BrowserDetect.browser=="Firefox" && BrowserDetect.OS=="Windows")
{
	document.write('<link rel="stylesheet" type="text/css" href="css/style_fWin.css">');
}

function redirectTo(loc)
{
	window.location=loc;
}




function deleteCurRecord(string)
{
	if(typeof(string)=="undefined"){
		string="Are you sure you want to delete this attendee?";
	}
	if(confirm(string))
    {
		return true;
	}
	else
	{	
		return false;
	}
}

function deleteAllRecords()
{
	if(confirm('Are you sure you want to delete all recipients from the list?\n\nNote: This process cannot be reversed!'))
    {
		return true;
	}
	else
	{	
		return false;
	}
}

function deleteCurSponsor()
{
	if(confirm('Are you sure you want to delete this sponsor?'))
    {
		return true;
	}
	else
	{	
		return false;
	}
}


function deleteCurPlayer()
{
	if(confirm('Are you sure you want to delete these players?'))
    {
		return true;
	}
	else
	{	
		return false;
	}
}

function deleteAllSponsors()
{
	if(confirm('Are you sure you want to delete all sponsors from the list?\n\nNote: This process cannot be reversed!'))
    {
		return true;
	}
	else
	{	
		return false;
	}
}


function deleteAllPlayers()
{
	if(confirm('Are you sure you want to delete all players from the list?\n\nNote: This process cannot be reversed!'))
    {
		return true;
	}
	else
	{	
		return false;
	}
}

function warningSameMail()
{
	alert("Recipient already exists in the list.\n\nPlease, try with another e-mail address."); return false;
}

function displayImg(id)
{
	window.location = "?section=1&action=2&id=" + id;
}


function checkIsTested(id, obj, pre)
{
	switch(obj.checked)
	{
		case true:
		window.location=pre + "&test=" + id;
		break;
		
		case false:
		window.location=pre + "&untest=" + id;
		break;
	}
}

var $=jQuery.noConflict();

/*
* jQuery Easing v1.3 - http://gsgd.co.uk/sandbox/jquery/easing/
*
* Uses the built in easing capabilities added In jQuery 1.1
* to offer multiple easing options
*
* TERMS OF USE - jQuery Easing
* 
* Open source under the BSD License. 
* 
* Copyright Â© 2008 George McGinley Smith
* All rights reserved.
* 
* Redistribution and use in source and binary forms, with or without modification, 
* are permitted provided that the following conditions are met:
* 
* Redistributions of source code must retain the above copyright notice, this list of 
* conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this list 
* of conditions and the following disclaimer in the documentation and/or other materials 
* provided with the distribution.
* 
* Neither the name of the author nor the names of contributors may be used to endorse 
* or promote products derived from this software without specific prior written permission.
* 
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
*  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
*  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
*  GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
*  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 
* OF THE POSSIBILITY OF SUCH DAMAGE. 
*
*/

// t: current time, b: begInnIng value, c: change In value, d: duration
jQuery.easing['jswing'] = jQuery.easing['swing'];

jQuery.extend(jQuery.easing,
{
    def: 'easeOutQuad',
    swing: function (x, t, b, c, d) {
        //alert(jQuery.easing.default);
        return jQuery.easing[jQuery.easing.def](x, t, b, c, d);
    },
    easeInQuad: function (x, t, b, c, d) {
        return c * (t /= d) * t + b;
    },
    easeOutQuad: function (x, t, b, c, d) {
        return -c * (t /= d) * (t - 2) + b;
    },
    easeInOutQuad: function (x, t, b, c, d) {
        if ((t /= d / 2) < 1) return c / 2 * t * t + b;
        return -c / 2 * ((--t) * (t - 2) - 1) + b;
    },
    easeInCubic: function (x, t, b, c, d) {
        return c * (t /= d) * t * t + b;
    },
    easeOutCubic: function (x, t, b, c, d) {
        return c * ((t = t / d - 1) * t * t + 1) + b;
    },
    easeInOutCubic: function (x, t, b, c, d) {
        if ((t /= d / 2) < 1) return c / 2 * t * t * t + b;
        return c / 2 * ((t -= 2) * t * t + 2) + b;
    },
    easeInQuart: function (x, t, b, c, d) {
        return c * (t /= d) * t * t * t + b;
    },
    easeOutQuart: function (x, t, b, c, d) {
        return -c * ((t = t / d - 1) * t * t * t - 1) + b;
    },
    easeInOutQuart: function (x, t, b, c, d) {
        if ((t /= d / 2) < 1) return c / 2 * t * t * t * t + b;
        return -c / 2 * ((t -= 2) * t * t * t - 2) + b;
    },
    easeInQuint: function (x, t, b, c, d) {
        return c * (t /= d) * t * t * t * t + b;
    },
    easeOutQuint: function (x, t, b, c, d) {
        return c * ((t = t / d - 1) * t * t * t * t + 1) + b;
    },
    easeInOutQuint: function (x, t, b, c, d) {
        if ((t /= d / 2) < 1) return c / 2 * t * t * t * t * t + b;
        return c / 2 * ((t -= 2) * t * t * t * t + 2) + b;
    },
    easeInSine: function (x, t, b, c, d) {
        return -c * Math.cos(t / d * (Math.PI / 2)) + c + b;
    },
    easeOutSine: function (x, t, b, c, d) {
        return c * Math.sin(t / d * (Math.PI / 2)) + b;
    },
    easeInOutSine: function (x, t, b, c, d) {
        return -c / 2 * (Math.cos(Math.PI * t / d) - 1) + b;
    },
    easeInExpo: function (x, t, b, c, d) {
        return (t == 0) ? b : c * Math.pow(2, 10 * (t / d - 1)) + b;
    },
    easeOutExpo: function (x, t, b, c, d) {
        return (t == d) ? b + c : c * (-Math.pow(2, -10 * t / d) + 1) + b;
    },
    easeInOutExpo: function (x, t, b, c, d) {
        if (t == 0) return b;
        if (t == d) return b + c;
        if ((t /= d / 2) < 1) return c / 2 * Math.pow(2, 10 * (t - 1)) + b;
        return c / 2 * (-Math.pow(2, -10 * --t) + 2) + b;
    },
    easeInCirc: function (x, t, b, c, d) {
        return -c * (Math.sqrt(1 - (t /= d) * t) - 1) + b;
    },
    easeOutCirc: function (x, t, b, c, d) {
        return c * Math.sqrt(1 - (t = t / d - 1) * t) + b;
    },
    easeInOutCirc: function (x, t, b, c, d) {
        if ((t /= d / 2) < 1) return -c / 2 * (Math.sqrt(1 - t * t) - 1) + b;
        return c / 2 * (Math.sqrt(1 - (t -= 2) * t) + 1) + b;
    },
    easeInElastic: function (x, t, b, c, d) {
        var s = 1.70158; var p = 0; var a = c;
        if (t == 0) return b; if ((t /= d) == 1) return b + c; if (!p) p = d * .3;
        if (a < Math.abs(c)) { a = c; var s = p / 4; }
        else var s = p / (2 * Math.PI) * Math.asin(c / a);
        return -(a * Math.pow(2, 10 * (t -= 1)) * Math.sin((t * d - s) * (2 * Math.PI) / p)) + b;
    },
    easeOutElastic: function (x, t, b, c, d) {
        var s = 1.70158; var p = 0; var a = c;
        if (t == 0) return b; if ((t /= d) == 1) return b + c; if (!p) p = d * .3;
        if (a < Math.abs(c)) { a = c; var s = p / 4; }
        else var s = p / (2 * Math.PI) * Math.asin(c / a);
        return a * Math.pow(2, -10 * t) * Math.sin((t * d - s) * (2 * Math.PI) / p) + c + b;
    },
    easeInOutElastic: function (x, t, b, c, d) {
        var s = 1.70158; var p = 0; var a = c;
        if (t == 0) return b; if ((t /= d / 2) == 2) return b + c; if (!p) p = d * (.3 * 1.5);
        if (a < Math.abs(c)) { a = c; var s = p / 4; }
        else var s = p / (2 * Math.PI) * Math.asin(c / a);
        if (t < 1) return -.5 * (a * Math.pow(2, 10 * (t -= 1)) * Math.sin((t * d - s) * (2 * Math.PI) / p)) + b;
        return a * Math.pow(2, -10 * (t -= 1)) * Math.sin((t * d - s) * (2 * Math.PI) / p) * .5 + c + b;
    },
    easeInBack: function (x, t, b, c, d, s) {
        if (s == undefined) s = 1.70158;
        return c * (t /= d) * t * ((s + 1) * t - s) + b;
    },
    easeOutBack: function (x, t, b, c, d, s) {
        if (s == undefined) s = 1.70158;
        return c * ((t = t / d - 1) * t * ((s + 1) * t + s) + 1) + b;
    },
    easeInOutBack: function (x, t, b, c, d, s) {
        if (s == undefined) s = 1.70158;
        if ((t /= d / 2) < 1) return c / 2 * (t * t * (((s *= (1.525)) + 1) * t - s)) + b;
        return c / 2 * ((t -= 2) * t * (((s *= (1.525)) + 1) * t + s) + 2) + b;
    },
    easeInBounce: function (x, t, b, c, d) {
        return c - jQuery.easing.easeOutBounce(x, d - t, 0, c, d) + b;
    },
    easeOutBounce: function (x, t, b, c, d) {
        if ((t /= d) < (1 / 2.75)) {
            return c * (7.5625 * t * t) + b;
        } else if (t < (2 / 2.75)) {
            return c * (7.5625 * (t -= (1.5 / 2.75)) * t + .75) + b;
        } else if (t < (2.5 / 2.75)) {
            return c * (7.5625 * (t -= (2.25 / 2.75)) * t + .9375) + b;
        } else {
            return c * (7.5625 * (t -= (2.625 / 2.75)) * t + .984375) + b;
        }
    },
    easeInOutBounce: function (x, t, b, c, d) {
        if (t < d / 2) return jQuery.easing.easeInBounce(x, t * 2, 0, c, d) * .5 + b;
        return jQuery.easing.easeOutBounce(x, t * 2 - d, 0, c, d) * .5 + c * .5 + b;
    }
});

/*
*
* TERMS OF USE - EASING EQUATIONS
* 
* Open source under the BSD License. 
* 
* Copyright Â© 2001 Robert Penner
* All rights reserved.
* 
* Redistribution and use in source and binary forms, with or without modification, 
* are permitted provided that the following conditions are met:
* 
* Redistributions of source code must retain the above copyright notice, this list of 
* conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this list 
* of conditions and the following disclaimer in the documentation and/or other materials 
* provided with the distribution.
* 
* Neither the name of the author nor the names of contributors may be used to endorse 
* or promote products derived from this software without specific prior written permission.
* 
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
*  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
*  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
*  GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
*  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 
* OF THE POSSIBILITY OF SUCH DAMAGE. 
*
*/


var DP = (typeof DP == "object") ? DP : {};

DP.validateForm = function(){
	
	
	
	stringAlert="Missing fields:\n\n";

    //generic check value method
	var formValidated = function()
	{		
			return true;
	}
	
	
    var fromReset = function(elmId, wrongValue, messageText){
        //reset
        $(".from_wrp input").css({"border":"1px solid #ACA69F"});
        $(".from_wrp select").css({"border":"1px solid #ACA69F"});
        $("#error_messages").empty("");
    }

    //generic check value method
    var valueCheck = function(elmId, wrongValue, messageText){
        if($("#" + elmId).val() == wrongValue){
            createAlert(elmId, messageText);
			return false;
		}
		if(elmId=="adminManagePasswordRe" && $("#" + elmId).val()!=$("#adminManagePassword").val())
		{
			createAlert(elmId, messageText + "\nIt must be the same.");
			return false;
		}
		
			
			return true;
				
    }
    
    //alert method
    var createAlert = function(elmId, messageText){
        stringAlert +=messageText + "\n";
    }

    //zip validation
    var isZip = function(s){
        var reZip = new RegExp(/(^\d{5}$)|(^\d{5}-\d{4}$)/);
        if (!reZip.test(s)) {
            return false;
        }
        return true;
    }
    
    //checks if value is integer
    var isInt = function(n){
        var reInt = new RegExp(/^-?\d+$/);
        if (!reInt.test(n)) {
            return false;
        }
        return true;
    } 
	//checks if value is integer
    var isPrice = function(n){
        var rePrice = new RegExp(/^\d+(\.\d{1,2})?$/);
        if (!rePrice.test(n)) {
            return false;
        }
        return true;
    } 
	
	//mail validation
    var isMail = function(s, elmId){
        var reMail = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
        if (!reMail.test(s)) {
            return false;
        }
		if(elmId=="playersManageEmailRe")
		{
			if(s==$("#playersManageEmail").val())
			{
				return true;
			}
			else
			{
				return false;
			}
			return false;
		}
        return true;
    }
    
    
    //public method checks fieds
    //requires 'valSetting' setting object
	
    this.runCheck = function(){
        //reseet form		
        //run checks
		var countTrueFilled=0;
		stringAlert="";
        for (i=0;i<this.valSetting.fileds.length;i++){
            
            if(this.valSetting.fileds[i].type == "zip"){
                //zip check
                if(isZip($("#" + this.valSetting.fileds[i].id).val()) == false){    
                    createAlert(this.valSetting.fileds[i].id, this.valSetting.fileds[i].msg);
                }
				else{
					countTrueFilled++;
				}
            }
            else if (this.valSetting.fileds[i].type == "number"){
                //checks for number
                if(isInt($("#" + this.valSetting.fileds[i].id).val()) == false){    
                    createAlert(this.valSetting.fileds[i].id, this.valSetting.fileds[i].msg);
                }
				else{
					countTrueFilled++;
				}
            }
			else if (this.valSetting.fileds[i].type == "price"){
                //checks for number
                if(isPrice($("#" + this.valSetting.fileds[i].id).val()) == false){    
                    createAlert(this.valSetting.fileds[i].id, this.valSetting.fileds[i].msg);
                }
				else{
					countTrueFilled++;
				}
            }
			else if (this.valSetting.fileds[i].type == "email"){
                //checks for number
                if(isMail($("#" + this.valSetting.fileds[i].id).val(), this.valSetting.fileds[i].id) == false){    
                    createAlert(this.valSetting.fileds[i].id, this.valSetting.fileds[i].msg);
                }
				else{
					countTrueFilled++;
				}
            }
            else{
                //checks for value
                if(valueCheck(this.valSetting.fileds[i].id, this.valSetting.fileds[i].val, this.valSetting.fileds[i].msg))
				{
					countTrueFilled++;
				}
            }
        }
		if(countTrueFilled>=this.valSetting.fileds.length)
		{
			
			formValidated();
			return true;
		}
		else
		{
			alert(stringAlert);
			return false;
		}
		
    }
	
	
} 


function getBrowserHeight()
{
	if (window.innerHeight)
	{
		return window.innerHeight;
	}
	else if (document.documentElement && document.documentElement.clientHeight != 0)
	{
		return document.documentElement.clientHeight;
	}
	else if (document.body)
	{
		return document.body.clientHeight;
	}
	
	return 0;
};

function getBrowserWidth()
{
	if (window.innerWidth)
	{
		return window.innerWidth;
	}
	else if (document.documentElement && document.documentElement.clientWidth != 0)
	{
		return document.documentElement.clientWidth;
	}
	else if (document.body)
	{
		return document.body.clientWidth;
	}
	
	return 0;
};


function getScreenHeight()
{
	if (screen.height)
	{
		return screen.height;
	}	
	return 0;
};

function getScreenWidth()
{
	if (screen.width)
	{
		return parseInt(screen.width*0.9);
	}	
	return 0;
};





function sumSL()
{
	var sumSponsorLevels = new Number(0);
	for(var i=1; i<6; i++)
	{
		if($("input#sponsorsManageSL" + i).is(':checked'))
		{
			sumSponsorLevels +=parseFloat($("input#sponsorsManageSLHidden" + i).val());
		}
	}
	return sumSponsorLevels;
}

function generateSelectBoxGenders(c)
{
	var rowP = new String("");
	rowP="<select id='sponsorshipSupPlayerGender" + c + "' name='sponsorshipSupPlayerGender" + c + "' size='1' class='mf-select'>";
	rowP +="<option value='0'>Sex</option>";
	rowP +="<option value='1'>Male</option>";
	rowP +="<option value='2'>Female</option>";
	rowP +="</select>";
	return rowP;
}

function generateSelectBoxSizes(c)
{
	var rowP = new String("");
	rowP="<select id='sponsorshipSupPlayerSizes" + c + "' size='1' name='sponsorshipSupPlayerSizes" + c + "' class='mf-selectEnd'>";
	rowP +="<option value='0'>Size</option>";
	rowP +="<option value='1'>S</option>";
	rowP +="<option value='2'>M</option>";
	rowP +="<option value='3'>L</option>";
	rowP +="<option value='4'>XL</option>";
	rowP +="</select>";
	return rowP;
}

function rowPP(c)
{
	var rowP = new String("");
	rowP="<tr><td class='pL1'>" + c + ".</td>";
	rowP +="<td class='pL2'><input type='text' id='sponsorshipSupPlayerInfoName" + c + "' name='sponsorshipSupPlayerInfoName" + c + "' value='' class='mf-input' /></td>";
	rowP +="<td class='pL3'><input type='text' id='sponsorshipSupPlayerInfoEmail" + c + "' name='sponsorshipSupPlayerInfoEmail" + c + "' value='' class='mf-input' /></td>";
	rowP +="<td class='pL4'>" + generateSelectBoxGenders(c) + generateSelectBoxSizes(c) + "</td></tr>";
	
	return rowP;
}


function resetPlayerRows(a)
{
	a.html();
}



function generatePlayerRows(a, b)
{
	resetPlayerRows(b);
	
	var rowPAll = new String("");
	rowPAll = "<table class='playerList'>";
	
	for(var i=1; i<=a; i++)
	{
		rowPAll +=rowPP(i);
	}
	rowPAll +="</table>";
	if(rowPAll.length>0)
	{
		b.html(rowPAll);
	}
	
}

function removePlayersRows(c, j)
{
	
	for(var i=(j+1); i<=c; i++)
	{
		$("div#generatePlayerList table.playerList tr:nth-child(" + (j+1) + ")").remove();
	}
}


function addPlayerRows(z, a, b)
{
	var rowPAll = new String("");
	
	var count = $("div#generatePlayerList table.playerList tr").length;
	if(count>z)
	{
		removePlayersRows(count, z); return false;
	}
	
	
	for(var i=(z+1); i<=(a+z); i++)
	{
		rowPAll +=rowPP(i);
	}
	if(rowPAll.length>0)
	{
		b.append(rowPAll);
	}
}

function addNewInvited(id, obj){
	var vl = new DP.validateForm();
    
				    //passes validation settings
				    vl.valSetting = {fileds : [
						{id : "invitedName", val : "Name", msg : "Name", type : ""}, {id : "invitedSurname", val : "Surname", msg : "Surname", type : ""}, {id : "invitedEmail", val : "Email", msg : "Email", type : "email"}
				        ]
				    };
	if(vl.runCheck()){
	var postData="id=" + id + "&name=" + $("input#invitedName").val() + "&surname=" + $("input#invitedSurname").val() + "&title=" + $("input#invitedTitle").val() + "&telephone=" + $("input#invitedPhone").val() + "&email=" + $("input#invitedEmail").val() + "&department=" + $("select#invitedDepartment").val() + "&context=addNewInvited";				
	$.ajax({
		type: "POST",
		url: "private.php?section=1",
		data: postData,
		dataType: "html",
		success: function(responseText){
			if(responseText==0){
				alert("Recipient already exists in the list.\n\nPlease, try with another e-mail address."); return false;
			}
			checkForInvited(id, obj);
		}
	});	
	}
}


function removeInvited(id, obj, idI){
	if(deleteCurRecord()){
	var postData="id=" + id + "&idI=" + idI + "&context=removeInvited";				
	$.ajax({
		type: "POST",
		url: "private.php?section=1",
		data: postData,
		dataType: "html",
		success: function(responseText){
			checkForInvited(id, obj);
		}
	});	
	}
}


function checkForInvited(id, obj){
	$("input#invitedName").val("Name");
	$("input#invitedSurname").val("Surname");
	$("input#invitedTitle").val("Title");
	$("input#invitedPhone").val("Phone number");
	$("input#invitedEmail").val("Email");
	$("select#invitedDepartment").val($("select#invitedDepartment option:first").val());
	
	var postData="id=" + id + "&context=checkForInvited";				
	$.ajax({
		type: "POST",
		url: "private.php?section=1",
		data: postData,
		dataType: "html",
		success: function(responseText){
			obj.html(responseText);
		}
	});				
}

function sendInvitationList(id){
	var postData="id=" + id + "&context=sendInvitationList";				
	$.ajax({
		type: "POST",
		url: "private.php?section=1",
		data: postData,
		dataType: "html",
		success: function(responseText){			
			window.location.href="private.php?section=1";
		}
	});				
}


function slideSwitch() {						
					    var $active = $('#slideshowPlace div.fadein div.active');
						var al=parseInt($active.attr("rel"))+1;
						$("div.controls img.arrowmove").attr("rel", $("#slideshowPlace div.fadein div[rel="+al+"]").find("a").attr("href"));
						if(al==5){
							$("div.controls img.arrowmove").attr("rel", $("#slideshowPlace div.fadein div[rel=1]").find("a").attr("href"));
						}
						moveArrow($active.attr("rel"), $("div.controls img.arrowmove"), $active);

					    if ( $active.length == 0 ) $active = $('#slideshowPlace div.fadein div:last');

					    var $next =  $active.next().length ? $active.next()
					        : $('#slideshowPlace div.fadein div:first');

					    $active.addClass('last-active');

					    $next.css({opacity: 0.0})
					        .addClass('active')
					        .animate({opacity: 1.0}, 3000, function() {								
					            $active.removeClass('active last-active');
								
					        });
					}


function moveArrow(a, b, c){
	var al=parseInt(a)+1;	
	var limit=4;
	if(a==limit) a=0;
	b.animate({"marginTop": (a*66)+"px"}, 1000, "easeOutQuad", function(){
		//b.attr("rel", $("#slideshowPlace div.fadein div[title="+al+"]").find("a").attr("href"));
	});
}


function show_overlay(responseText) {
    if ($("div#overlay").length==0) append_overlay(responseText);
    overlay_wrapper.fadeIn("fast");
}

function hide_overlay() {
    overlay_wrapper.fadeOut("fast", function(){										  
		overlay_wrapper.remove();	
		});
}

function append_overlay(responseText) {
    overlay_wrapper = $('<div id="overlay"></div>').appendTo( $('BODY') );    
	overlay_panel = $("<div />" )
             .attr("id", "displayInfoDomainOwner")
             .addClass("displayErrMessage")
             .html(responseText)
			 .appendTo(overlay_wrapper);
    attach_overlay_events();
}

function attach_overlay_events() {	

	$("div#pWTAddNew").toggle(function(){
				$("div#invitedForm").slideDown();}, function(){
				$("div#invitedForm").slideUp();
			});
			
	if($("div#invitedMemberList").length>0){
			$("input#invitedName").focus(function(){
				if($(this).val()=="Name"){
					$(this).val("");
				}
			}).blur(function(){
				if($(this).val()==""){
					$(this).val("Name");
				}
			});
			$("input#invitedSurname").focus(function(){
				if($(this).val()=="Surname"){
					$(this).val("");
				}
			}).blur(function(){
				if($(this).val()==""){
					$(this).val("Surname");
				}
			});
			$("input#invitedTitle").focus(function(){
				if($(this).val()=="Title"){
					$(this).val("");
				}
			}).blur(function(){
				if($(this).val()==""){
					$(this).val("Title");
				}
			});
			$("input#invitedPhone").focus(function(){
				if($(this).val()=="Phone number"){
					$(this).val("");
				}
			}).blur(function(){
				if($(this).val()==""){
					$(this).val("Phone number");
				}
			});
			$("input#invitedEmail").focus(function(){
				if($(this).val()=="Email"){
					$(this).val("");
				}
			}).blur(function(){
				if($(this).val()==""){
					$(this).val("Email");
				}
			});
			
			$("input#invitedSubmit").click(function(){
					addNewInvited($("div#invitedMemberList").attr("title"), $("div#invitedMemberList"));								
			});
			
			$("input#invitedSubmitList").click(function(){
				sendInvitationList($("div#invitedMemberList").attr("title"));								
			});
			
			$("div.fRow_5 img").live("click", function(){
				removeInvited($("div#invitedMemberList").attr("title"), $("div#invitedMemberList"), $(this).attr("title"));									   
			});
			
			checkForInvited($("div#invitedMemberList").attr("title"), $("div#invitedMemberList"));
		}		
			
	
    $('div#overlay div.displayErrMessage div.closeOverlay').click( function(e) {
        e.preventDefault();
        hide_overlay();
    });
}


$.fn.preload = function() {
    this.each(function(){
        $('<img/>')[0].src = this;
    });
}


function currentURL(isHash){
	var curURL=window.location.href;
	curURL=curURL.substr(curURL.indexOf("?"));
	if(!isHash){
		if(curURL.indexOf("#")!=-1){
			curURL=curURL.substr(0, curURL.indexOf("#"));
		}
	}
	return curURL;
}

function switchBGColors(){
	$("div.bottomAbsolute div.innerContent, div.bottomAbsolute div.innerContent a").animate({color: "#000000"}, "slow");
	$("div.bottomAbsolute").animate({backgroundColor:"#ffcc00"}, "slow", function(){
	setTimeout(switchBGColorsBack, 5000);
	});
}
function switchBGColorsBack(){
	$("div.bottomAbsolute div.innerContent, div.bottomAbsolute div.innerContent a").animate({color: "#ffffff"}, "slow");
	$("div.bottomAbsolute").animate({backgroundColor:"#990000"}, "slow", function(){
	setTimeout(switchBGColors, 5000);
	});
}

$(document).ready(function() {
	
	setTimeout(switchBGColors, 5000);
	
	$("div.controls img.arrowmove").attr("rel", $("#slideshowPlace div.fadein div[title=1]").find("a").attr("href"));
	
	
	
	if($("input[name=profilUserDietary]:checked").val()==1){
				$("div#dietaryDetailsDisplay").show();
	}
	if($("input[name=profilUserTransportation]:checked").val()==1){
				$("div.redAlert").show();
			}
	if(currentURL(false).indexOf("success")!=-1){
		var successMessage=currentURL(false).substr(currentURL(false).indexOf("success"));
		successMessage=successMessage.split("=");		
		show_overlay("<div class='popupWhite3' id='preUserLangChooser'><div class='insideContent'><h3 class='bodytext'>" + $("input#successMessage" + successMessage[1]).val() + "</h3></div></div>");
		setTimeout( "hide_overlay()", 4000 );		
	}
	
	var countImagesInFader=$("div.fadein img").length;
	var loadedImagesFromFader=0;
	$("div.fadein img").each(function(){
		$(this).css({display: "none"}).preload();
		loadedImagesFromFader++;
		$(this).css({display: "block"});
	});
	if(loadedImagesFromFader==countImagesInFader){
		if($("div#slideshowPlace").length>0){
		var fWidth=$(".fadein").width()/2;
		var fHeight=$(".fadein").height()/2;
		$(".fadein div").first().addClass("active");
		$(".fadein div").each(function(){
			$(this).css({
				"left": (fWidth-556/2) + "px",
				"top": (fHeight-255/2) + "px"			
			});
			
		});
	}
	setInterval( "slideSwitch()", 5000 );
	}
	
	
	
	$("div.blocksOuter div.block4 span.clickAvailable").click(function(){
		var postData="context=addNewAttendeeToEvent&eventid=" + $(this).attr("title");				
			$.ajax({
				type: "POST",
				url: "private.php?section=1",
				data: postData,
				dataType: "html",
				success: function(responseText){			
					show_overlay(responseText);
				}
			});	
	});
	
	
	
	if($("input#NoLanguageChoosenYet").length>0){
		if($("input#NoLanguageChoosenYet").val()!=0){
			var langChooserBlock='<div id="preUserLangChooser" class="popupWhite"><div class="insideContent"><form id="frmChooseLanguage" method="post" action=""><input type="submit" id="langEn" value="English" /><input class="mf-input" type="submit" id="langFr" value="French" /><input type="hidden" id="context" name="context" value="updateLanguage" /><input type="hidden" id="choosedLanguage" name="choosedLanguage" /></form></div></div>';
			show_overlay(langChooserBlock);
		}
	}
	
	if($("input#NoInvitedChoosenYet").length>0){
		if($("input#NoInvitedChoosenYet").val()!=0){
			var postData="context=NoInvitedChoosenYet";				
			$.ajax({
				type: "POST",
				url: "private.php?section=1",
				data: postData,
				dataType: "html",
				success: function(responseText){			
					show_overlay(responseText);
				}
			});				
		}
	}
	
	if($("input#YesInvitedChoosenYet").length>0){
		if($("input#YesInvitedChoosenYet").val()!=0){
			var postData="context=YesInvitedChoosenYet";				
			$.ajax({
				type: "POST",
				url: "private.php?section=1",
				data: postData,
				dataType: "html",
				success: function(responseText){			
					show_overlay(responseText);
				}
			});				
		}
	}
	
	/*
	if($("div#slideshowPlace").length>0){
		var fWidth=$(".fadein").width()/2;
		var fHeight=$(".fadein").height()/2;
		$(".fadein div").first().addClass("active");
		$(".fadein div").each(function(){
			$(this).css({
				"left": (fWidth-$("img", this).width()/2) + "px",
				"top": (fHeight-$("img", this).height()/2) + "px"			
			});
			
		});
		*/
		$("#slideshowPlace div.fadein div").each(function(){
			if($(this).find("a").length>0){
				$(this).css({cursor: "pointer"});
			}
		});
		
		$("#slideshowPlace div.fadein div").click(function(){
			if($(this).find("a").length>0){
				window.location=$(this).find("a").attr("href");
			}
		});
		
		$("#slideshowPlace div.controls div").each(function(){
			if($(this).find("a").length>0){
				$(this).css({cursor: "pointer"});
			}
		});
		
		$("#slideshowPlace div.controls div").click(function(){
			if($(this).find("a").length>0){
				window.location=$(this).find("a").attr("href");
			}
		});
	
		$("div.controls img.arrowmove").click(function(){
			if($(this).attr("rel")!=""){
				window.location=$(this).attr("rel");
			}
		});
		
						   
		$("div#preUserLangChooser input").live("click", function(){
				var whatLangChoosed;
				switch($(this).attr("id")){
					case "langEn":
					whatLangChoosed=1;
					break;
					case "langFr":
					whatLangChoosed=2;
					break;
					case "inviteDo":
					whatLangChoosed=1;
					break;
					case "inviteNo":
					whatLangChoosed=0;
					hide_overlay();
					break;
					case "returnToProfile":
					window.location="?section=1&page=4";
					break;
				}
				if($(this).attr("id")!="inviteNo"){
					$("input#choosedLanguage").val(whatLangChoosed);
					$("#frmChooseLanguage").submit();
				}
		});
						   
		
		$("#frmLoginAdmin").submit(function()	{											
			return vl.runCheck();
		});	
		
		$("div#menu ul li.sLink, div#menu ul li.sLinkCurrent").hover(function(){
			$(this).animate({height: "80px"}, "fast", "easeOutQuad");}, function(){
			$(this).animate({height: "31px"}, "fast", "easeOutQuad");
		}).click(function(){ window.location=$("a", this).attr("href");});
				
		$("#frmAddUpdateRSVP input[type=radio]").click(function(){
			$("#frmAddUpdateRSVP").submit();
		});
		$("#frmAddUpdateTransportationMethod input[type=radio]").click(function(){
			$("#frmAddUpdateTransportationMethod").submit();
		});
		$("#frmAddUpdateDietary input[type=radio]").click(function(){
			if($(this).val()==2){
				$("div#dietaryDetailsDisplay").hide();
				$("#frmAddUpdateDietary").submit();
			}else if($(this).val()==1){
				$("div#dietaryDetailsDisplay").slideDown();
			}
		});
		$("#frmAddUpdateRoommates select").change(function(){
			var postData="id=" + $(this).val()+"&section=1&context=addRoommateToUser";				
				$.ajax({
						   type: "POST",
						   url: "private.php",
						   data: postData,
						   dataType: "html",
						   success: function(responseText){
							   $("#showHideRoommateSection").hide();
							   $("p#showRoommateHere").html(responseText);				
						   }
					});	
			//$("#frmAddUpdateRoommates").submit();
		});
		
		$("span#clickToRemoveRoommate a").live("click", function(e){
			e.preventDefault();
			var postData="context=removeRoommateToUser";				
				$.ajax({
						   type: "POST",
						   url: "private.php",
						   data: postData,
						   dataType: "html",
						   success: function(responseText){
							   $("#showHideRoommateSection").show();
							   $("p#showRoommateHere").html(responseText);				
						   }
					});	
		});
		
});
