// -------------------------------------------------------------------
//  validate subscription detail
// -------------------------------------------------------------------

function isSubscribeValid(){
	var errormessage ='';
	//var re= new RegExp("([a-zA-Z0-9_\.\-])+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3})(\]?)$");
	var reg = /^([a-zA-Z0-9_\.\-])+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,4})(\]?)$/; 
	if (document.getElementById('txtName').value=="")
		errormessage = "Please enter your name"+"\n";
	if (document.getElementById('txtEmail1').value=="")
		errormessage += "Please enter your email address"+"\n";
	else if (!document.getElementById('txtEmail1').value.match(reg))
		errormessage +="Please enter a valid email address"+"\n";
	else 
	{
		if (document.getElementById('txtEmail2').value=="")
			errormessage +="Please enter your email again to verify"+"\n";
		else if (document.getElementById('txtEmail1').value!=document.getElementById('txtEmail2').value)
			errormessage +="Please make sure that you verify the email correctly"+"\n";
		//else if (!document.getElementById('chkHekupu').checked && !document.getElementById('chkEcelearn').checked)
			//errormessage +="Please click one of the subscription option"+"\n";
	}
	
	if (errormessage!='')
	{
		alert(errormessage);
		return false;
	}
	else
	{
		
		var country = getDropDownBoxTextByValue(document.getElementById('optCountry'));
		//alert(country);
		document.getElementById('hidCountry').value = country;
		//document.getElementById('subscribe_form').submit();
		return true;
	}
}

// -------------------------------------------------------------------
//  get drop-down box option text
// -------------------------------------------------------------------
function getDropDownBoxTextByValue(obj)
{
	for (i=0; i<obj.options.length; i++) {
		if (obj.options[i].value == obj.value)
			return obj.options[i].text;
	}
}

// -------------------------------------------------------------------
// Returns the width of the current page
// -------------------------------------------------------------------
function GetPageHeight()
{
    if(window.innerHeight)
    {
        return window.innerHeight;
    }
    else if(document.documentElement && document.documentElement.clientHeight)
    {
        return document.documentElement.clientHeight;
    }
    else if(document.body && document.body.clientHeight)
    {
        return document.body.clientHeight;
    }
    return 0;
}

// -------------------------------------------------------------------
// Returns the width of the current page
// -------------------------------------------------------------------
function GetPageWidth()
{
    if(window.innerWidth)
    {
        return window.innerWidth;
    }
    else if(document.documentElement && document.documentElement.clientWidth)
    {
        return document.documentElement.clientWidth;
    }
    else if(document.body && document.body.clientWidth)
    {
        return document.body.clientWidth;
    }
    return 0;
}        

// -------------------------------------------------------------------
// Returns the y position of the current page
// -------------------------------------------------------------------
function GetPageY()
{
    if(!isNaN(window.screenTop)) {
        return window.screenTop;
    }
    var y = window.screenY + (window.outerHeight - window.innerHeight);
    if(!isNaN(y)) {
        return y;
    }
    return 0;
}

// -------------------------------------------------------------------
// Returns the x position of the current page
// -------------------------------------------------------------------
function GetPageX()
{
    if(!isNaN(window.screenLeft)) {
        return window.screenLeft;
    }
    var x = window.screenX + (window.outerWidth - window.innerWidth);
    if(!isNaN(x)) {
        return x;
    }
    return 0;
}

// -------------------------------------------------------------------
//  open a new browser window
// -------------------------------------------------------------------
function OpenLinkWindow(url)
{
	var popupWindow = null;
	
    if(popupWindow && !popupWindow.closed) {
        popupWindow.focus();
        if(popupWindow.location != url) {
            popupWindow.location = url;
        }
        return;
    }
    var top =100;//60;
    var left = 190;//150;
    var height = GetPageHeight() - top - 220 ;//450
    var width = GetPageWidth() - left -220;//800
    top += GetPageY();
    left += GetPageX();
    
    popupWindow = window.open(url,"linkWindow","width=" + width + ",height=" + height + ",scrollbars=yes,resizable=yes,location=yes,left=" + left + ",top=" + top + ",screenX=" + left + ",screenY=" + top);
}

// Click a button
// used to perform a button click on a specific button when the enter key is hit inside a textbox
// otherwise, asp.net will click the form's default button
function ClickButton(e, buttonID)
{
    if(!e)
    {
        e = window.event;
    }
    if (e.keyCode != 13)
    {
        return true;
    }
    var btn = document.getElementById(buttonID);
    if(!btn)
    {
        return true;
    }
    btn.click();
    return false;
}
