var newwindow;

function popup_window(url,name)
{
	newwindow=window.open(url,name,'height=400,width=400');
	if (window.focus) {newwindow.focus()}
}

function show_hide(id)
{
	if (document.getElementById)
	{
		obj = document.getElementById(id);
		if (obj.style.display == "none" || obj.style.display == "")
		{
			obj.style.display = "block";
		}
		else
		{
			obj.style.display = "none";
		}
	}
}

function expand(id){
	if (document.getElementById)
	{
		obj = document.getElementById(id);
		if (obj.style.backgroundPosition == "100% 0%" || obj.style.backgroundPosition == "")
		{
			obj.style.backgroundPosition = "100% 100%";
		}
		else
		{
			obj.style.backgroundPosition = "100% 0%";
		}
	}
}

function show(id)
{
    if (document.getElementById)
    {
        obj = document.getElementById(id);
        obj.style.display = "block";
    }
}

function hide(id)
{
    if (document.getElementById)
    {
        obj = document.getElementById(id);
        obj.style.display = "none";
    }
}

function toggle(object,id)
{
	if (document.getElementById)
    {
		obj = document.getElementById(id);
		if (document.getElementById(object).checked == 1)
		{
        	obj.style.display = "block";
		}
		else
		{
			obj.style.display = "none";
		}
    }
}

function setcookie(c_name,value,expiredays)
{
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie=c_name+ "=" +escape(value)+
	((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}

function clear_text(id,original_text)
{
	if (document.getElementById)
	{
		obj = document.getElementById(id);
		if (obj.value == original_text)
		{
			obj.value = "";
		}
	}
}

function default_text(id,original_text)
{
	if (document.getElementById)
	{
		obj = document.getElementById(id);
		if (obj.value == "")
		{
			obj.value = original_text;
		}
	}
}

function text_colour(id,new_colour,original_colour,original_text)
{
	if (document.getElementById)
	{
		obj = document.getElementById(id);
		if (obj.value == original_text)
		{
			obj.style.color = original_colour;
		}
		else
		{
			obj.style.color = new_colour;
		}
	}
}

function parseScript(_source) {
	var source = _source;
	var scripts = new Array();
	
	// Strip out tags
	while(source.indexOf("<script") > -1 || source.indexOf("</script") > -1) {
		var s = source.indexOf("<script");
		var s_e = source.indexOf(">", s);
		var e = source.indexOf("</script", s);
		var e_e = source.indexOf(">", e);
		
		// Add to scripts array
		scripts.push(source.substring(s_e+1, e));
		// Strip from source
		source = source.substring(0, s) + source.substring(e_e+1);
	}
	
	// Loop through every script collected and eval it
	for(var i=0; i<scripts.length; i++) {
		try {
			eval(scripts[i]);
		}
		catch(ex) {
			// do what you want here when a script fails
		}
	}
	
	// Return the cleaned source
	return source;
}

function valid_email(str) {
	var at="@";
	var dot=".";
	var lat=str.indexOf(at);
	var lstr=str.length;
	var ldot=str.indexOf(dot);
	if (str.indexOf(at)==-1){
	   return false;
	}

	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
	   return false;
	}

	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		return false;
	}

	 if (str.indexOf(at,(lat+1))!=-1){
		return false;
	 }

	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		return false;
	 }

	 if (str.indexOf(dot,(lat+2))==-1){
		return false;
	 }
	
	 if (str.indexOf(" ")!=-1){
		return false;
	 }

	 return true;				
}

function ucfirst(str) {
    var f = str.charAt(0).toUpperCase();
    return f + str.substr(1);
}

function str_pad (input, pad_length, pad_string, pad_type) {
    var half = '',
        pad_to_go; 
    var str_pad_repeater = function (s, len) {
        var collect = '',
            i;
         while (collect.length < len) {
            collect += s;
        }
        collect = collect.substr(0, len);
         return collect;
    };
 
    input += '';
    pad_string = pad_string !== undefined ? pad_string : ' '; 
    if (pad_type != 'STR_PAD_LEFT' && pad_type != 'STR_PAD_RIGHT' && pad_type != 'STR_PAD_BOTH') {
        pad_type = 'STR_PAD_RIGHT';
    }
    if ((pad_to_go = pad_length - input.length) > 0) {        if (pad_type == 'STR_PAD_LEFT') {
            input = str_pad_repeater(pad_string, pad_to_go) + input;
        } else if (pad_type == 'STR_PAD_RIGHT') {
            input = input + str_pad_repeater(pad_string, pad_to_go);
        } else if (pad_type == 'STR_PAD_BOTH') {            half = str_pad_repeater(pad_string, Math.ceil(pad_to_go / 2));
            input = half + input + half;
            input = input.substr(0, pad_length);
        }
    } 
    return input;
}

function get_month(month) {
    switch(month)
    {
        case 1:
          return "January";
        break;
        case 2:
          return "February";
        break;
        case 3:
          return "March";
        break;
        case 4:
          return "April";
        break;
        case 5:
          return "May";
        break;
        case 6:
          return "June";
        break;
        case 7:
          return "July";
        break;
        case 8:
          return "August";
        break;
        case 9:
          return "September";
        break;
        case 10:
          return "October";
        break;
        case 11:
          return "November";
        break;
        case 12:
          return "December";
        break;
    }
}
