var popupWin = null;

function openPopup() {
	var url = "popup.htm"
	if( !popupWin || popupWin.closed ) {
		popupWin = window.open( url, "popupWin", "width=400,height=200" );
	} else popupWin.focus();
}

function LoginError()
{
alert("We could not find your username/password.\n\nContact the administrator.");
window.location = "default.aspx"
}

function LoginSuccess(UserName,DateAndTime, refURL) 
{ 
var OK; 
OK = confirm("Successfully logged in as " + UserName + " at " + DateAndTime);

if (OK){
     window.location = "default.aspx?" + refURL;
     }
else
{
	window.location = "default.aspx"
}
}

function SMSProgress()
{
   var ProgressWindow;
   // Display topic in named window.
   ProgressWindow = window.open("SMSProgress.aspx", 
     "Progresswin","toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=425,height=250,left=0,top=0");
   // Displays the window on top.
   ProgressWindow.focus();
   
   return true;
}

function EmailProgress()
{
   var ProgressWindow;
   // Display topic in named window.
   ProgressWindow = window.open("emailprogress.aspx", 
     "Progresswin","toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=500,height=200,left=0,top=0");
   // Displays the window on top.
   ProgressWindow.focus();
   
   return true;
}


function preview(templatetype)
{

//alert('This may take a few seconds');

//pausecomp(2000);
	
   var PreviewWindow;
   // Display topic in named window.
   PreviewWindow = window.open("preview.aspx?templatetype=" + templatetype, 
     "Previewwin","toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=800,height=800,left=0,top=0");
   // Displays the window on top.
   PreviewWindow.focus();
   
   return true;
}

function pausecomp(Amount)
    {
    d = new Date() //today's date
    while (1)
        {
        mill=new Date() // Date Now
        diff = mill-d //difference in milliseconds
        if( diff > Amount ) {break;}
        }
    }

function previewmain(contentid)
{
   var PreviewWindow;
   // Display topic in named window.
   PreviewWindow = window.open("maincontent.aspx?contentid=" + contentid + "&contactid=0&showback=false", 
     "Previewwin","toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=700,height=500,left=0,top=0");
   // Displays the window on top.
   PreviewWindow.focus();
   
   return true;
}

function validateCellPhone(objCapture){
	var Mobile = objCapture.value
	if (Mobile ==""){
		return
	}
	else{
	
		if (Mobile.substring(0,3)!="082" && Mobile.substring(0,3)!="083" && Mobile.substring(0,3)!="076" && Mobile.substring(0,3)!="084" && Mobile.substring(0,3)!="072" && Mobile.substring(0,3)!="073" && Mobile.substring(0,3)!="074"){
			alert("Please check Cell phone number - it does not appear to be valid. (082 xxx xxxx)")
			objCapture.focus();
            return false;
		}
	}
}

function ConfirmDeleteContacts() 
{ 
var Delete; 
Delete = confirm('Are you sure you want to permanently delete the selected contact(s)?'); 

if (Delete){
     return true;
     }
else
	{
	return false;
	}
}

function ConfirmDeleteContent() 
{ 
var Delete; 
Delete = confirm('Are you sure you want to permanently delete the selected content?'); 

if (Delete){
     return true;
     }
else
	{
	return false;
	}
}

function ConfirmDeleteLookupItem() 
{ 
var Delete; 
Delete = confirm('Are you sure you want to permanently delete this item?'); 

if (Delete){
     return true;
     }
else
	{
	return false;
	}
}

function ConfirmDeleteProperties() 
{ 
var Delete; 
Delete = confirm('Are you sure you want to permanently delete the selected properties, as well as ALL of stock of the property?'); 

if (Delete){
     return true;
     }
else
	{
	return false;
	}
}

function ConfirmDeleteStock() 
{ 
var Delete; 
Delete = confirm('Are you sure you want to permanently delete this stock?'); 

if (Delete){
     return true;
     }
else
	{
	return false;
	}
}

function TakeAWhile() 
{ 
var AWhile; 
AWhile = confirm('This may take a little while...'); 

if (AWhile){
     return true;
     }
else
	{
	return false;
	}
}

function CheckSMSLength(Target) {;StrLen = Target.value.length;if (StrLen > 160 ) {Target.value = Target.value.substring(0,160);charsLeft = 0;}else {charsLeft = 160 - StrLen;}document.all.objSMS_charsLeft.value = charsLeft;}

if(window.attachEvent)
    window.attachEvent("onload",setListeners);

  function setListeners(){
    inputList = document.getElementsByTagName("INPUT");
    for(i=0;i<inputList.length;i++){
      inputList[i].attachEvent("onpropertychange",restoreStyles);
      inputList[i].style.backgroundColor = "";
    }
    selectList = document.getElementsByTagName("SELECT");
    for(i=0;i<selectList.length;i++){
      selectList[i].attachEvent("onpropertychange",restoreStyles);
      selectList[i].style.backgroundColor = "";
    }
  }

  function restoreStyles(){
    if(event.srcElement.style.backgroundColor != "")
      event.srcElement.style.backgroundColor = "";
  }
  
 function numbersonly(myfield, e)
				{
				var key;
				var keychar;

				if (window.event)
				key = window.event.keyCode;
				else if (e)
				key = e.which;
				else
				return true;
				keychar = String.fromCharCode(key);

				// control keys
				if ((key==null) || (key==0) || (key==8) || 
					(key==9) || (key==13) || (key==27) )
				return true;

				// numbers
				else if ((("0123456789").indexOf(keychar) > -1))
				return true;
				else
				return false;
}


function CheckSearch()
{
	var PriceFrom;
	var PriceTo;

	PriceFrom = document.all.ddlMinPrice.options[document.all.ddlMinPrice.selectedIndex].value;
	PriceTo = document.all.ddlMaxPrice.options[document.all.ddlMaxPrice.selectedIndex].value;
	
	if (PriceTo == 0){
	PriceTo = 100000;
	}
	
	if (parseFloat(PriceFrom) > parseFloat(PriceTo)){
	alert("'Price From' must be less than or equal to 'Price To'.");
	return false;
	}
	else
	{
	return true;
	}
}