﻿// JScript File
function ValidateFields()
{   
    //alert(document.getElementById("ddlcountry").value);
    return false;
}
function noListings(province)
{
    var alertmsg = 'Sorry there are currently no listings for ' + province
    alert(alertmsg);
}
function AddItemToCombo(ComboName,ComboValue,ComboText)
{
	var objCmbOptions=document.getElementById(ComboName);
	objCmbOptions.options[objCmbOptions.options.length] = new Option(ComboText,ComboValue);
}
function ClearComboBox(ComboName)
{

	var objCmbOptions=document.getElementById(ComboName);
	objCmbOptions.options.length=0;
	
}
function DoCallback(url, params)
{
	// url:    URL to invoke
	// params: string object to pass to the remote URL
	//Add some parameters to the query string
	var pageUrl = url;
	// Initialize the XmlHttp object
	try
	{
		//Mozilla Browsers
		xmlRequest = new XMLHttpRequest();
	}
	catch (e)
	{
		try
		{
			//IE
			xmlRequest = new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch (e)
		{
			//Something else that won't work with this code...
			xmlRequest=false;
		}
	}
	// Post our XmlRequest and get our desired string
	xmlRequest.open("POST", pageUrl, false);
	xmlRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	xmlRequest.send(params);
	// Return the XmlHttp object
	return xmlRequest;
}
function GetProv(iID,objCombo,txtString,txtValue,txtCommandName,tblname)
{
	var xml=new DoCallback('/XMLResponse.aspx','command='+ txtCommandName+ '&eventArgument=' + iID);
	var resp=xml.responseText;
	var resp1 =resp;
	var sPos=0;
	ClearComboBox(objCombo);
	AddItemToCombo(objCombo,0,'...Select...');
	while (1)
	{
		var intQueNo=GetNodeValue(resp,txtValue);
		var varQueDesc=GetNodeValue(resp,txtString);
		GetNodeValue(resp,tblname);
		if(NextRecPosition==0)
			break;
		else
		{
			AddItemToCombo(objCombo,intQueNo,varQueDesc);
			resp=resp.substring(NextRecPosition,resp.length);
		}
	}
}

function CheckUsers(txtEmail,txtCommandName)
{
    if(txtEmail.value!="")
    {
	    var xml=new DoCallback('/XMLResponse.aspx','command='+ txtCommandName+ '&eventArgument=' + txtEmail.value);
	    var resp=xml.responseText;
	    if (resp=='True')
	    {
	        alert("ID Already in Use");
	        txtEmail.value="";
	        txtEmail.focus();
	        return false;
	    }
	}
}
var NextRecPosition=0;
function GetNodeValue(FullText,NodeName)
{
	NextRecPosition=0;
	var LeftText="<" + NodeName + ">";
	var EndText="</" + NodeName + ">";
	var FString=new String(FullText);
	var sPos=0,EPos=0;
	sPos = FString.indexOf(LeftText);
	if(sPos==-1)
	{
		NextRecPosition=0;
		return '';
	}
	else
	{
		sPos=sPos+LeftText.length;
		ePos=FString.indexOf(EndText);
		if(ePos==-1)
		{
			return '';
			NextRecPosition=0;
		}
		else
		{
			NextRecPosition=ePos + EndText.length; 
			return FString.substring(sPos ,ePos);
		}  
	 }
}


// function to check for blank values.
function isBlank(s)
{
	  var len,k,flg;
	  flg=true;
	  if(s!=null)
	  {
		len=s.length;
		for(k=0;k<len;k++)
		 {
		  if(s.substring(k,k+1)!=" ")
		    flg=false;
		 }
	  }
	 return flg;
}


// function to check for the numbers
function validnum(mnum) 
{
	mlen=mnum.length;
	cnt=0;
	for (var i = 0; i < mlen; i++)	
	{
		if (mnum.substring(i,i+1) != 0) 
		{
			if (!parseInt(mnum.substring(i,i+1)))
				cnt++;
		}
	}
	if ((cnt>0))
		return 0;
	else
		return 1;
}

function MM_swapImgRestore() { //v3.0

  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;

}



function MM_preloadImages() { //v3.0

  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();

    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)

    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}

}



function MM_findObj(n, d) { //v4.0

  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {

    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}

  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];

  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);

  if(!x && document.getElementById) x=document.getElementById(n); return x;

}


function MM_swapImage() { //v3.0

  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)

   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}

}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

// Declaring valid date character, minimum year and maximum year
var dtCh= "-";
var minYear=1900;
var maxYear=2100;

function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}

function isDate(dtStr){
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strMonth=dtStr.substring(0,pos1)
	var strDay=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
		alert("The date format should be : mm/dd/yyyy")
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		alert("Please enter a valid month")
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		alert("Please enter a valid day")
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		alert("Please enter a valid date")
		return false
	}
return true
}

function ValidateForm(objText){
	if (isDate(objText.value)==false){
		return false
	}
    return true
 }
function AcceptTerms(objchk)
{
    if(objchk.checked==true)
    {
        return true;
    }
    else
    {
        alert('Click Agree Terms and Condition');
        return false;
    }
}
function UpdateListingStatus(iID,iMember,iStatus)
{
    var xml=new DoCallback('/XMLResponse.aspx','command=UpdateStatus&eventArgument=' + iID +'&memberID='+ iMember +'&salesStaus='+ document.getElementById(iStatus).value);
	var resp=xml.responseText;
	alert(resp);
}
function UpdateExpiryDate(iPostingNumber,iMember,dtExpiryDate)
{
    var xml=new DoCallback('/XMLResponse.aspx','command=UpdateExpiryDate&eventArgument=' + iPostingNumber +'&memberID='+ iMember +'&ExpiryDate='+ document.getElementById(dtExpiryDate).value);
	var resp=xml.responseText;
	alert(resp);
}
//-------------------------------------------------------------
// Select all the checkboxes (Hotmail style)
//-------------------------------------------------------------
function SelectAllCheckboxes(spanChk)
{
    // Added as ASPX uses SPAN for checkbox
    var oItem = spanChk.children;
	var theBox=oItem.item(0)
	xState=theBox.checked;
	elm=theBox.form.elements;
	for(i=0;i<elm.length;i++)
	    if(elm[i].type=="checkbox" && elm[i].id!=theBox.id)
	    {
	        if(elm[i].checked!=xState)
	        elm[i].click();
        }
}
//-------------------------------------------------------------
//----Select highlish rows when the checkboxes are selected
//
// Note: The colors are hardcoded, however you can use 
//       RegisterClientScript blocks methods to use Grid's
//       ItemTemplates and SelectTemplates colors.
//		 for ex: grdEmployees.ItemStyle.BackColor OR
//				 grdEmployees.SelectedItemStyle.BackColor
//-------------------------------------------------------------
function HighlightRow(chkB)
{
    var oItem = chkB.children;
    xState=oItem.item(0).checked;
    if(xState)
    {
        chkB.parentElement.parentElement.style.backgroundColor='lightcoral';  // grdEmployees.SelectedItemStyle.BackColor
        chkB.parentElement.parentElement.style.color='white'; // grdEmployees.SelectedItemStyle.ForeColor
    }
    else
    {
        chkB.parentElement.parentElement.style.backgroundColor='white'; //grdEmployees.ItemStyle.BackColor
        chkB.parentElement.parentElement.style.color='black'; //grdEmployees.ItemStyle.ForeColor
    }
}
function ClientValidate(source,arguments)
{
    if(arguments.Value==0)
    {
        arguments.IsValid=false;
    }
    else
    {
        arguments.IsValid=true;
    }
}
/*****************************************************************************************************
Created By: Sunil Ubale, Software Engineer
Created On: 18 April 2005
Last Modified: 
******************************************************************************************************/
//Generating Pop-up Print Preview page
function getPrint(print_area)
{
    //Creating new page
    var pp = window.open('/preview.htm');
    //Adding HTML opening tag with <HEAD> … </HEAD> portion
    pp.document.writeln('<HTML><HEAD><title>Print Preview</title>')
    //pp.document.writeln('<scr' + 'ipt language="Javascript" src="/Landmarketer/js/Script/common.js"></scr' + 'ipt>')
    pp.document.writeln('<LINK href="/DesktopModules/View_Images/PrintStyle.css"  type="text/css" rel="stylesheet" media="print, screen" /><base target="_self"></HEAD>')
    //Adding Body Tag
    pp.document.writeln('<body MS_POSITIONING="GridLayout" bottomMargin="0" leftMargin="0" topMargin="0" rightMargin="0">');
	//<object id="factory" viewastext  style="display:none" classid="clsid:1663ed61-23eb-11d2-b92f-008048fdd814" codebase="http://www.meadroid.com/scriptx/ScriptX.cab#Version=6,2,433,14"></object>
    //Adding form Tag
    pp.document.writeln('<form  method="post">');
    //Creating two buttons Print and Close within a table
    pp.document.writeln('<TABLE width=50%><TR><TD></TD></TR><TR><TD align=right><INPUT ID="PRINT" type="button" value="Print" onclick="window.print();"><INPUT ID="CLOSE" type="button" value="Close" onclick="window.close();"></TD></TR><TR><TD></TD></TR></TABLE><center><table width="700px" class="table_border"><tr><td><center>');
    //Writing print area of the calling page
    pp.document.writeln(document.getElementById(print_area).innerHTML.replace("width=760","width=100%"));
    //Ending Tag of </form>, </body> and </HTML>
    pp.document.writeln('</center></td></tr></table></center></form></body></HTML>');
    pp.document.close();
}

function BrowserCheck()
{
    var b = navigator.appName;
    if (b == "Netscape") this.b = "NS";
    else if (b == "Microsoft Internet Explorer") this.b = "IE";
    else this.b = b;
    this.v = parseInt(navigator.appVersion);
    this.NS = (this.b == "NS" && this.v>=4);
    this.NS4 = (this.b == "NS" && this.v == 4);
    this.NS5 = (this.b == "NS" && this.v == 5);
    this.IE = (this.b == "IE" && this.v>=4);
    this.IE4 = (navigator.userAgent.indexOf('MSIE 4')>0);
    this.IE5 = (navigator.userAgent.indexOf('MSIE 5')>0);
    if (this.IE5 || this.NS5) this.VER5 = true;
    if (this.IE4 || this.NS4) this.VER4 = true;
    this.OLD = (! this.VER5 && ! this.VER4) ? true : false;
    this.min = (this.NS||this.IE);
}
    /*is = new BrowserCheck();
    alertBox = (is.VER5) ? document.getElementById("alertLayer").style : (is.NS) ? document.layers["alertLayer"] : document.all["alertLayer"].style;*/
function hideAlert()
{
    alertBox.visibility = "hidden";
}

function makeAlert(aTitle,aMessage)
{
    document.getElementById('alertLayer').innerHTML = "<table border=0 width=100% height=100%>" +
    "<tr height=5><td colspan=4 class=alertTitle>" + " " + aTitle + "</td></tr>" +
    "<tr height=5><td width=5></td></tr>" +
    "<tr><td width=5></td><td width=20 align=left><img src='images/alert.gif'></td><td align=center class=alertMessage>" + aMessage + "<BR></td><td width=5></td></tr>" + 
    "<tr height=5><td width=5></td></tr>" +
    "<tr><td width=5></td><td colspan=2 align=center><input type=button value='OK' onClick='hideAlert()' class=okButton><BR></td><td width=5></td></tr>" +
    "<tr height=5><td width=5></td></tr></table>";
    thisText = aMessage.length;
    if (aTitle.length > aMessage.length)
    {
        thisText = aTitle.length; 
    }
    aWidth = (thisText * 5) + 80;
    aHeight = 100;
    if (aWidth < 150){ aWidth = 200; }
    if (aWidth > 350){ aWidth = 350; }
    if (thisText > 60){ aHeight = 110; }
    if (thisText > 120){ aHeight = 130; }
    if (thisText > 180){ aHeight = 150; }
    if (thisText > 240){ aHeight = 170; }
    if (thisText > 300){ aHeight = 190; }
    if (thisText > 360){ aHeight = 210; }
    if (thisText > 420){ aHeight = 230; }
    if (thisText > 490){ aHeight = 250; }
    if (thisText > 550){ aHeight = 270; }
    if (thisText > 610){ aHeight = 290; }
    alertBox.width = aWidth;
    alertBox.height = aHeight;
    alertBox.left = (document.body.clientWidth - aWidth)/2;
    alertBox.top = (document.body.clientHeight - aHeight)/2;
    alertBox.visibility = "visible";
}
var da = (document.all) ? 1 : 0;
var pr = (window.print) ? 1 : 0;
var mac = (navigator.userAgent.indexOf("Mac") != -1); 

function myprint() 
{
  //save existing user's info
  var h = factory.printing.header;
  var f = factory.printing.footer;
  //hide the button
  //document.all("printbtn").style.visibility = 'hidden';
  //set header and footer to blank
  factory.printing.header = "";
  factory.printing.footer = "";
  //print page with prompt
  print();
  //factory.DoPrint(true);
  //restore user's info
  factory.printing.header = h;
  factory.printing.footer = f;
  //show the print button
  //document.all("printbtn").style.visibility = 'visible';  
}

function printPage() {
  if (pr) // NS4, IE5
  // parent.Bottom.print()
  //	print()
    {
		//window.parent.Middle.focus();
		//window.parent.content.focus();
		myprint() //changed to hide header and footer on the page
	}	
  //else if (da && !mac) // IE4 (Windows)
    //vbPrintPage()
  else // other browsers
    {
	  alert("Sorry, your browser does not support this feature.");
      return false;
	}  
  }
  
function win_open(theURL) { 
    alert(theURL);
    window.open(theURL);
}

