function openLink(link)
{
	window.open(link)
}

function changeColor(id)
{
	document.getElementById(id).style.backgroundColor="#507cd1"
	document.getElementById(id).style.color="white"
}
function changeColorBack(id, color)
{
	document.getElementById(id).style.backgroundColor=color
	document.getElementById(id).style.color="black"
}

function getImgName(src)
{
	return src.substring(src.lastIndexOf("/")+1);
}

function checkText(id)
{
	if (document.getElementById(id).value=="")
		document.getElementById("val_"+id).innerHTML = "<img src='images/error.png' class='val_icon'>"
	else
		document.getElementById("val_"+id).innerHTML = ""
}
function checkCase(id)
{
	document.getElementById(id).value = document.getElementById(id).value.substring(0,1).toUpperCase()+document.getElementById(id).value.substring(1)
}

function showModal(id)
{
	var modalbg = document.getElementById("modal")
	modalbg.style.display = "block";
	modalbg.style.width = document.documentElement.clientWidth + 15;
	modalbg.style.height = document.body.scrollHeight + 15;
	
	var modal = document.getElementById(id);
	modal.style.display = "block";
	
	document.body.style.overflow = "hidden";
	
	var windowWidth = document.documentElement.clientWidth;
    var windowHeight = document.documentElement.clientHeight;
    
    var popupHeight = modal.offsetHeight;
	var popupWidth = modal.offsetWidth;
	
	if(popupHeight>windowHeight)
	{
		popupHeight=windowHeight - 50
		modal.style.height=windowHeight - 50
		modal.style.overflow = "auto";
		
		try
		{
			document.getElementById("div_modalDetails").style.height = windowHeight - 170
			document.getElementById("div_modalDetailsEst").style.height = windowHeight - 50
		}
		catch(e)
		{
		}
	}
    
    modal.style.left = windowWidth/2-popupWidth/2;
    modal.style.top = document.documentElement.scrollTop+(windowHeight/2-popupHeight/2);
}
function closeModal(id)
{
	document.getElementById("modal").style.display = "none";
	document.getElementById(id).style.display = "none";
	
	document.body.style.overflow = "auto";
}

function getCookie(name) 
{
	var start = document.cookie.indexOf( name + "=" );
	var len = start + name.length + 1;
	
	if (!start && (name != document.cookie.substring( 0, name.length )))
	{
		return null;
	}
	if ( start == -1 ) return null;
	var end = document.cookie.indexOf( ";", len );
	if ( end == -1 ) end = document.cookie.length;
	return unescape( document.cookie.substring( len, end ) );
}

function checkEmail(id)
{
	document.getElementById("val_"+id).innerHTML="<img src='images/ajax-loader.gif' class='val_icon'>"
	
	var xmlhttp=new GetXmlHttpObject();

	if (xmlhttp==null)
	{
		alert ("Your browser does not support XMLHTTP");
		return;
	}
	
	xmlhttp.onreadystatechange= function()
	{
		if (xmlhttp.readyState==4)
		{
			if(xmlhttp.responseText==0)
			{
				document.getElementById("val_"+id).innerHTML=""
				
				if(email=="")
					document.getElementById("val_"+id).innerHTML="<img src='images/error.png' class='val_icon'>"
			}
			else
				document.getElementById("val_"+id).innerHTML="<img src='images/error.png' class='val_icon'><span style='margin-left: 20px'><b>Email exists</b>"
		}
	}

	dt = new Date().getTime()
	var email = document.getElementById(id).value
	
	xmlhttp.open("GET", "app_code/checkEmail.php?email="+email+"&dt="+dt, true);
	xmlhttp.send(null);
}

function changeCheckColor(id)
{
	if(document.getElementById("col1_"+id).style.backgroundColor=="white")
	{
		document.getElementById("col1_"+id).style.backgroundColor="#FFEECC"
		document.getElementById("col2_"+id).style.backgroundColor="#FFEECC"
	}
	else
	{
		document.getElementById("col1_"+id).style.backgroundColor="white"
		document.getElementById("col2_"+id).style.backgroundColor="white"
	}
}
