function DialogPage(url,boid,name,title) { 
address = '/IIS/Common/FramePage.aspx?editPageUrl='+url+'&Symbol='+boid+'&title='+title+'&Name='+name;
	
	if(window.showModalDialog){
	var winSettings = 'center:yes;resizable:no;help:no;status:no;dialogWidth:850px;dialogHeight:400px;align:center';
	var flag = window.showModalDialog(address,"",winSettings);
	return false;}
	else
	{
	retVal = window.open(address,title,'height=400,width=850,resizable=no,modal=yes');
          //  retVal.focus();   
            return false;
	
	}
}

function ShowDialogPage(url,title,length,width ) {
    address = '/IIS/Common/FramePage.aspx?editPageUrl='+url+'&title='+title;
    	if(window.showModalDialog){
	var winSettings = 'center:yes;resizable:no;help:no;status:no;dialogWidth:' + width +'px;dialogHeight:' + length + 'px;align:center';
		
	var flag = window.showModalDialog(address,"",winSettings);
	return false;}
		else
	{
	
	retVal = window.open(address,title,'height='+length+',width='+width+',resizable=no,modal=yes');
            retVal.focus();   
            return false;
	}
	
}

function ShowDialogPageMarket(url,title) {
 address = '/IIS/Common/FramePage.aspx?editPageUrl='+url+'&title='+title;
if(window.showModalDialog){
	var winSettings = 'center:yes;resizable:no;help:no;status:no;dialogWidth:850px;dialogHeight:700px;align:center';
	
	//alert( 'report is about to be displayed ' );
	var flag = window.showModalDialog(address,"",winSettings);
	return false;}
	else
	{
	
	retVal = window.open(address,title,'height=700px,width=850px,resizable=no,modal=yes');
            retVal.focus();   
            return false;
	}
}



function ShowDialogPage(url,title) { 
address = '/IIS/Common/FramePage.aspx?editPageUrl='+url+'&title='+title;
if(window.showModalDialog){
	var winSettings = 'center:yes;resizable:no;help:no;toolbar:no;status:no;dialogWidth:720px;dialogHeight:700px;align:center';
	
	//alert( 'report is about to be displayed ' );
	var flag = window.showModalDialog(address,"",winSettings);
	//window.open(address, "","toolbar=no,location=no,directories=no,menubar=no,scrollbars=no,resizable=yes,status=no,top=0,left=0")


	
	return false;}
		else
	{
	
	retVal = window.open(address,title,'height=700px,width=720px,resizable=no,status=no,location=0,modal=yes');
           // retVal.focus(); 
              
            return false;
	}
}
function CloseWindow(){
	window.close();
	
}

function SizeableDialogPage(url,boid,width,height,title) { 
	address = '/IIS/Common/FramePage.aspx?editPageUrl='+url+'&Symbol='+boid+'&title='+title;
	if(window.showModalDialog){
	var winSettings = 'center:yes;resizable:no;help:no;status:no;dialogWidth:'+width+'px;dialogHeight:'+height+'px;align:center';
	
	var flag = window.showModalDialog(address,"",winSettings);
	return false;}
	else
	{
	retVal = window.open(address,title,'height='+height+',width='+width+',resizable=no,modal=yes');
           // retVal.focus(); 
              
            return false;
	
	}
}

var lastHighlightedElement;

function ValidateFormForRequiredFields(myForm)  { 
	var elementCount = myForm.elements.length;
	var i, element;

	if (lastHighlightedElement) {
		unhighlightTextField(lastHighlightedElement);
	}
	
	for(i=0; i< elementCount; i++) {
		element = myForm.elements[i];
		if (element.type=="text") {
			if (isElementRequired(element)) {
				if (trim(element.value) == '') {	// required but empty input box
					highlightTextField(element);
					alert("Please provide all the required information.");
					element.focus();
					lastHighlightedElement = element;
					return false;
				}
			}
			
			if (trim(element.value) != '') {
				if (isDateInput(element)) {
					if (!ValidateForDateInput(element)) {
						highlightTextField(element);
						element.focus();
						lastHighlightedElement = element;
						return false;
					}
				} else if (isNumericInput(element)) {
					if (!ValidateForNumericInput(element)) {
						highlightTextField(element);
						element.focus();
						lastHighlightedElement = element;
						return false;
					}
				}
				
			}	
			
		}
	}
	return true;
}


function highlightTextField(element) {
	element.style.border ="1px solid #DC143C";
}

function unhighlightTextField(element) {
	element.style.border ="1px solid Black";
}

function ValidateForNumericInput(element) {
	if (checkForValidFloat(trim(element.value))) {
		return true;
	} else {
		alert("Please enter a valid number!");
		return false;
	}
}

function ValidateForDateInput(element) {
	if (isValidDate(trim(element.value))) {
		return true;
	} else {
		return false;
	}
}
function isNumericInput(element) {
	return element.className.toLowerCase().indexOf('numeric') >= 0;
}

function isDateInput(element) {
	return element.className.toLowerCase().indexOf('date') >= 0;
}

function isElementRequired(element) {
	return !element.disabled && !element.readonly && element.className.toLowerCase().indexOf('required') >= 0;
}

function trim(str) {
	if (!str) {
		return "";
	}
	return ltrim(rtrim(str));
}

function rtrim(str) {
	var w_space = String.fromCharCode(32);
	var v_length = str.length;
	var strTemp = "";
	
	if(v_length < 0){
		return"";
	}
	var iTemp = v_length -1;

	while(iTemp > -1){
		if(str.charAt(iTemp) == w_space){
		} else {
			strTemp = str.substring(0,iTemp +1);
			break;
		}
		iTemp = iTemp-1;
	}
	return strTemp;
}

function ltrim(str) {
	var w_space = String.fromCharCode(32);

	if(v_length < 1){
		return"";
	}
	
	var v_length = str.length;
	var strTemp = "";
	var iTemp = 0;

	while(iTemp < v_length){
		if(str.charAt(iTemp) == w_space){
		} else {
			strTemp = str.substring(iTemp,v_length);
			break;
		}
		iTemp = iTemp + 1;
	}
	return strTemp;
}   

function checkValidEmailField(obj){
	result=obj.value;
	if(result!=""){
		if(result.indexOf('@')==-1 || result.indexOf('.')==-1){
			obj.value = "";
			obj.focus();
			alert('Please enter a valid email address!');
			return false;
		}
	}
	return true;
}

