function getCookie(NameOfCookie)
{
	if (document.cookie.length > 0)
	{
		begin = document.cookie.indexOf(NameOfCookie+"=");
		if (begin != -1)
		{
			begin += NameOfCookie.length+1;
			end = document.cookie.indexOf(";", begin);
			if (end == -1) end = document.cookie.length;
			return unescape(document.cookie.substring(begin, end));
		} 
	}
	return null; 
}
function setCookie(NameOfCookie, value, path, expiredays)
{
	var ExpireDate = new Date ();
	ExpireDate.setTime(ExpireDate.getTime() + (expiredays * 24 * 3600 * 1000));
	document.cookie = NameOfCookie + "=" + escape(value) + 
	((path == null) ? "" : "; path=" + path) + 
	((expiredays == null) ? "" : "; expires=" + ExpireDate.toGMTString());
}
function delCookie(NameOfCookie) 
{
	if (getCookie(NameOfCookie))
	{
		document.cookie = NameOfCookie + "=" + "; expires=Thu, 01-Jan-70 00:00:01 GMT";
	}
}
//----------------------------------------------------------------
// The Code below necessary to determine JS Enabled
//----------------------------------------------------------------
	if ( window.navigator.cookieEnabled )
	{
		setCookie('jsChecker','True','/');
		//window.status = 'jsChecker = ' + getCookie('jsChecker');
	}
//----------------------------------------------------------------
function Exists( obj )
{
	return typeof(obj) != 'undefined' && obj != null;
}
//
// Display Dump of object or array in nice dialog format
//
function dump( obj ){
	var result = '';
	var i = 0;
	var srch = (typeof(dump.arguments[1])=='undefined')?'':dump.arguments[1];
	if (!obj) {alert(obj);return;}
	result += ' *** '+typeof(obj)+' ***\n';
	result += ' === '+obj+' ===\n';
	for ( x in obj ) {
		if ((srch > '') && (x.toLowerCase().indexOf(srch.toLowerCase()) < 0)) continue;
		try {
			result += x + ': ' + obj[x] + '\n';
			i++;
			if ( i > 20 ) {
				if ( !confirm(result) ) {return;}
				result = '';
				i = 0;
			}
		} catch (e) {
			alert(e);
			if ( !confirm(result) ) {return;}
			result = '';
			i = 0;
		}
	}
	if ( result > '' ) {
		alert(result);
	}
}
//-----------------

function CheckGender(source, arguments){
	if(arguments.Value==-1)	
		arguments.IsValid = false;
}
function CheckMaritalStatus(source, arguments){
	if(arguments.Value==-1)	
		arguments.IsValid = false;
}
function CheckAge(source, arguments){
	if(arguments.Value==-1)	
		arguments.IsValid = false;
}
function CheckCountry(source, arguments){
	if(arguments.Value==-1)	
		arguments.IsValid = false;
}

//---START UNIVERSAL VALIDATORS
function CheckUniversal(source, arguments){
	var reg = new RegExp("^[^<>]{1,}$");
	reg.ignoreCase = true;
	reg.multiline = true;
	reg.global = true;
	arguments.IsValid = arguments.Value.match(reg);
}
function CheckLogin(source, arguments){
	//FOR ALL LANGUAGES
	//var reg = new RegExp("^[^\x21-\x2C\x2F\x3A-\x3E\x5B-\x5E\x60\x7B-\x7E]{1,}$");
	var reg = new RegExp("^[a-zA-Z0-9_@.-]{1,}$");
	reg.ignoreCase = true;
	reg.multiline = true;
	reg.global = true;
	arguments.IsValid = arguments.Value.match(reg);
}
function CheckPassword(source, arguments){
	//FOR ALL LANGUAGES
	//var reg = new RegExp("^[^\x21-\x2F\x3A-\x40\x5B-\x5E\x60\x7B-\x7E ]{1,}$");
	var reg = new RegExp("^[a-zA-Z0-9_]{1,}$");
	reg.ignoreCase = true;
	reg.multiline = true;
	reg.global = true;
	arguments.IsValid = arguments.Value.match(reg);
}
function CheckPasswordTag(source, arguments){
	//FOR ALL LANGUAGES
	//var reg = new RegExp("^[^\x21-\x2F\x3A-\x40\x5B-\x5E\x60\x7B-\x7E ]{1,}$");
	var reg = new RegExp("^[a-zA-Z0-9_]{1,}$");
	reg.ignoreCase = true;
	reg.multiline = true;
	reg.global = true;
	var str=TrimTag(arguments.Value);
	arguments.IsValid = str.match(reg);
}
function CheckPhone(source, arguments){
	var reg = new RegExp("^[0-9\x5F\x5C \x2B\x28\x29\x2D]{6,26}$");
	reg.ignoreCase = true;
	reg.multiline = true;
	reg.global = true;
	arguments.IsValid = arguments.Value.match(reg);
}
function CheckEmail(source, arguments){
	var reg = new RegExp("^([a-zA-Z0-9_\\-\\.]+)@((\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.)|(([a-zA-Z0-9_\\-]+\\.)+))([a-zA-Z0-9_]{2,4}|[0-9]{1,3})(\\]?)$");
	reg.ignoreCase = true;
	reg.multiline = true;
	reg.global = true;
	var str=Trim(arguments.Value);
	arguments.IsValid = str.match(reg);
}
function CheckZip(source, arguments){
	var reg = new RegExp("^[0-9 ]{4,}$");
	reg.ignoreCase = true;
	reg.multiline = true;
	reg.global = true;
	arguments.IsValid = arguments.Value.match(reg);
}
function CheckAlphanumeric(source, arguments){
	var reg = new RegExp("^[_0-9a-zA-Z]{1,}$");
	reg.ignoreCase = true;
	reg.multiline = true;
	reg.global = true;
	var str=Trim(arguments.Value);
	arguments.IsValid = str.match(reg);
}
function CheckAge(source, arguments){
	var reg = new RegExp("^[0-9]{1,2}$");
	reg.ignoreCase = true;
	reg.multiline = true;
	reg.global = true;
	var str=Trim(arguments.Value);
	arguments.IsValid = (str.match(reg) && str>0);
}
function Trim(str,symb){
	while(str.charAt(0) == symb)
		str = str.substring(1,str.length);		
	while(str.charAt(str.length-1) == symb)
		str = str.substring(0,str.length-1);		
	return str;
}
function TrimTag(str){
	while(str.charAt(0) == ">")
		str = str.substring(1,str.length);		
	while(str.charAt(str.length-1) == "<")
		str = str.substring(0,str.length-1);		
	return str;
}
function CheckNumeric(source, arguments){
	var reg = new RegExp("^[0-9 ]{1,}$");
	reg.ignoreCase = true;
	reg.multiline = true;
	reg.global = true;
	var str=Trim(arguments.Value);
	arguments.IsValid = (str.match(reg) && str>0);
}
function CheckNumeric0(source, arguments){
	var reg = new RegExp("^[0-9 ]{1,}$");
	reg.ignoreCase = true;
	reg.multiline = true;
	reg.global = true;
	var str=Trim(arguments.Value);
	arguments.IsValid = (str.match(reg) && str>=0);
}
function CheckDouble(source, arguments){
	var reg = new RegExp("^([^_0-9a-zA-Z\.\,]*)([0-9]{1,})((\,|\.)([0-9]{1,2}))?([^_0-9a-zA-Z]*)$");
	reg.ignoreCase = true;
	reg.multiline = true;
	reg.global = true;
	var str=Trim(arguments.Value);
	arguments.IsValid = str.match(reg);
}
//---END UNIVERSAL VALIDATORS

function ShowSummaryValidator(summaryId)
{
	var summary = document.getElementById(summaryId);
	if (typeof(Page_Validators) == 'undefined' || Page_Validators == null) return;
	if (typeof(summary) == 'undefined' || summary == null) return; 
	if (summary.showmessagebox == "True") {
		s = "";
		if (typeof(summary.headertext) == "string") {
			s += summary.headertext + "<BR>";
		}
		var needShow = false;
		for (i=0; i<Page_Validators.length; i++) { 
			//alert(Page_Validators[i].enabled+':'+Page_Validators[i].id)
			if (!Page_Validators[i].isvalid && typeof(Page_Validators[i].errormessage) == "string") {
				needShow = true;
				
				switch (summary.displaymode) {
					case "List":
						s += Page_Validators[i].errormessage + "<BR>";
						break;
					case "BulletList":
					default: 
						s += "  - " + Page_Validators[i].errormessage + "<BR>";
						break;
					case "SingleParagraph":
						s += Page_Validators[i].errormessage + " ";
						break;
				}
			}
		}
		if (!needShow) return;
		span = document.createElement("SPAN");
		span.innerHTML = s;
		s = span.innerText;
		alert(s);
	}
}
/*
	argument[0] - checkBox
	argument[1] - function wich calls when you want set CheckBox true;
	argument[2] - function wich calls when you want set CheckBox false;
*/
function ConfirmSetCheck(checkBox)
{
	var foo1 = ConfirmSetCheck.arguments[1];
	var foo2 = ConfirmSetCheck.arguments[2]
	if(checkBox.checked)
	{
		var cnfrmRes = false;
		if ( typeof(foo1) == 'function' )
		{
			cnfrmRes = foo1();
		}
		if(!cnfrmRes)
		{
			checkBox.checked=false;
			return;
		}
	}else{
		var cnfrmRes = false;
		if ( typeof(foo2) == 'function' )
		{
			cnfrmRes = foo2();
		}
		if(!cnfrmRes)
		{
			checkBox.checked=true;
			return;
		}
	}
}
function StopDate(tdIdText,tdIdButton,iam)
{
	var foo = StopDate.arguments[3];
	if(iam.checked)
	{
		var cnfrmRes = false;
		if ( typeof(foo) == 'function' )
		{
			cnfrmRes = foo();
		}
		if(!cnfrmRes)
		{
			iam.checked=false;
			return;
		}
	}
	var tdT = document.getElementById(tdIdText);
	var tdB = document.getElementById(tdIdButton);
	if ( typeof(tdT) != 'undefined' && typeof(tdB) != 'undefined' && tdB != null && tdT != null )
	{
		tdB.disabled = !iam.checked;
		tdT.disabled = !iam.checked;
	}
	
	//td.Disable = !iam.checked;
	
	//alert("Date control disabled is " + td.disabled);
	/*
	for(var i = 0; i < td.childNodes.length; i++)
	{
		if ( typeof(td.childNodes[i].disabled) != 'undefined' && td.childNodes[i].disabled != null )
		{
			td.childNodes[i].disabled = !iam.checked;

		}
	}*/
}
function KillDrop(idDisc,idDist,iam)
{
	var v1=document.getElementById(idDisc);
	var v2=document.getElementById(idDist);

	for(var i = 0; i < v1.childNodes.length; i++)
	{
		if ( typeof(v1.childNodes[i].disabled) != 'undefined' && v1.childNodes[i].disabled != null )
		{
			v1.childNodes[i].disabled = !iam.checked;
		}
	}
	for(var i = 0; i < v2.childNodes.length; i++)
	{
		if ( typeof(v2.childNodes[i].disabled) != 'undefined' && v2.childNodes[i].disabled != null )
		{
			v2.childNodes[i].disabled = !iam.checked;
		}
	}
}
function EnableControls(container,tagName,enabled)
{
	if ( typeof(container) != 'undefined' && container != null )
	{
		var ctrls = container.childNodes;
		for ( var i = 0; i < ctrls.length; i++ )
		{
			if ( typeof(ctrls[i].tagName) != 'undefined' && ctrls[i].tagName != null )
			{
				if ( ctrls[i].tagName.toUpperCase() == tagName.toUpperCase() )
				{
					ctrls[i].disabled = !enabled;
				}
				else
				{
					EnableControls(ctrls[i],tagName,enabled);
				}
			}
		}
	}
}


function CopyLinkToClip(link)
{
	if ( typeof(link) != 'undefined' && link != null )
	{
		if ( typeof(window.clipboardData) != 'undefined' && window.clipboardData != null)
		{
			window.clipboardData.setData("Text", link.href);
			alert("Copied ... Use Ctrl+V to paste.");
		}
	}
	return false;
}
function SetFocus(id)
{
	var fld = document.getElementById(id);
	if ( typeof(fld) != 'undefined' && fld != null )
	{
		if ( typeof(fld.focus) != 'undefined' && fld.focus != null )
		{
			fld.focus();
		}
	}
}
function CheckSelection(sender, arguments)
{
	rExp=new RegExp("SelectedGroups","g");
	for(i=0; i<document.all.length; i++)
		if("INPUT"==document.all(i).tagName)
			if("checkbox"==document.all(i).type)
				if("SelectedGroups"==document.all(i).id.match(rExp))
					if(document.all(i).checked)
					{
						arguments.IsValid=true;
						return;
					}
	arguments.IsValid=false;
}

/*function HideSO()
{
	var soList = document.getElementsByTagName('DIV');
	for (var i = 0; i < soList.length; i++)
	{
		if ( soList[i].id.indexOf('soList') == 0 )
		{
			soList[i].style.display = 'none';
		}
	}
}*/

/*function ShowSO(id, btn)
{

	var div = document.getElementById(id);
	if ( typeof(div) != 'undefined' && div != null )
	{
		//div.style.display = '';
		btn.title = "This group served by these shops:"
		btn.title += "\n";
		btn.title += "\n"; 
		btn.title += div.innerText;
		btn.title += "\n"; 
		btn.title += "\n"; 
		btn.title += "Click to view details..."; 
	}
}*/

function getPosLeft(el)
{
	var pos = 0;
	pos = window.event.screenX - window.event.offsetX;
    return pos;
}
  
function getPosTop(el)
{
	var pos = 0;
	pos = window.event.screenY - window.event.offsetY;
    return pos;
}
function ShowTerms()
{
	window.open('/BipBip/terms.aspx','terms','width=800,height=650,status=0');
	return false;
}

function SetFocusFirstChild(el)
{
	if ( typeof(el) != 'undefined' && el != null )
	{
		if ( typeof(el.childNodes) != 'undefined' && el.childNodes != null )
		{
			for( var i = 0; i < el.childNodes.length; i++ )
			{
				try
				{
					el.childNodes[i].focus();
					return true;
				}
				catch(e)
				{
				}
			}
		}
	}
}