var SiteUrl="http://"+location.hostname+"/"; 
//var SiteUrl="http://www.grooveallnight.com/beta/"; 
//var SiteUrl="http://php1.funnymedialinks.com/grooveallnight/"; 

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function chklogin()
{
	if((document.getElementById("top_uname").value=="") || (document.getElementById("top_uname").value=="username"))
	{
		alert("Please Enter Username!")
		document.getElementById("top_uname").focus();
		return false;
	}
	
	if(document.getElementById("top_pass").value=="")
	{
		alert("Please Enter password!")
		document.getElementById("top_pass").focus();
		return false;
	}
return true;
}

function show_state(sid)
{ 
	document.getElementById("state").innerHTML="<img src='"+SiteUrl+"images/loader.gif'>";
	url = SiteUrl+"state_box.php?stateid="+sid+"&show=registration";
	ajaxLink(url,"state")	;
}
function show_state_new(sid)
{ 
	document.getElementById("stateDiv").innerHTML="<img src='"+SiteUrl+"images/loader.gif'>";
	url = "state_box.php?show=registration&stateid="+sid;
	showit(url,"stateDiv");
}

function show_state_update(sid)
{ 
	document.getElementById("state_updt").innerHTML="<img src='"+SiteUrl+"images/loader.gif'>";
	url = "state_box.php?show=eventupdate&stateid="+sid;
	showit(url,"state_updt");
}


function show_city_new(sid)
{ 
	document.getElementById("cityDiv").innerHTML="<img src='"+SiteUrl+"images/loader.gif'>";
	var cid=document.getElementById('show_country').value;
	document.getElementById('state_id').value=sid;
	url = "city_box.php?setto=show_city&show=registration&stateid="+sid+"&countryid="+cid;
	showit(url,"cityDiv");
}

function show_city_update(sid)
{ 
	document.getElementById("city_updt").innerHTML="<img src='"+SiteUrl+"images/loader.gif'>";
	var cid=document.getElementById('country_update').value;
	document.getElementById('update_state').value=sid;
	url = "city_box.php?function=add_cityname&show=eventupdate&stateid="+sid+"&countryid="+cid;
	showit(url,"city_updt");
}

function show_state_event(sid)
{ 
	document.getElementById("stateDiv").innerHTML="<img src='"+SiteUrl+"images/loader.gif'>";
	url = "state_box.php?show=newEvent&stateid="+sid;
	showit(url,"stateDiv");
}
function show_city_event(sid)
{ 
	document.getElementById("cityDiv").innerHTML="<img src='"+SiteUrl+"images/loader.gif'>";
	var cid=document.getElementById('show_country').value;
	document.getElementById('state_id').value=sid;
	url = "city_box.php?function=get_venue&show=registration&stateid="+sid+"&countryid="+cid;
	showit(url,"cityDiv");
}

function get_venue(city)
	{
	document.getElementById("venueDiv").innerHTML="<img src='"+SiteUrl+"images/loader.gif'>";
	document.getElementById('show_city').value=city;
	var cid=document.getElementById('show_country').value;
	var sid=document.getElementById('state_id').value;
	url = "venue_box.php?setto=venue_id&show=registration&cityid="+city+"&stateid="+sid+"&countryid="+cid;
	showit(url,"venueDiv");
	}
	
function update_venue(vid)
	{
	document.getElementById('venue_id').value=vid;
	}
	
/////////////////////common libraries         ////////////

function $id(element) 
		{
			//function for getting element id
			if (typeof element == 'string')
			element = document.getElementById(element);
			return element;
		}


function isBlank(id)
		{	//function to check is value blank		
		if($id(id).value=="") return  true; else	return false;
		}
			
			
			
function isBlankFocus(id,message)
		{	//function to check is value blank and focus with return false		
			if($id(id).value=="")
				{  
				alert(message);
				$id(id).focus();
				return  true;
				}
		}
			
			
			
function isValidEmail(value)
			{	//function to check is email address valid	
				if(!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(value)))
				return false;
				else
				return true;
			}
			
function isvalidphoto(thisfile)
 {
 //function to check is valid image type valid	
 var fileext = new Array ('.jpg', '.gif', '.jpeg', '.png', '.bmp', '.tif');
 	if(thisfile!="")
		{		
					var fileOK = 0;
					var aa = thisfile.substr(thisfile.indexOf('.'));
					var bb = aa.toLowerCase()
					for (j = 0; j < fileext.length; j++)
					{
							if(bb==fileext[j])
							{
								return true;
								break;
							}
					}
		}

	return false;
	
 }			
function switchDiv(divid)
			{
				if($id(divid).style.display=='')
				$id(divid).style.display='none';
				else
				$id(divid).style.display='';
				
			}



function ReverseCss(id)
	{//function to change navigation css
		if(id.className=='TitleTextNew_ro')
		id.className='TitleTextNew';
		else
		id.className='TitleTextNew_ro';
	}
	
function switchDivOn(divid)
			{
				$id(divid).style.display='';
				
			}
			
function switchDivOff(divid)
			{
				$id(divid).style.display='none';
				
			}
function isProper(val,fieldLabel)
	{
	var iChars = "!@#$%^&*()+=-[]\\\';,./{}|\":<>?";
	  for (var i = 0; i < val.value.length; i++)
	  {
		if (iChars.indexOf(val.value.charAt(i)) != -1)
		{
		alert (fieldLabel+" is not allowed to have special characters");
		return false;
		}
	  }
	  return true;
	}
// {{{ implode
function implode( glue, pieces ) {
       return ( ( pieces instanceof Array ) ? pieces.join ( glue ) : pieces );
}// }}}

// {{{ explode
function explode( delimiter, string ) {
    // Split a string by string
    // *     example 1: explode(' ', 'DD Agarwal');
    // *     returns 1: {0: 'DD', 1: 'van', 2: 'Zonneveld'}

    var emptyArray = { 0: '' };

    if ( arguments.length != 2
        || typeof arguments[0] == 'undefined'
        || typeof arguments[1] == 'undefined' )
    {
        return null;
    }

    if ( delimiter === ''
        || delimiter === false
        || delimiter === null )
    {
        return false;
    }

    if ( typeof delimiter == 'function'
        || typeof delimiter == 'object'
        || typeof string == 'function'
        || typeof string == 'object' )
    {
        return emptyArray;
    }

    if ( delimiter === true ) {
        delimiter = '1';
    }

    return string.toString().split ( delimiter.toString() );
}// }}}


// {{{ in_array
function in_array(needle, haystack, strict) {
    // Checks if a value exists in an array
    // 
    // +    discuss at: http://DD.Agarwal.net/techblog/article/javascript_equivalent_for_phps_in_array/
    // +       version: 803.2519
    // +   original by: DD Agarwal (http://DD.Agarwal.net)
    // *     example 1: in_array('van', ['DD', 'van', 'Zonneveld']);
    // *     returns 1: true

    var found = false, key, strict = !!strict;

    for (key in haystack) {
        if ((strict && haystack[key] === needle) || (!strict && haystack[key] == needle)) {
            found = true;
            break;
        }
    }

    return found;
}// }}}

String.prototype.trim = function () {
  return this.replace(/^\s*(\S*(\s+\S+)*)\s*$/, "$1");
};
