function popwin(page,wid,hght,winname){
    window.open(page, winname, "width="+wid+",height="+hght+",scrollbars=no");
}

function popwins(page,wid,hght,winname){
    mynewwin = window.open(page, winname, "width="+wid+",height="+hght+",left=360,top=0,scrollbars=yes,resizable=no"); 
    mynewwin.opener.name = "opener";
    mynewwin.focus();
}

function popwinsImg(page,wid,hght,winname){ // Added to have control over the popup window position
    mynewwin = window.open(page, winname, "width="+wid+",height="+hght+",left=400,top=100,scrollbars=no,resizable=no,"); 
    mynewwin.opener.name = "opener";
    mynewwin.focus();
}

function popUserDet(page,wid,hght,winname){ // Added by KCP to have control on view of user details in admin
    mynewwin = window.open(page, winname, "width="+wid+",height="+hght+",left=400,top=100,scrollbars=no,resizable=no,"); 
    mynewwin.opener.name = "opener";
    mynewwin.focus();
}

function popStdWinUserDet(page, winname){
	popUserDet(page, 350, 420, winname) //Added by KCP on 11.07.2008 to pop up the page for image for sale
}

function popUserDetOnly(page,wid,hght,winname){ // Added by KCP to have control on view of user details in admin
    mynewwin = window.open(page, winname, "width="+wid+",height="+hght+",left=400,top=100,scrollbars=no,resizable=no,"); 
    mynewwin.opener.name = "opener";
    mynewwin.focus();
}
function popUserDeteleOnly(page,wid,hght,winname){ // Added by KCP to have control on view of user details in admin
    mynewwin = window.open(page, winname, "width="+wid+",height="+hght+",left=250,top=350,scrollbars=no,resizable=no,"); 
    mynewwin.opener.name = "opener";
    mynewwin.focus();
}
function popStdWinUserDetOnly(page, winname){
	popUserDetOnly(page, 350, 400, winname) //Added by KCP on 11.07.2008 to pop up the page for image for sale
}

function popStdWinDetOnly(page, winname){
	popUserDeteleOnly(page, 330, 95, winname) //Added by KCP on 11.07.2008 to pop up the page for image for sale
}

function popStdWinImg(page, winname)
	{
		popwinsImg(page, 510, 435, winname) //Added by KCP on 24.Apr.2008 to pop up the page for image for sale
	}

function popStdWin(page, winname)
	{
		popwins(page, 550, 710, winname) //Changed by KCP on 11.Apr.2008 to adjust the size of popup
	}

function popFAQWin(page, winname) {
    popwins(page, 800, 710, winname) //Changed on 04/02/2009 to adjust the size of popup
}
	
function popSizeWin(page, winname)
	{
		popwins(page, 550, 710, winname)	//Changed by KCP on 11.Apr.2008 to adjust the size of popup
	}
	
function popBigWin(page, winname)
	{
	//Don't specify any properties for window opening and it will just open a standard IE window,
	//specify any requirements and it will use those and copy the remaining requirements from the
	//current (opening) window
	mynewwin = window.open(page, winname, "")
	if (mynewwin != null)
		{
		mynewwin.opener.name = "opener";
		}
    mynewwin.focus();
	}


// Deprecated, use preloadImages()
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];}}
}

// Deprecated, use swapImageRestore()
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;
}

//Deprecated, use findObj()
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;
}

// Deprecated, use swapImage()
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_showHideLayers() { //v3.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v='hide')?'hidden':v; }
    obj.visibility=v; }
}

function ddjump(jumpvalue)
{
    eval("document.location.href = '" + jumpvalue + "'")
}


function mOver(Item, className) {
Item.className = className;
}

function mOut(Item) {
Item.className = "";
}

function preloadImages()
	{
	var doc = document;
	if	(doc.images)
		{
		if(!doc.imageArray)
			{
			doc.imageArray = new Array();
			}
		}

	var argIndex;
	var imagesStoredCount = doc.imageArray.length;
	var args = preloadImages.arguments;
	for(argIndex = 0; argIndex < args.length; argIndex++)
		{
		if (args[argIndex].indexOf("#")!=0)
			{
			doc.imageArray[imagesStoredCount] = new Image;
			doc.imageArray[imagesStoredCount++].src = args[argIndex];
			}
		}
	}

function swapImageRestore()
	{
	var i;
	var x;
	var a = document.MM_sr;
	for(i = 0; a && i < a.length && (x = a[i])&& x.oSrc; i++)
		{
		x.src = x.oSrc;
		}
	}

function openWindow(theURL, winName, features)
	{
	window.open(theURL, winName, features);
	}

function findObj(n, d)
	{
	var p;
	var i;
	var 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= findObj(n, d.layers[i].document);
		}
	if(!x && document.getElementById)
		{
		x=document.getElementById(n);
		}
	return x;
	}

function swapImage()
	{
	var i;
	var j = 0;
	var x;
	var args = swapImage.arguments;
	document.MM_sr = new Array;
	for(i = 0; i < (args.length - 2);i += 3)
		{
		if ((x = findObj(args[i]))!=null)
			{
			document.MM_sr[j++] = x;
			if (!x.oSrc)
				{
				x.oSrc=x.src;
				}
			x.src=args[i+2];
			}
		}
	}
	
function validateForm()
	{
	var i;
	var p;
	var q;
	var nm;
	var test;
	var num;
	var min;
	var max;
	var errors = '';
	var args = validateForm.arguments;
  	
	for (i=0; i<(args.length-2); i+=3)
		{
		test = args[i+2];
		val = findObj(args[i]);
		if (val)
			{
			nm=val.name;
			if ((val=val.value)!="")
				{
				if (test.indexOf('isEmail')!=-1)
					{
					p=val.indexOf('@');
					if (p<1 || p==(val.length-1))
						{
						errors+='- '+nm+' must contain an e-mail address.\n';
						}
					}
				else
					{
					if (test!='R')
						{
						if (isNaN(val))
							{
							errors+='- '+nm+' must contain a number.\n';
							}
						if (test.indexOf('inRange') != -1)
							{
							p=test.indexOf(':');
							min=test.substring(8,p);
							max=test.substring(p+1);
							if (val < min || max < val)
								{
								errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
								}
							}
						}
					}
				}
			else
				{
				if (test.charAt(0) == 'R')
					{
					errors += '- '+nm+' is required.\n';
					}
				}
			}
		} 
		
	// If there are errors
	if (errors) 
	{
		alert('Please complete the following fields :\n\n' +errors);
		return false;
	}
	else
	{
  		return true;
	}
}

function blink(blinkOnColour, blinkOffColour)
	{
	if (document.all.blink != null)
		{
		if (document.all.blink.length == null)
			{
			if( document.all.blink.style.color == blinkOffColour)
				{
				document.all.blink.style.color = blinkOnColour;
				}
			else
				{
				document.all.blink.style.color = blinkOffColour;
				}
			}
		else
			{
			for(i=0;i<document.all.blink.length;i++)
				{
				if( document.all.blink(i).style.color == blinkOffColour)
					{
					document.all.blink(i).style.color = blinkOnColour;
					}
				else
					{
					document.all.blink(i).style.color = blinkOffColour;
					}
				}
			}
		}
	}
	
function reloadOpener()
	{
	if (opener != null)
		{
		opener.location.reload()
		}
	}
	
function isIE()
{
	if (-1 != navigator.appName.indexOf('Microsoft'))
	{
		return true;      
	}      
	else
	{
		return false;
	}
}

function scrollToAnchor(anchorNumber)
{
	//window.alert("calcing scroll value");
	var y = 0;
	
	//Scroll to top
	window.scrollTo(0, 0);
	
	//Determine the offset value of the anchor
	y = getTrueOffsetTop(document.anchors[anchorNumber]);
	//window.alert("About to scroll");
	//Scroll to the anchor (with the anchor at the top of the window, not the bottom)
	window.scrollTo(0, y);
	//window.alert("scrolled");
}

function getTrueOffsetTop(ctl)
{
	var parentOffsetVal;
	var total;
	if (ctl.offsetParent != null)
	{
		parentOffsetVal = getTrueOffsetTop(ctl.offsetParent);
	}
	else
	{
		parentOffsetVal = 0;
	}
	total = parentOffsetVal + ctl.offsetTop;
	
	return total;
}

function GetElementClientId(partNameToFind, tagName) {
    var elems = top.document.getElementsByTagName(tagName);
    var id = '';
    for (var i = 0; i < elems.length; i++) {
        if (elems[i].id.indexOf(partNameToFind) > 0) {
            id = elems[i].id;
        }
    }
    return id;
}

function modalCloseButtonClickMaintainScroll(){
    //top.document.cookie = top.document.documentElement.scrollTop;

    var btnClose = top.document.getElementById(GetElementClientId('btnCloseModal', 'input'));
    if (btnClose != null) {
        btnClose.click();
    }
    else { //must have somehow got out of modal functionality and actually want to close this window.
    
        //window.opener.location.reload();
        window.close();
    }
}

function modalCloseButtonClick(){
    var btnClose = top.document.getElementById(GetElementClientId('btnCloseModal', 'input'));
    if (btnClose != null) {
        btnClose.click();
    }
    else { //must have somehow got out of modal functionality and actually want to close this window.
        window.opener.location.reload();
        window.close();
    }
}

function modalCloseButtonClickRedirect(redirectURL) {
    var modalIFrame = top.document.getElementById(GetElementClientId('modalIframe', 'iframe'));
    if (redirectURL != null && redirectURL != '') {
        modalIFrame.src = redirectURL;
    }
}


function modalShowButtonClick() {
    var btnShow = top.document.getElementById(GetElementClientId('btnShowModal', 'input'));
    if (btnShowPopup != null) {
        btnShowPopup.click();
    }
}

function showModalPopup(url) {
    var modalIFrame = top.document.getElementById(GetElementClientId('modalIframe', 'iframe'));
    var btnShowPopup = top.document.getElementById(GetElementClientId('btnShowModal', 'input'));
    if (modalIFrame != null) {
        setModalPopupSize(modalIFrame);
        if (url != null && url != '') {
            modalIFrame.src = url;
        }
    }
    if (btnShowPopup != null) {
        btnShowPopup.click();
    }
}

function showModalPopupOffline(url) {
    var modalIFrame = top.document.getElementById(GetElementClientId('modalIframe', 'iframe'));
    var btnShowPopup = top.document.getElementById(GetElementClientId('btnShowModal', 'input'));
    if (modalIFrame != null) {
        setModalPopupSizeOffline(modalIFrame);
        if (url != null && url != '') {
            modalIFrame.src = url;
        }
    }
    if (btnShowPopup != null) {
        btnShowPopup.click();
    }
}

function setModalPopupSize(mdlFrame) {
    //mdlFrame.width = (document.documentElement.clientWidth * 17) / 24;
    //mdlFrame.height = (document.documentElement.clientHeight * 17) / 24;
}

function setModalPopupSizeOffline(mdlFrame) {
    mdlFrame.width = 450;  //(document.documentElement.clientWidth) * 50 / 100;
    mdlFrame.height = 550;  //(document.documentElement.clientHeight * 75) / 100;
}

function resizeModalPopup(mdlFrameId) {
    var modalIFrame = top.document.getElementById(mdlFrameId);
    if (modalIFrame != null && modalIFrame.width != '') { // check for width here means that only reset size if modal is actually showing
        setModalPopupSize(modalIFrame);
    }
}

function closeModalPopup(reloadTop) {
//    if (reloadTop.toString().toUpperCase() == 'TRUE') {
//        window.top.location.href = window.top.location.href;
//    }
    var str = window.top.location.href.toLowerCase();
    if (str.indexOf("useraccount/message.aspx") > 0) {
        window.top.location.href = window.top.location.href;
    }
    var modalIFrame = top.document.getElementById(GetElementClientId('modalIframe', 'iframe'));
    if (modalIFrame != null) {
        modalIFrame.src = '';
    }
    launch = false;
}

function isModalShowing() {
    var modalIFrame = top.document.getElementById(GetElementClientId('modalIframe', 'iframe'));
    if (modalIFrame != null && modalIFrame.width != '' && modalIFrame.src != null && modalIFrame.src != '' && modalIFrame.src != "../blankpage.htm" && modalIFrame.src.indexOf("blankpage.htm") == -1) {    
        return true;
    }
    else {
        return false;
    }
}

function showUrlInTopIfModalOpen(urlToShow) {
    if (isModalShowing()) {
        closeModalPopup(false);
        window.top.location.href = urlToShow;
    }
}

function GetModalSize() {
    var modalIFrame = top.document.getElementById(GetElementClientId('modalIframe', 'iframe'));
    if (modalIFrame != null) {
        return modalIFrame.height;
    }
    else {
        return null;
    }
}

function noSpace(obj) {
    var str = obj.value
    obj.value = obj.value.replace(/\s/g, "");
    if (str.indexOf(" ") >= 0) {
        alert('Sorry, spaces are not allowed');
    }     
}