document.getElementsByClassName = function(className, parent){
	
	if(!parent){
		parent = window.document;
	}
	
	
	elements = parent.getElementsByTagName('*');
	felements = new Array();
	
	temp = '\\b' + className + '\\b';
	temp = new RegExp(temp);
	
	for(i=0, j=0; i<elements.length; i++){
		str = elements[i].className.match(temp);
		if(str){
			felements[j] = elements[i];
			j++;
		}
	}
	
	
	return felements;
}

var last_clicked = false;
function init(elem_name){
	
	var buff = document.getElementsByClassName(elem_name);
	
	for(i=0; i<buff.length; i++){
		buff[i].onclick = function(){
			if(last_clicked != false){
				last_clicked.style.backgroundColor = "";
			}
			
			
			this.style.backgroundColor = "#fffcd3";
			last_clicked = this;
			
			if(this.href != undefined){
				window.location = this.href;
			}
			else{
				this.action.submit();			
			}
		}
		
		
		childs = buff[i].childNodes;
		
		for(j=0; j<childs.length; j++){
			
			if(childs[j].nodeName == 'A'){
				buff[i].href = childs[j].href;
			}
			else if(childs[j].nodeName == 'FORM'){
				buff[i].action = childs[j];
			}
			else if(childs[j].className == "text"){
				in_child = childs[j].childNodes;
				buff[i].href = in_child[1].href;
			}
		}
	}
}



function setcookie(cookieName,cookieValue,nDays) {
 var today = new Date();
 var expire = new Date();
 if (nDays==null || nDays==0) nDays=1;
 expire.setTime(today.getTime() + 3600000*24*nDays);
 document.cookie = cookieName+"="+escape(cookieValue)
                 + ";expires="+expire.toGMTString();
}

function getCookie(name) {
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1) {
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
    } else {
        begin += 2;
    }
    var end = document.cookie.indexOf(";", begin);
    if (end == -1) {
        end = dc.length;
    }
    return unescape(dc.substring(begin + prefix.length, end));
}

function show_iphone_popup()
{
  if((navigator.userAgent.match(/iPhone/i)))
	{
		if(!getCookie('iphone_popup') || getCookie('iphone_popup') != 'hide')
		{
			document.getElementById('iphone_popup').style.display = '';
		}
	}

}

function hide_iphone_popup()
{
	setcookie('iphone_popup', 'hide', 30);
	document.getElementById('iphone_popup').style.display = 'none';
}
window.onload = function(){

    for(var i=0; i<document.forms.length; i++){
		if(document.forms[i].name=='main_redirect'){
		   document.forms[i].elements['redirect'].onmouseover = function(){this.style.color='#8C0E00';}
		   document.forms[i].elements['redirect'].onmouseout = function(){this.style.color='#1C56A5';}
		}
  	}
}


