var PopupWindow = ""
var NumClick = 2
//************************************************************************************************
function OpenPopUp(windowsname,address,width,height,scrollbars,resizable)
{
	var w = 480, h = 340;
		
	if (document.all || document.layers)
	{
	   w = screen.availWidth;
	   h = screen.availHeight;
	}
	
	var popW = width, popH = height;
	
	var leftPos = (w-popW)/2, topPos = (h-popH)/2;
	
	if(PopupWindow)
	{
		if(!PopupWindow.closed)
		{
			PopupWindow.close();
		}
	}
	PopupWindow = window.open(address, windowsname,'width=' + popW + ',height=' + popH + ',top=' + topPos + ',left=' + leftPos + ',scrollbars=' + scrollbars + ',resizable=' + resizable + ',status=0,toolbar=0,location=0,menubar=0,directories=0');
	PopupWindow.focus();
}

//************************************************************************************************
function funcValidate(strField,strFieldLimitation)
{
	if(!strField) return false;
	var Chars = strFieldLimitation
	
	for (var i = 0; i < strField.length; i++)
	{
		if (Chars.indexOf(strField.charAt(i)) == -1)
		{
			alert("Please enter number field");
			return false;
		}
	}	
}

//************************************************************************************************
function SelectAll(amount,formName,fieldName)
{
	for(i=0; i < amount; i++)
	{
		strSelected = 'document.' + formName + '.' + fieldName + '[' + i + '].selected=true;'
		eval(strSelected);
	}
}

//************************************************************************************************
function DeSelectAll(amount,formName,fieldName)
{
	for(i=0; i < amount; i++)
	{
		strSelected = 'document.' + formName + '.' + fieldName + '[' + i + '].selected=false;'
		eval(strSelected);
	}
}

//************************************************************************************************
function defaultFocus()
{
	if (document.forms[0][0])
			document.forms[0][0].focus();
}

//************************************************************************************************
function funcValidate(strField,strFieldLimitation)
{
	if(!strField) return false;
	var Chars = strFieldLimitation
	
	for (var i = 0; i < strField.length; i++)
	{
		if (Chars.indexOf(strField.charAt(i)) == -1)
		{
			alert("Please enter number field");
			return false;
		}
	}	
}
/**
 * DHTML email validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */
function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("Invalid email address")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid email address")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Invalid email address")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid email address")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid email address")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid email address")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Invalid email address")
		    return false
		 }

 		 return true					
	}

function ValidateForm(strEmail){
	var emailID=eval(strEmail)
	if (echeck(emailID.value)==false){
		emailID.value=""
		emailID.focus()
		return false
	}
	return true
 }
 
//************************************************************************************************ 
function show(object, strFrameName, strWebPage) {
	i = NumClick++
	if (document.getElementById && document.getElementById(object) != null)
		{
			node = document.getElementById(object).style.visibility = 'visible';
			if(strFrameName != "" && strWebPage != "")
			{
				node = document.getElementById(strFrameName).src = strWebPage
			}
			node = document.getElementById(object).style.zIndex = i;
		}    
    else if (document.layers && document.layers[object] != null)
        {
			document.layers[object].visibility = 'visible';
			if(strFrameName != "" && strWebPage != "")
			{
				document.layers[strFrameName].location.href = strWebPage
			}
			document.layers[object].zIndex = i;
        }
    else if (document.all)
        {
			document.all[object].style.visibility = 'visible';
			if(strFrameName != "" && strWebPage != "")
			{
				document.all[strFrameName].location.href = strWebPage	
			}
			document.all[object].style.zIndex = i;
		}
}

//************************************************************************************************
function hide(object) {
    if (document.getElementById && document.getElementById(object) != null)
         node = document.getElementById(object).style.visibility='hidden';
    else if (document.layers && document.layers[object] != null)
        document.layers[object].visibility = 'hidden';
    else if (document.all)
         document.all[object].style.visibility = 'hidden';
}

//**************************************************************************************************************
function y2k(number) { return (number < 1000) ? number + 1900 : number; }
var reason = '';

//**************************************************************************************************************
function isValidDate (myDate,sep) {
// checks if date passed is in valid dd/mm/yyyy format

    if (myDate.length == 10) {
        if (myDate.substring(2,3) == sep && myDate.substring(5,6) == sep) {
            var date  = myDate.substring(3,5);
            var month = myDate.substring(0,2);
            var year  = myDate.substring(6,10);

            var test = new Date(year,month-1,date);

            if (year == y2k(test.getYear()) && (month-1 == test.getMonth()) && (date == test.getDate())) {
                reason = '';
                return true;
            }
            else {
                reason = 'valid format but an invalid date';
                return false;
            }
        }
        else {
            reason = 'invalid spearators';
            return false;
        }
    }
    else {
        reason = 'invalid length';
        return false;
    }
}

//**************************************************************************************************************
function tellMeIfInvalid(myDate) {
    if (isValidDate(myDate,'/'))
	{
		return true;
	}
    else
	{
        return false;
	}
		
}

//**************************************************************************************************************
function noRightClick() 
{
	var ie=(document.all);
	var ns=(document.layers);
	var ns6=(document.getElementById && !ie);
	
	strMessage = "Please contact Ky Signature Portraits for the use of pictures.";

	function IE() {
		if (event.button > 1)
		{ 
			alert(strMessage);
			return false;
		}
	}
	function NS(e) {
		if (document.layers || (document.getElementById && !document.all))
		{
			if (e.which > 1)
			{ 
				alert(strMessage);
				return false;
			}
		}
	}
	document.onmousedown=IE;
	document.onmouseup=NS;
	document.oncontextmenu=new Function("return false");
	
}



