function verify(objForm)
{


//attributes
var iAttributes = "";
var iAttributesCount = 0;

if(objForm.chk5.checked)
{
	if(iAttributes=="")
	{
		iAttributes += "attColor";
	}
	else
	{
		iAttributes += ",attColor";
	}
	
	iAttributesCount++;
}

if(objForm.chk6.checked)
{
	if(iAttributes=="")
	{
		iAttributes += "attBlackAndWhite";
	}
	else
	{
		iAttributes += ",attBlackAndWhite";
	}
	iAttributesCount++;
}

if(objForm.chk1.checked)
{
	if(iAttributes=="")
	{
		iAttributes += "attHorizontal";
	}
	else
	{
		iAttributes += ",attHorizontal";
	}
	iAttributesCount++;
}

if(objForm.chk2.checked)
{
	if(iAttributes=="")
	{
		iAttributes += "attVertical";
	}
	else
	{
		iAttributes += ",attVertical";
	}	
	iAttributesCount++;
}

if(objForm.chk4.checked)
{
	if(iAttributes=="")
	{
		iAttributes += "attSquare";
	}
	else
	{
		iAttributes += ",attSquare";
	}	
	iAttributesCount++;
}

if(objForm.chk3.checked)
{
	if(iAttributes=="")
	{
		iAttributes += "attPanoramic";
	}
	else
	{
		iAttributes += ",attPanoramic";
	}
	iAttributesCount++;	
}

if(objForm.chk7.checked)
{
	if(iAttributes=="")
	{
		iAttributes += "attPhotograph";
	}
	else
	{
		iAttributes += ",attPhotograph";
	}
	iAttributesCount++;	
}

if(objForm.chk8.checked)
{
	if(iAttributes=="")
	{
		iAttributes += "attIllustration";
	}
	else
	{
		iAttributes += ",attIllustration";
	}	
	iAttributesCount++;
}



if(iAttributesCount==8)
{
	iAttributes = "";
}





	var options = ''
	var sp = '';
	var urlipp = '';
	var ss = ''; //special seacrh eg.advanced search
	var it = '';
	if (isObject(objForm.RM)){
		if(!objForm.RM.checked && !objForm.RF.checked)
		{
			alert("Please select 'Rights Managed' or 'Royalty Free'.");
			return false;
		}	
		if (objForm.RM.checked&&objForm.RF.checked){
			it = '&it=2';
		}else if (objForm.RF.checked){
			it = '&it=1';
		}else if (objForm.RM.checked){
			it = '&it=0';
		}
	}

/*

	if (objForm.s.value == '')
	{
		objForm.s.value	= objForm.cs.value;
		if (objForm.st[1].checked)
		{
			sp = objForm.sp.value;
			if (objForm.ss){
				ss = objForm.ss.value;
			}
		}
	}else{
		if (objForm.sp.value=='')
		{
			objForm.sp.value = objForm.cs.value;
		}else{
			objForm.sp.value = objForm.cs.value+' AND ('+objForm.sp.value+')';
		}
		if (objForm.st[1].checked)
		{
			sp = objForm.sp.value;
			if (objForm.ss){
				ss = objForm.ss.value;
			}
		}
	}

*/


//JDJ - 05092010

if (objForm.s.value == '')
	{
		objForm.s.value	= objForm.cs.value;
		if (objForm.st[1].checked)
		{
			sp = objForm.sp.value;
			if (objForm.ss){
				ss = objForm.ss.value;
			}
		}
	}else{
		if (objForm.sp.value=='')
		{
			objForm.sp.value = objForm.cs.value;
		}else{
			objForm.sp.value = objForm.cs.value;//+' AND ('+objForm.sp.value+')';
		}
		if (objForm.st[1].checked)
		{
			sp = objForm.sp.value;
			if (objForm.ss){
				ss = objForm.ss.value;
			}
		}
	}


//JDJ - 05092010

	//if ( isSearchable ) {
	    var FilterValue = 0;
	    
	    //MarkS 
		options += addFilter(objForm.chkColor);
		options += addFilter(objForm.chkBW);
		options += addFilter(objForm.chkHorizontal);
		options += addFilter(objForm.chkVertical);
		options += addFilter(objForm.chkSquare);
		options += addFilter(objForm.chkPanoramic);
		options += addFilter(objForm.chkPhotograph);
		options += addFilter(objForm.chkIllustration);
		
	
	    /*
		FilterValue += addFilterValue(objForm.chkColor);
		FilterValue += addFilterValue(objForm.chkBW);
		FilterValue += addFilterValue(objForm.chkHorizontal);
		FilterValue += addFilterValue(objForm.chkVertical);
		FilterValue += addFilterValue(objForm.chkSquare);
		FilterValue += addFilterValue(objForm.chkPanoramic);
		FilterValue += addFilterValue(objForm.chkPhotograph);
		FilterValue += addFilterValue(objForm.chkIllustration);
		*/
		
		//alert ("Checking here");
		try {
		    var iLoop;
		    var obj;
		    iLoop = 1;
		    for (iLoop = 1;iLoop<100;iLoop++){
		        obj = document.getElementById("chk" + iLoop);
		        if (isObject(obj)){
		            FilterValue += addFilterValue(obj);
		            
		        }
		    }
		}
		catch (err) 
		{
		    alert("Error" + err+ ' ' + iLoop);
		    FilterValue = 0;
		}
		
		
		filter = "&FilterValue=" + FilterValue;
		filter = filter.replace("undefined,","");
		filter = filter.replace("undefined","");
		filter = filter.replace(/^\s+$/g,"");
		filter = filter.replace(" ","");
		
		//alert (filter);
	//}
	//if (objForm.ImagesPerPage.value != '<%= itemsPerPage %>'){

		urlipp = "&ipps="+objForm.ImagesPerPage.value
	//}
	//alert ("?"+ss+"s="+objForm.s.value+"&sp="+sp+"&lib="+Collection+urlipp+options+it+filter);
	var Collection = getCollection(objForm)
	
	if (ss != ''){
	
		ss = 'ss='+ss+'&'

	}
	
	if(objForm.s.value == "Continental Shift")
	{
	
		document.location = "http://www.greatstock.co.za/images/Conti/index.htm";
	}
	



//jdj 110908
		if (HasValue(objForm.s.value) == true)
{
	
		if (objForm.st[1].checked)
		{
//			sp = objForm.sp.value;

			//document.location = "?"+ss+"s="+CleanString(objForm.s.value) + " and " + sp  +"&sp="+sp+"&lib="+Collection+urlipp+options+it+filter;

			sx = objForm.s.value;

			if(sx.substring(0,4) == "not ")
			{
				document.location = "?s=" + sp + " " + CleanString(objForm.s.value) + "&sp="+sp+"&lib="+Collection+urlipp+options+it+filter+"&iAttributes="+iAttributes;
			}
			else if (sx.substring(0,4) == "and ")
			{
				document.location = "?s=" + sp + " " + CleanString(objForm.s.value) + "&sp="+sp+"&lib="+Collection+urlipp+options+it+filter+"&iAttributes="+iAttributes;
			}
			else if (sx.substring(0,3) == "or ")
			{
				document.location = "?s=" + sp + " " + CleanString(objForm.s.value) + "&sp="+sp+"&lib="+Collection+urlipp+options+it+filter+"&iAttributes="+iAttributes;
			}
			else
			{
				document.location = "?"+ss+"s="+CleanString(objForm.s.value) + " and " + sp  +"&sp="+sp+"&lib="+Collection+urlipp+options+it+filter+"&iAttributes="+iAttributes;
			}
		}
		else 
		{
			document.location = "?"+ss+"s="+CleanString(objForm.s.value)+"&sp="+sp+"&lib="+Collection+urlipp+options+it+filter+"&iAttributes="+iAttributes;		
		}
}
else
{
	alert('Please provide a search string');
}
	
//jdj 110908


	//jdj 110908 - below commented
	//document.location = "?"+ss+"s="+objForm.s.value+"&sp="+sp+"&lib="+Collection+urlipp+options+it+filter+"&iAttributes="+iAttributes;
	


	return false;
}

function CleanString(ToCleanString)
{  
	
        	var CleanedString = ToCleanString.replace(/^\s+|\s+$/g,"");        
        	CleanedString = CleanedString.replace(/ and and /i, "and");
        	return CleanedString;		
}


function HasValue(NewValue)
{
	if (CleanString(NewValue) == '')
	{
		return false;
	}
	else
	{
		return true;
	}
	
}


function verifyIPP(objForm, pgFrom)
{


	var options = ''
	var sp = '';
	var urlipp = '';
	var filter = '';
	if (isObject(objForm.RM)){
		if(!objForm.RM.checked && !objForm.RF.checked)
		{
			alert("Please select 'Rights Managed' or 'Royalty Free'.");
			return false;
		}	
		if (objForm.RM.checked&&objForm.RF.checked){
			it = '&it=2';
		}else if (objForm.RF.checked){
			it = '&it=1';
		}else if (objForm.RM.checked){
			it = '&it=0';
		}
	}

	if (objForm.s.value == '')
	{
		objForm.s.value	= objForm.cs.value;
		if (objForm.st[1].checked)
		{
			sp = objForm.sp.value;
		}
	}else{
		if (objForm.sp.value=='')
		{
			objForm.sp.value = objForm.cs.value;
		}else{
			objForm.sp.value = objForm.cs.value+' AND ('+objForm.sp.value+')';
		}
		if (objForm.st[1].checked)
		{
			sp = objForm.sp.value;
		}
	}
	//if ( isSearchable ) {
		var FilterValue;
	    //MarkS 
	    
		options += addFilter(objForm.chkColor);
		options += addFilter(objForm.chkBW);
		options += addFilter(objForm.chkHorizontal);
		options += addFilter(objForm.chkVertical);
		options += addFilter(objForm.chkSquare);
		options += addFilter(objForm.chkPanoramic);
		options += addFilter(objForm.chkPhotograph);
		options += addFilter(objForm.chkIllustration);
		
		
		/*
		FilterValue += addFilterValue(objForm.chkColor);
		FilterValue += addFilterValue(objForm.chkBW);
		FilterValue += addFilterValue(objForm.chkHorizontal);
		FilterValue += addFilterValue(objForm.chkVertical);
		FilterValue += addFilterValue(objForm.chkSquare);
		FilterValue += addFilterValue(objForm.chkPanoramic);
		FilterValue += addFilterValue(objForm.chkPhotograph);
		FilterValue += addFilterValue(objForm.chkIllustration);
		*/
		
		
		
		//alert ("Checking here");
		try {
		    var iLoop;
		    var obj;
		    iLoop = 1;
		    for (iLoop = 1;iLoop<100;iLoop++){
		        obj = document.getElementById("chk" + iLoop);
		        if (isObject(obj)){
		            FilterValue += addFilterValue(obj);
		        }
		    }
		}
		catch (err) 
		{
		    alert("Error" + err+ ' ' + iLoop);
		    FilterValue = 0;
		}
		
		
		filter = "&FilterValue=" + FilterValue;
		filter = filter.replace("undefined,","");
		filter = filter.replace("undefined","");
		filter = filter.replace(/^\s+$/g,"");
		filter = filter.replace(" ","");
//		alert (filter);
		
	//}
	//if (objForm.ImagesPerPage.value != '<%= itemsPerPage %>'){
		urlipp = "&ipps="+objForm.ImagesPerPage.value
	//}
	var Collection = getCollection(objForm)
	
	document.location = pgFrom+"?s="+objForm.s.value+"&sp="+sp+"&lib="+Collection+urlipp+options+it+filter;
	return false;
}

function addFilter(objName)
{

	var query = "";
	if (isObject(objName)){
		if (!objName.checked)
			query = "&"+objName.name+"=off";

	}
		return query;
}


function addFilterValue(objName)
{

	var filterValue = '';
	if (isObject(objName)){
	    
		if (objName.checked)
		    
			filterValue = ',' + objName.value;
	}
		return filterValue.replace(" ","");
}



function getCollection(objForm){
//alert();
	var collectionID = '';
	var sep = '';
	if (isObject(objForm.RMCollection)){
	
	for (i = 0; i < objForm.RMCollection.length; i++) {
		if (objForm.RMCollection[i].selected){
				collectionID += sep + objForm.RMCollection[i].value;
				sep = ','
		}	
	}
	for (i = 0; i < objForm.RFCollection.length; i++) {
		if (objForm.RFCollection[i].selected){
				collectionID += sep + objForm.RFCollection[i].value;
				sep = ','
		}	
	}
	}
	return collectionID;
}

function SwapLightBox(objVal) 
{
	var url;
	url = '../iframe_alterlightbox.asp?action=swap&slb='+objVal+'';
	setIFrame(url,'iframeUpdate');
}

function doSelect(objChecked, SelectName, assocObjName)
{
	if (SelectName != ''){
		var objSelect = eval('document.frm.'+SelectName+'');
		var len = objSelect.length;
		if (assocObjName != ''){
			var objAssoc =  eval('document.frm.'+assocObjName+'')
		}
	}
	if (objChecked){
		for (var i=0; i < len; i++) 
		{
			objSelect.options[i].selected = true;
			if (isObject(objAssoc))
			{
				objAssoc.checked= true;
			}
		}
	}else{
		for (var i=0; i < len; i++) 
		{
			objSelect.options[i].selected = false;
			if (isObject(objAssoc))
			{
				objAssoc.checked= false;
			}
		}
	}
}

function SetCheckBoxes(objSelect,strCheckBox) 
{
	var arrCheckBox = strCheckBox.split(",")
	var len = objSelect.length;
	var bUnSelected = false
	var bSelected = false
	
	for (var i=0;i<len;i++)
	{
		if (objSelect[i].selected)
		{
			bSelected = true
		}else{
			bUnSelected = true
		}
	}
	if (bUnSelected == true){
		for (var i=0;i<arrCheckBox.length;i++){
			eval('document.frm.'+arrCheckBox[i]+".checked= false")
		}	
	}
	if (bUnSelected == true && bUnSelected == true){
		eval('document.frm.'+arrCheckBox[0]+".checked= true")	
	}
	if (bSelected == true && bUnSelected == false){
		for (var i=0;i<arrCheckBox.length;i++){
			eval('document.frm.'+arrCheckBox[i]+".checked= true")
		}	
	}
}

function login(lib, img){
	document.frm.onsubmit="";
	document.frm.method ="post";
	document.frm.submit();
}

function show(val){
	var blnValue = false;
	if (val == 1) {
		blnValue = true;
	}
		/*document.frm.chkHorizontal.checked = blnValue;
		document.frm.chkVertical.checked=blnValue;
		document.frm.chkPanoramic.checked=blnValue;
		document.frm.chkSquare.checked=blnValue;
		document.frm.chkBW.checked=blnValue;
		document.frm.chkColor.checked=blnValue;
		document.frm.chkPhotograph.checked=blnValue;
		document.frm.chkIllustration.checked=blnValue;
		*/
		
		for (iLoop = 1;iLoop<100;iLoop++){
		        obj = document.getElementById("chk" + iLoop);
		        if (isObject(obj)){
		            obj.checked = blnValue;
		        }
		    }
		
}

function setImagesPerPage(){
	val = document.frm.ImagesPerPage[document.frm.ImagesPerPage.selectedIndex].value;
	url = window.location.href
	if (url.indexOf("ipps=") > 0){
		posAt = url.substr(url.indexOf("ipps="),url.length - url.indexOf("ipps="))
		if (url.indexOf("&") > 0){
			posAt = posAt.substr(0,posAt.length - posAt.indexOf("&")-1)
		}
		url = replaceSubstring(url,posAt,"ipps="+val)
		window.location.href = url;
	}else{
		if (url.indexOf("?") > 0){
			window.location.href = url + "&ipps="+val;
		}else{
			window.location.href = window.location.href + "?ipps="+val;
		}
	}
	return false;
}
