/* this is the java script that is used by friends Module

	developd Bhagirath Chakalasiya 
	on 23-Feb-2009
*/

function ismaxlength(obj) {
    var mlength = obj.getAttribute ? parseInt(obj.getAttribute("maxlength")) : ""
    if (obj.getAttribute && obj.value.length > mlength) obj.value = obj.value.substring(0, mlength)
}

function ismaxlengthforcommontextarea(obj) {
    if (document.getElementById('a1').checked == false) {
        if (obj.value.length > 255) obj.value = obj.value.substring(0, 255)
    } else {
        if (obj.value.length > 1000) obj.value = obj.value.substring(0, 1000)
    }
    /* document.getElementByName('radio').value */

}







/**
 *	model popup settingds	model popup settingds	model popup settingds	model popup settingds	model popup settingds	model popup settingds	model popup settingds	model popup settingds	model popup settingds	model popup settingds	model popup settingds	model popup settingds	model popup settingds	model popup settingds	model popup settingds	model popup settingds	model popup settingds	model popup settingds	model popup settingds	model popup settingds	model popup settingds	model popup settingds	
 *
 */

function deleteSingleScrapAlert(moduleLink)
{
	str = '<form name="allDeleteConfirmationForm" method="post" action="'+moduleLink+'"><div class="popupWindow" id="popupAlertWindow"><div class="popupWindowContentContainer"><div class="popupAlertContainer"><div class="QuestionIcon"></div><p class="areUSureContainer">Are You Sure?</p><div class="controlBar"><input type="button" value=" " class="noLink" onclick="modalClose(this);" /><input type="submit" value=" " class="yesLink" /></div></div></div></div></form>';
	$(str).modal({onOpen: modalOpen, onClose: simplemodal_close, minWidth:300, minHeight:400});
}




function deleteAccountAlert(moduleLink)
{

	if(document.getElementById('deleteKeep').checked == true)
	{
		var radioDel = "rdo_keep";
	}
	else
	{
		var radioDel = "rdo_remove";
	}

	str = '<form name="allDeleteConfirmationForm" method="post" action="'+moduleLink+'/settings/delete"><input type="hidden" name="radioDelete" value="'+radioDel+'" /><div class="popupWindow" id="popupAlertWindow"><div class="popupWindowContentContainer"><div class="popupAlertContainer"><div class="QuestionIcon"></div><p class="areUSureContainer">Are You Sure?</p><div class="controlBar"><input type="button" value=" " class="noLink" onclick="modalClose(this);" /><input type="submit" value=" " class="yesLink" /></div></div></div></div></form>';  
	$(str).modal({onOpen: modalOpen, onClose: simplemodal_close, minWidth:300, minHeight:400});
}






function deleteSelectedScrapAlert(baseurl)
{

	var elements=document.myform.elements;
	var idsForDelete = "";
	for(i=0;i<elements.length;i++)
	{
		if(elements[i].type=="checkbox")
		{
			if(elements[i].checked == true)
			{
				idsForDelete = idsForDelete+elements[i].name+'_';
			}
		}
	}
	
	
	if (idsForDelete != "")
	{
	 str = '<form name="allDeleteConfirmationForm" method="post" action="'+baseurl+idsForDelete+'"><div class="popupWindow" id="popupAlertWindow"><div class="popupWindowContentContainer"><div class="popupAlertContainer"><div class="QuestionIcon"></div><p class="areUSureContainer">Are You Sure?</p><div class="controlBar"><input type="button" value=" " class="noLink" onclick="modalClose(this);" /><input type="submit" value=" " class="yesLink" /></div></div></div></div></form>';  
	$(str).modal({onOpen: modalOpen, onClose: simplemodal_close, minWidth:300, minHeight:400});
	}
	 return false;
}


function showFullScrap(str)
{
	$(str).modal({onOpen: modalOpen, onClose: simplemodal_close, minWidth:700, minHeight:400});
}


function areYouSureAlert(str)
{
	$(str).modal({onOpen: modalOpen, onClose: simplemodal_close, minWidth:300, minHeight:400});
}



/**
 * When the open event is called, this function will be used to 'open'
 * the overlay, container and data portions of the modal dialog.
 *
 * onOpen callbacks need to handle 'opening' the overlay, container
 * and data.
 */
function modalOpen (dialog) {
	dialog.overlay.fadeIn('slow', function () {
		dialog.container.fadeIn('slow', function () {
			dialog.data.slideDown('slow');
		});
	});
}

/**
 * When the close event is called, this function will be used to 'close'
 * the overlay, container and data portions of the modal dialog.
 *
 * The SimpleModal close function will still perform some actions that
 * don't need to be handled here.
 *
 * onClose callbacks need to handle 'closing' the overlay, container
 * data and iframe.
 */
function modalClose (dialog) {
	$.modal.close();
	/*
	dialog.data.fadeOut('slow', function () {
		dialog.container.hide('slow', function () {
			dialog.overlay.slideUp('slow', function () {
				$.modal.close();
			});
		});
	});
	*/
}

/**
 * After the dialog is show, this callback will bind some effects
 * to the data when the 'button' button is clicked.
 *
 * This callback is completely user based; SimpleModal does not have
 * a matching function.
 */
function modalShow (dialog) {
	dialog.data.find('input.animate').one('click', function () {
		dialog.data.slideUp('slow', function () {
			dialog.data.slideDown('slow');
		});
	});
}


/**
 * When the close event is called, this function will be used to 'close'
 * the overlay, container and data portions of the modal dialog.
 *
 * The SimpleModal close function will still perform some actions that
 * don't need to be handled here.
 *
 * onClose callbacks need to handle 'closing' the overlay, container
 * and data.
 */
function noLink (dialog) {
	dialog.data.fadeOut('slow', function () {
		dialog.container.hide('slow', function () {
			dialog.overlay.slideUp('slow', function () {
				$.modal.close();
			});
		});
	});
}


function simplemodal_close (dialog) {
	dialog.data.fadeOut('slow', function () {
		dialog.container.hide('slow', function () {
			dialog.overlay.slideUp('slow', function () {
				$.modal.close();
			});
		});
	});
}

function validateSearch()
{
	var searchString = document.getElementById('searchtxt').value;	
	
	if(searchString == "search")
	{
		alert("Please enter proper text to search");
		return false;
	}
	
	searchString = stringTrim(searchString);	
	
	var strlen = searchString.length;
	
	if (!isProper(searchString))
		return false;
		
	if(strlen < 3)
	{
		alert("More than 3 characters to search");
		return false;
	}
	
	if(!validateArray(searchString))
		return false;
		
	return true;
	
}

function isProper(string)
{
	var strlen = string.length;
	
	var iChars = "*|,\":<>[]{}`\';()@&$#%";
	for (var i = 0; i < strlen; i++) 
	{
		if (iChars.indexOf(string.charAt(i)) != -1)
		{
			alert("No Special Characters allowed");
			return false;
		}
	}

	
	return true;

} 

function stringTrim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}

function validateArray(string)
{
	var temp = new Array();
	temp = string.split(' ');
	
	var arrCount = temp.length;
	
	
	for(i=0;i<arrCount;i++)
	{
		strlen = temp[i].length;
		
		if(strlen < 3)
		{
			alert("All words must be more than 3 characters");
			return false;
		}
		
	}
	
	return true;
	
}

